api.c 3.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492
  1. /* api.c API unit tests
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* For AES-CBC, input lengths can optionally be validated to be a
  22. * multiple of the block size, by defining WOLFSSL_AES_CBC_LENGTH_CHECKS,
  23. * also available via the configure option --enable-aescbc-length-checks.
  24. */
  25. /*----------------------------------------------------------------------------*
  26. | Includes
  27. *----------------------------------------------------------------------------*/
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/settings.h>
  32. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  33. #include <wolfssl/wolfcrypt/logging.h>
  34. #include <wolfssl/wolfcrypt/hash.h>
  35. #if defined(WOLFSSL_STATIC_MEMORY)
  36. #include <wolfssl/wolfcrypt/memory.h>
  37. #endif
  38. #ifdef WOLFSSL_ASNC_CRYPT
  39. #include <wolfssl/wolfcrypt/async.h>
  40. #endif
  41. #ifdef HAVE_ECC
  42. #include <wolfssl/wolfcrypt/ecc.h> /* wc_ecc_fp_free */
  43. #ifdef WOLFSSL_SM2
  44. #include <wolfssl/wolfcrypt/sm2.h>
  45. #endif
  46. #endif
  47. #ifndef NO_ASN
  48. #include <wolfssl/wolfcrypt/asn_public.h>
  49. #endif
  50. #include <stdlib.h>
  51. #include <wolfssl/ssl.h> /* compatibility layer */
  52. #include <wolfssl/error-ssl.h>
  53. #include <wolfssl/test.h>
  54. #include <tests/unit.h>
  55. #include <tests/utils.h>
  56. /* for testing compatibility layer callbacks */
  57. #include "examples/server/server.h"
  58. #ifndef NO_MD5
  59. #include <wolfssl/wolfcrypt/md5.h>
  60. #endif
  61. #ifndef NO_SHA
  62. #include <wolfssl/wolfcrypt/sha.h>
  63. #endif
  64. #ifndef NO_SHA256
  65. #include <wolfssl/wolfcrypt/sha256.h>
  66. #endif
  67. #ifdef WOLFSSL_SHA512
  68. #include <wolfssl/wolfcrypt/sha512.h>
  69. #endif
  70. #ifdef WOLFSSL_SHA384
  71. #include <wolfssl/wolfcrypt/sha512.h>
  72. #endif
  73. #ifdef WOLFSSL_SHA3
  74. #include <wolfssl/wolfcrypt/sha3.h>
  75. #endif
  76. #ifdef WOLFSSL_SM3
  77. #include <wolfssl/wolfcrypt/sm3.h>
  78. #endif
  79. #ifndef NO_AES
  80. #include <wolfssl/wolfcrypt/aes.h>
  81. #ifdef HAVE_AES_DECRYPT
  82. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  83. #endif
  84. #endif
  85. #ifdef WOLFSSL_SM4
  86. #include <wolfssl/wolfcrypt/sm4.h>
  87. #endif
  88. #ifdef WOLFSSL_RIPEMD
  89. #include <wolfssl/wolfcrypt/ripemd.h>
  90. #endif
  91. #ifndef NO_DES3
  92. #include <wolfssl/wolfcrypt/des3.h>
  93. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  94. #endif
  95. #ifdef WC_RC2
  96. #include <wolfssl/wolfcrypt/rc2.h>
  97. #endif
  98. #ifndef NO_HMAC
  99. #include <wolfssl/wolfcrypt/hmac.h>
  100. #endif
  101. #ifdef HAVE_CHACHA
  102. #include <wolfssl/wolfcrypt/chacha.h>
  103. #endif
  104. #ifdef HAVE_POLY1305
  105. #include <wolfssl/wolfcrypt/poly1305.h>
  106. #endif
  107. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  108. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  109. #endif
  110. #ifdef HAVE_CAMELLIA
  111. #include <wolfssl/wolfcrypt/camellia.h>
  112. #endif
  113. #ifndef NO_RC4
  114. #include <wolfssl/wolfcrypt/arc4.h>
  115. #endif
  116. #ifdef HAVE_BLAKE2
  117. #include <wolfssl/wolfcrypt/blake2.h>
  118. #endif
  119. #ifndef NO_RSA
  120. #include <wolfssl/wolfcrypt/rsa.h>
  121. #endif
  122. #ifndef NO_SIG_WRAPPER
  123. #include <wolfssl/wolfcrypt/signature.h>
  124. #endif
  125. #ifdef HAVE_AESCCM
  126. #include <wolfssl/wolfcrypt/aes.h>
  127. #endif
  128. #ifdef HAVE_PKCS7
  129. #include <wolfssl/wolfcrypt/pkcs7.h>
  130. #include <wolfssl/wolfcrypt/asn.h>
  131. #ifdef HAVE_LIBZ
  132. #include <wolfssl/wolfcrypt/compress.h>
  133. #endif
  134. #endif
  135. #ifdef WOLFSSL_SMALL_CERT_VERIFY
  136. #include <wolfssl/wolfcrypt/asn.h>
  137. #endif
  138. #ifndef NO_DSA
  139. #include <wolfssl/wolfcrypt/dsa.h>
  140. #endif
  141. #ifdef WOLFSSL_CMAC
  142. #include <wolfssl/wolfcrypt/cmac.h>
  143. #endif
  144. #ifdef HAVE_ED25519
  145. #include <wolfssl/wolfcrypt/ed25519.h>
  146. #endif
  147. #ifdef HAVE_CURVE25519
  148. #include <wolfssl/wolfcrypt/curve25519.h>
  149. #endif
  150. #ifdef HAVE_ED448
  151. #include <wolfssl/wolfcrypt/ed448.h>
  152. #endif
  153. #ifdef HAVE_CURVE448
  154. #include <wolfssl/wolfcrypt/curve448.h>
  155. #endif
  156. #ifdef WOLFSSL_HAVE_KYBER
  157. #include <wolfssl/wolfcrypt/kyber.h>
  158. #ifdef WOLFSSL_WC_KYBER
  159. #include <wolfssl/wolfcrypt/wc_kyber.h>
  160. #endif
  161. #endif
  162. #ifdef HAVE_DILITHIUM
  163. #include <wolfssl/wolfcrypt/dilithium.h>
  164. #endif
  165. #ifdef HAVE_PKCS12
  166. #include <wolfssl/wolfcrypt/pkcs12.h>
  167. #endif
  168. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  169. defined(OPENSSL_ALL)
  170. #include <wolfssl/openssl/ssl.h>
  171. #ifndef NO_ASN
  172. /* for ASN_COMMON_NAME DN_tags enum */
  173. #include <wolfssl/wolfcrypt/asn.h>
  174. #endif
  175. #ifdef HAVE_OCSP
  176. #include <wolfssl/openssl/ocsp.h>
  177. #endif
  178. #endif
  179. #ifdef OPENSSL_EXTRA
  180. #include <wolfssl/openssl/cmac.h>
  181. #include <wolfssl/openssl/x509v3.h>
  182. #include <wolfssl/openssl/asn1.h>
  183. #include <wolfssl/openssl/crypto.h>
  184. #include <wolfssl/openssl/pkcs12.h>
  185. #include <wolfssl/openssl/evp.h>
  186. #include <wolfssl/openssl/dh.h>
  187. #include <wolfssl/openssl/bn.h>
  188. #include <wolfssl/openssl/buffer.h>
  189. #include <wolfssl/openssl/pem.h>
  190. #include <wolfssl/openssl/ec.h>
  191. #include <wolfssl/openssl/ecdh.h>
  192. #include <wolfssl/openssl/engine.h>
  193. #include <wolfssl/openssl/hmac.h>
  194. #include <wolfssl/openssl/objects.h>
  195. #include <wolfssl/openssl/rand.h>
  196. #include <wolfssl/openssl/modes.h>
  197. #include <wolfssl/openssl/fips_rand.h>
  198. #include <wolfssl/openssl/kdf.h>
  199. #ifdef OPENSSL_ALL
  200. #include <wolfssl/openssl/txt_db.h>
  201. #include <wolfssl/openssl/lhash.h>
  202. #endif
  203. #ifndef NO_AES
  204. #include <wolfssl/openssl/aes.h>
  205. #endif
  206. #ifndef NO_DES3
  207. #include <wolfssl/openssl/des.h>
  208. #endif
  209. #ifndef NO_RC4
  210. #include <wolfssl/openssl/rc4.h>
  211. #endif
  212. #ifdef HAVE_ECC
  213. #include <wolfssl/openssl/ecdsa.h>
  214. #endif
  215. #ifdef HAVE_PKCS7
  216. #include <wolfssl/openssl/pkcs7.h>
  217. #endif
  218. #ifdef HAVE_CURVE25519
  219. #include <wolfssl/openssl/ec25519.h>
  220. #endif
  221. #ifdef HAVE_ED25519
  222. #include <wolfssl/openssl/ed25519.h>
  223. #endif
  224. #ifdef HAVE_CURVE448
  225. #include <wolfssl/openssl/ec448.h>
  226. #endif
  227. #ifdef HAVE_ED448
  228. #include <wolfssl/openssl/ed448.h>
  229. #endif
  230. #endif /* OPENSSL_EXTRA */
  231. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  232. !defined(NO_SHA256) && !defined(RC_NO_RNG)
  233. #include <wolfssl/wolfcrypt/srp.h>
  234. #endif
  235. #if (defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)) || \
  236. defined(HAVE_SESSION_TICKET) || (defined(OPENSSL_EXTRA) && \
  237. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)) || \
  238. defined(WOLFSSL_TEST_STATIC_BUILD) || defined(WOLFSSL_DTLS) || \
  239. defined(HAVE_ECH) || defined(HAVE_EX_DATA) || !defined(NO_SESSION_CACHE) \
  240. || !defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13)
  241. /* for testing SSL_get_peer_cert_chain, or SESSION_TICKET_HINT_DEFAULT,
  242. * for setting authKeyIdSrc in WOLFSSL_X509, or testing DTLS sequence
  243. * number tracking */
  244. #include "wolfssl/internal.h"
  245. #endif
  246. /* force enable test buffers */
  247. #ifndef USE_CERT_BUFFERS_2048
  248. #define USE_CERT_BUFFERS_2048
  249. #endif
  250. #ifndef USE_CERT_BUFFERS_256
  251. #define USE_CERT_BUFFERS_256
  252. #endif
  253. #include <wolfssl/certs_test.h>
  254. /* include misc.c here regardless of NO_INLINE, because misc.c implementations
  255. * have default (hidden) visibility, and in the absence of visibility, it's
  256. * benign to mask out the library implementation.
  257. */
  258. #define WOLFSSL_MISC_INCLUDED
  259. #include <wolfcrypt/src/misc.c>
  260. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  261. !defined(NO_RSA) && !defined(SINGLE_THREADED) && \
  262. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  263. #define HAVE_IO_TESTS_DEPENDENCIES
  264. #endif
  265. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  266. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  267. !defined(WOLFSSL_TIRTOS)
  268. #define HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  269. #endif
  270. #if !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_FILESYSTEM) && \
  271. !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  272. !defined(WOLFSSL_NO_CLIENT_AUTH))
  273. #define HAVE_CERT_CHAIN_VALIDATION
  274. #endif
  275. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  276. /* FIPS build has replaced ecc.h. */
  277. #define wc_ecc_key_get_priv(key) (&((key)->k))
  278. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  279. #endif
  280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  281. #if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || defined(SESSION_CERTS)
  282. #ifdef OPENSSL_EXTRA
  283. #define TEST_TLS_STATIC_MEMSZ (400000)
  284. #else
  285. #define TEST_TLS_STATIC_MEMSZ (320000)
  286. #endif
  287. #else
  288. #define TEST_TLS_STATIC_MEMSZ (80000)
  289. #endif
  290. #endif
  291. #ifdef HAVE_ECC
  292. #ifndef ECC_ASN963_MAX_BUF_SZ
  293. #define ECC_ASN963_MAX_BUF_SZ 133
  294. #endif
  295. #ifndef ECC_PRIV_KEY_BUF
  296. #define ECC_PRIV_KEY_BUF 66 /* For non user defined curves. */
  297. #endif
  298. /* ecc key sizes: 14, 16, 20, 24, 28, 30, 32, 40, 48, 64 */
  299. /* logic to choose right key ECC size */
  300. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  301. #define KEY14 14
  302. #else
  303. #define KEY14 32
  304. #endif
  305. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  306. #define KEY16 16
  307. #else
  308. #define KEY16 32
  309. #endif
  310. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  311. #define KEY20 20
  312. #else
  313. #define KEY20 32
  314. #endif
  315. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  316. #define KEY24 24
  317. #else
  318. #define KEY24 32
  319. #endif
  320. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  321. #define KEY28 28
  322. #else
  323. #define KEY28 32
  324. #endif
  325. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  326. #define KEY30 30
  327. #else
  328. #define KEY30 32
  329. #endif
  330. #define KEY32 32
  331. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  332. #define KEY40 40
  333. #else
  334. #define KEY40 32
  335. #endif
  336. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  337. #define KEY48 48
  338. #else
  339. #define KEY48 32
  340. #endif
  341. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  342. #define KEY64 64
  343. #else
  344. #define KEY64 32
  345. #endif
  346. #if !defined(HAVE_COMP_KEY)
  347. #if !defined(NOCOMP)
  348. #define NOCOMP 0
  349. #endif
  350. #else
  351. #if !defined(COMP)
  352. #define COMP 1
  353. #endif
  354. #endif
  355. #if !defined(DER_SZ)
  356. #define DER_SZ(ks) ((ks) * 2 + 1)
  357. #endif
  358. #endif /* HAVE_ECC */
  359. #ifndef NO_DSA
  360. #ifndef DSA_SIG_SIZE
  361. #define DSA_SIG_SIZE 40
  362. #endif
  363. #ifndef MAX_DSA_PARAM_SIZE
  364. #define MAX_DSA_PARAM_SIZE 256
  365. #endif
  366. #endif
  367. #ifndef NO_RSA
  368. #define GEN_BUF 294
  369. #endif
  370. #ifndef ONEK_BUF
  371. #define ONEK_BUF 1024
  372. #endif
  373. #ifndef TWOK_BUF
  374. #define TWOK_BUF 2048
  375. #endif
  376. #ifndef FOURK_BUF
  377. #define FOURK_BUF 4096
  378. #endif
  379. #ifndef HEAP_HINT
  380. #define HEAP_HINT NULL
  381. #endif
  382. typedef struct testVector {
  383. const char* input;
  384. const char* output;
  385. size_t inLen;
  386. size_t outLen;
  387. } testVector;
  388. #if defined(HAVE_PKCS7)
  389. typedef struct {
  390. const byte* content;
  391. word32 contentSz;
  392. int contentOID;
  393. int encryptOID;
  394. int keyWrapOID;
  395. int keyAgreeOID;
  396. byte* cert;
  397. size_t certSz;
  398. byte* privateKey;
  399. word32 privateKeySz;
  400. } pkcs7EnvelopedVector;
  401. #ifndef NO_PKCS7_ENCRYPTED_DATA
  402. typedef struct {
  403. const byte* content;
  404. word32 contentSz;
  405. int contentOID;
  406. int encryptOID;
  407. byte* encryptionKey;
  408. word32 encryptionKeySz;
  409. } pkcs7EncryptedVector;
  410. #endif
  411. #endif /* HAVE_PKCS7 */
  412. typedef int (*ctx_cb)(WOLFSSL_CTX* ctx);
  413. typedef int (*ssl_cb)(WOLFSSL* ssl);
  414. typedef int (*test_cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
  415. typedef int (*hs_cb)(WOLFSSL_CTX **ctx, WOLFSSL **ssl);
  416. typedef struct test_ssl_cbf {
  417. method_provider method;
  418. ctx_cb ctx_ready;
  419. ssl_cb ssl_ready;
  420. ssl_cb on_result;
  421. ctx_cb on_ctx_cleanup;
  422. ssl_cb on_cleanup;
  423. hs_cb on_handshake;
  424. WOLFSSL_CTX* ctx;
  425. const char* caPemFile;
  426. const char* certPemFile;
  427. const char* keyPemFile;
  428. const char* crlPemFile;
  429. #ifdef WOLFSSL_STATIC_MEMORY
  430. byte* mem;
  431. word32 memSz;
  432. wolfSSL_method_func method_ex;
  433. #endif
  434. int devId;
  435. int return_code;
  436. int last_err;
  437. unsigned char isSharedCtx:1;
  438. unsigned char loadToSSL:1;
  439. unsigned char ticNoInit:1;
  440. unsigned char doUdp:1;
  441. } test_ssl_cbf;
  442. #define TEST_SSL_MEMIO_BUF_SZ (64 * 1024)
  443. typedef struct test_ssl_memio_ctx {
  444. WOLFSSL_CTX* s_ctx;
  445. WOLFSSL_CTX* c_ctx;
  446. WOLFSSL* s_ssl;
  447. WOLFSSL* c_ssl;
  448. const char* c_ciphers;
  449. const char* s_ciphers;
  450. char* c_msg;
  451. int c_msglen;
  452. char* s_msg;
  453. int s_msglen;
  454. test_ssl_cbf s_cb;
  455. test_ssl_cbf c_cb;
  456. byte c_buff[TEST_SSL_MEMIO_BUF_SZ];
  457. int c_len;
  458. byte s_buff[TEST_SSL_MEMIO_BUF_SZ];
  459. int s_len;
  460. } test_ssl_memio_ctx;
  461. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  462. test_ssl_cbf* server_cb, test_cbType client_on_handshake);
  463. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  464. const char* currentTestName;
  465. char tmpDirName[16];
  466. int tmpDirNameSet = 0;
  467. #endif
  468. /*----------------------------------------------------------------------------*
  469. | Constants
  470. *----------------------------------------------------------------------------*/
  471. /* Test result constants and macros. */
  472. /* Test succeeded. */
  473. #define TEST_SUCCESS (1)
  474. /* Test failed. */
  475. #define TEST_FAIL (0)
  476. /* Test skipped - not run. */
  477. #define TEST_SKIPPED (-7777)
  478. /* Returns the result based on whether check is true.
  479. *
  480. * @param [in] check Condition for success.
  481. * @return When condition is true: TEST_SUCCESS.
  482. * @return When condition is false: TEST_FAIL.
  483. */
  484. #ifdef DEBUG_WOLFSSL_VERBOSE
  485. #define XSTRINGIFY(s) STRINGIFY(s)
  486. #define STRINGIFY(s) #s
  487. #define TEST_RES_CHECK(check) ({ \
  488. int _ret = (check) ? TEST_SUCCESS : TEST_FAIL; \
  489. if (_ret == TEST_FAIL) { \
  490. fprintf(stderr, " check \"%s\" at %d ", \
  491. XSTRINGIFY(check), __LINE__); \
  492. } \
  493. _ret; })
  494. #else
  495. #define TEST_RES_CHECK(check) \
  496. ((check) ? TEST_SUCCESS : TEST_FAIL)
  497. #endif /* DEBUG_WOLFSSL_VERBOSE */
  498. #define TEST_STRING "Everyone gets Friday off."
  499. #define TEST_STRING_SZ 25
  500. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  501. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  502. #define TEST_RSA_BITS 1024
  503. #else
  504. #define TEST_RSA_BITS 2048
  505. #endif
  506. #define TEST_RSA_BYTES (TEST_RSA_BITS/8)
  507. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  508. (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
  509. static const char* bogusFile =
  510. #ifdef _WIN32
  511. "NUL"
  512. #else
  513. "/dev/null"
  514. #endif
  515. ;
  516. #endif /* !NO_FILESYSTEM && !NO_CERTS && (!NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT) */
  517. enum {
  518. TESTING_RSA = 1,
  519. TESTING_ECC = 2
  520. };
  521. #ifdef WOLFSSL_QNX_CAAM
  522. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  523. static int testDevId = WOLFSSL_CAAM_DEVID;
  524. #else
  525. static int testDevId = INVALID_DEVID;
  526. #endif
  527. /*----------------------------------------------------------------------------*
  528. | BIO with fixed read/write size
  529. *----------------------------------------------------------------------------*/
  530. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  531. static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data,
  532. int len)
  533. {
  534. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  535. len = 0;
  536. }
  537. else {
  538. if (bio->wrSz - bio->wrIdx < len) {
  539. len = bio->wrSz - bio->wrIdx;
  540. }
  541. XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len);
  542. bio->wrIdx += len;
  543. }
  544. return len;
  545. }
  546. static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len)
  547. {
  548. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  549. len = 0;
  550. }
  551. else {
  552. if (bio->wrSz - bio->rdIdx < len) {
  553. len = bio->wrSz - bio->rdIdx;
  554. }
  555. XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len);
  556. bio->rdIdx += len;
  557. }
  558. return len;
  559. }
  560. static WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void)
  561. {
  562. static WOLFSSL_BIO_METHOD meth;
  563. meth.type = WOLFSSL_BIO_BIO;
  564. XMEMCPY(meth.name, "Fixed Memory Size", 18);
  565. meth.writeCb = wolfssl_bio_s_fixed_mem_write;
  566. meth.readCb = wolfssl_bio_s_fixed_mem_read;
  567. return &meth;
  568. }
  569. #endif
  570. /*----------------------------------------------------------------------------*
  571. | Setup
  572. *----------------------------------------------------------------------------*/
  573. static int test_wolfSSL_Init(void)
  574. {
  575. EXPECT_DECLS;
  576. ExpectIntEQ(wolfSSL_Init(), WOLFSSL_SUCCESS);
  577. return EXPECT_RESULT();
  578. }
  579. static int test_wolfSSL_Cleanup(void)
  580. {
  581. EXPECT_DECLS;
  582. ExpectIntEQ(wolfSSL_Cleanup(), WOLFSSL_SUCCESS);
  583. return EXPECT_RESULT();
  584. }
  585. /* Initialize the wolfCrypt state.
  586. * POST: 0 success.
  587. */
  588. static int test_wolfCrypt_Init(void)
  589. {
  590. EXPECT_DECLS;
  591. ExpectIntEQ(wolfCrypt_Init(), 0);
  592. return EXPECT_RESULT();
  593. } /* END test_wolfCrypt_Init */
  594. static int test_wolfCrypt_Cleanup(void)
  595. {
  596. EXPECT_DECLS;
  597. ExpectIntEQ(wolfCrypt_Cleanup(), 0);
  598. return EXPECT_RESULT();
  599. }
  600. #ifdef WOLFSSL_STATIC_MEMORY
  601. #define TEST_LSM_STATIC_SIZE 440000
  602. /* Create new bucket list, using the default list, adding
  603. * one dang large buffer size. */
  604. #define TEST_LSM_DEF_BUCKETS (WOLFMEM_DEF_BUCKETS+1)
  605. #define TEST_LSM_BUCKETS WOLFMEM_BUCKETS,(LARGEST_MEM_BUCKET*2)
  606. #define TEST_LSM_DIST WOLFMEM_DIST,1
  607. #endif
  608. static int test_wc_LoadStaticMemory_ex(void)
  609. {
  610. EXPECT_DECLS;
  611. #ifdef WOLFSSL_STATIC_MEMORY
  612. byte staticMemory[TEST_LSM_STATIC_SIZE];
  613. word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
  614. word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
  615. WOLFSSL_HEAP_HINT* heap;
  616. /* For this test, the size and dist lists will be the ones configured
  617. * for the build, or default. The value of WOLFMEM_DEF_BUCKETS is 9,
  618. * so these lists are 10 long. For most tests, the value of
  619. * WOLFMEM_DEF_BUCKETS is used. There's a test case where one is added
  620. * to that, to make sure the list size is larger than
  621. * WOLFMEM_MAX_BUCKETS. */
  622. /* Pass in zero everything. */
  623. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
  624. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  625. /* Set the heap pointer to NULL. */
  626. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
  627. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  628. staticMemory, (word32)sizeof(staticMemory),
  629. 0, 1),
  630. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  631. /* Set other pointer values to NULL one at a time. */
  632. heap = NULL;
  633. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  634. WOLFMEM_DEF_BUCKETS, NULL, distList,
  635. staticMemory, (word32)sizeof(staticMemory),
  636. 0, 1),
  637. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  638. heap = NULL;
  639. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  640. WOLFMEM_DEF_BUCKETS, sizeList, NULL,
  641. staticMemory, (word32)sizeof(staticMemory),
  642. 0, 1),
  643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  644. heap = NULL;
  645. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  646. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  647. NULL, (word32)sizeof(staticMemory),
  648. 0, 1),
  649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  650. /* Set the size of the static buffer to 0. */
  651. heap = NULL;
  652. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  653. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  654. staticMemory, 0,
  655. 0, 1),
  656. WC_NO_ERR_TRACE(BUFFER_E));
  657. /* Set the size of the static buffer to one less than minimum allowed. */
  658. heap = NULL;
  659. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  660. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  661. staticMemory,
  662. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
  663. 0, 1),
  664. WC_NO_ERR_TRACE(BUFFER_E));
  665. /* Set the size of the static buffer to exactly the minimum size. */
  666. heap = NULL;
  667. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  668. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  669. staticMemory,
  670. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
  671. 0, 1),
  672. 0);
  673. wc_UnloadStaticMemory(heap);
  674. /* Use more buckets than able. Success case. */
  675. heap = NULL;
  676. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  677. WOLFMEM_DEF_BUCKETS*2, sizeList, distList,
  678. staticMemory, (word32)sizeof(staticMemory),
  679. 0, 1),
  680. 0);
  681. wc_UnloadStaticMemory(heap);
  682. /* Success case. */
  683. heap = NULL;
  684. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  685. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  686. staticMemory, (word32)sizeof(staticMemory),
  687. 0, 1),
  688. 0);
  689. wc_UnloadStaticMemory(heap);
  690. #endif /* WOLFSSL_STATIC_MEMORY */
  691. return EXPECT_RESULT();
  692. }
  693. /*----------------------------------------------------------------------------*
  694. | Platform dependent function test
  695. *----------------------------------------------------------------------------*/
  696. static int test_fileAccess(void)
  697. {
  698. EXPECT_DECLS;
  699. #if defined(WOLFSSL_TEST_PLATFORMDEPEND) && !defined(NO_FILESYSTEM)
  700. const char *fname[] = {
  701. svrCertFile, svrKeyFile, caCertFile,
  702. eccCertFile, eccKeyFile, eccRsaCertFile,
  703. cliCertFile, cliCertDerFile, cliKeyFile,
  704. dhParamFile,
  705. cliEccKeyFile, cliEccCertFile, caEccCertFile, edCertFile, edKeyFile,
  706. cliEdCertFile, cliEdKeyFile, caEdCertFile,
  707. NULL
  708. };
  709. const char derfile[] = "./certs/server-cert.der";
  710. XFILE f = XBADFILE;
  711. size_t sz;
  712. byte *buff = NULL;
  713. int i;
  714. ExpectTrue(XFOPEN("badfilename", "rb") == XBADFILE);
  715. for (i=0; EXPECT_SUCCESS() && fname[i] != NULL ; i++) {
  716. ExpectTrue((f = XFOPEN(fname[i], "rb")) != XBADFILE);
  717. XFCLOSE(f);
  718. }
  719. ExpectTrue((f = XFOPEN(derfile, "rb")) != XBADFILE);
  720. ExpectTrue(XFSEEK(f, 0, XSEEK_END) == 0);
  721. ExpectIntGE(sz = (size_t) XFTELL(f), sizeof_server_cert_der_2048);
  722. ExpectTrue(XFSEEK(f, 0, XSEEK_SET) == 0);
  723. ExpectTrue((buff = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE)) != NULL);
  724. ExpectTrue(XFREAD(buff, 1, sz, f) == sz);
  725. ExpectIntEQ(XMEMCMP(server_cert_der_2048, buff, sz), 0);
  726. XFREE(buff, NULL, DYNAMIC_TYPE_FILE);
  727. XFCLOSE(f);
  728. #endif
  729. return EXPECT_RESULT();
  730. }
  731. /*----------------------------------------------------------------------------*
  732. | Method Allocators
  733. *----------------------------------------------------------------------------*/
  734. static int test_wolfSSL_Method_Allocators(void)
  735. {
  736. EXPECT_DECLS;
  737. #define TEST_METHOD_ALLOCATOR(allocator, condition) \
  738. do { \
  739. WOLFSSL_METHOD *method = NULL; \
  740. condition(method = allocator()); \
  741. XFREE(method, 0, DYNAMIC_TYPE_METHOD); \
  742. } while (0)
  743. #define TEST_VALID_METHOD_ALLOCATOR(a) \
  744. TEST_METHOD_ALLOCATOR(a, ExpectNotNull)
  745. #define TEST_INVALID_METHOD_ALLOCATOR(a) \
  746. TEST_METHOD_ALLOCATOR(a, ExpectNull)
  747. #ifndef NO_OLD_TLS
  748. #ifdef WOLFSSL_ALLOW_SSLV3
  749. #ifndef NO_WOLFSSL_SERVER
  750. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_server_method);
  751. #endif
  752. #ifndef NO_WOLFSSL_CLIENT
  753. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_client_method);
  754. #endif
  755. #endif
  756. #ifdef WOLFSSL_ALLOW_TLSV10
  757. #ifndef NO_WOLFSSL_SERVER
  758. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_server_method);
  759. #endif
  760. #ifndef NO_WOLFSSL_CLIENT
  761. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_client_method);
  762. #endif
  763. #endif
  764. #ifndef NO_WOLFSSL_SERVER
  765. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_server_method);
  766. #endif
  767. #ifndef NO_WOLFSSL_CLIENT
  768. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_client_method);
  769. #endif
  770. #endif /* !NO_OLD_TLS */
  771. #ifndef WOLFSSL_NO_TLS12
  772. #ifndef NO_WOLFSSL_SERVER
  773. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_server_method);
  774. #endif
  775. #ifndef NO_WOLFSSL_CLIENT
  776. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_client_method);
  777. #endif
  778. #endif /* !WOLFSSL_NO_TLS12 */
  779. #ifdef WOLFSSL_TLS13
  780. #ifndef NO_WOLFSSL_SERVER
  781. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_server_method);
  782. #endif
  783. #ifndef NO_WOLFSSL_CLIENT
  784. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_client_method);
  785. #endif
  786. #endif /* WOLFSSL_TLS13 */
  787. #ifndef NO_WOLFSSL_SERVER
  788. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_server_method);
  789. #endif
  790. #ifndef NO_WOLFSSL_CLIENT
  791. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_client_method);
  792. #endif
  793. #ifdef WOLFSSL_DTLS
  794. #ifndef NO_OLD_TLS
  795. #ifndef NO_WOLFSSL_SERVER
  796. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_server_method);
  797. #endif
  798. #ifndef NO_WOLFSSL_CLIENT
  799. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_client_method);
  800. #endif
  801. #endif
  802. #ifndef WOLFSSL_NO_TLS12
  803. #ifndef NO_WOLFSSL_SERVER
  804. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_server_method);
  805. #endif
  806. #ifndef NO_WOLFSSL_CLIENT
  807. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_client_method);
  808. #endif
  809. #endif
  810. #endif /* WOLFSSL_DTLS */
  811. #if !defined(NO_OLD_TLS) && defined(OPENSSL_EXTRA)
  812. /* Stubs */
  813. #ifndef NO_WOLFSSL_SERVER
  814. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_server_method);
  815. #endif
  816. #ifndef NO_WOLFSSL_CLIENT
  817. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_client_method);
  818. #endif
  819. #endif
  820. /* Test Either Method (client or server) */
  821. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  822. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_method);
  823. #ifndef NO_OLD_TLS
  824. #ifdef WOLFSSL_ALLOW_TLSV10
  825. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_method);
  826. #endif
  827. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_method);
  828. #endif /* !NO_OLD_TLS */
  829. #ifndef WOLFSSL_NO_TLS12
  830. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_method);
  831. #endif /* !WOLFSSL_NO_TLS12 */
  832. #ifdef WOLFSSL_TLS13
  833. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_method);
  834. #endif /* WOLFSSL_TLS13 */
  835. #ifdef WOLFSSL_DTLS
  836. TEST_VALID_METHOD_ALLOCATOR(wolfDTLS_method);
  837. #ifndef NO_OLD_TLS
  838. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_method);
  839. #endif /* !NO_OLD_TLS */
  840. #ifndef WOLFSSL_NO_TLS12
  841. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_method);
  842. #endif /* !WOLFSSL_NO_TLS12 */
  843. #endif /* WOLFSSL_DTLS */
  844. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  845. return EXPECT_RESULT();
  846. }
  847. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  848. /*----------------------------------------------------------------------------*
  849. | Dual algorithm Certificate Tests
  850. *----------------------------------------------------------------------------*/
  851. #define LARGE_TEMP_SZ 4096
  852. /* To better understand this, please see the X9.146 example in wolfssl-examples
  853. * repo. */
  854. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  855. char *sapkiFile, char *altPrivFile)
  856. {
  857. EXPECT_DECLS;
  858. FILE* file = NULL;
  859. Cert newCert;
  860. DecodedCert preTBS;
  861. byte caKeyBuf[LARGE_TEMP_SZ];
  862. word32 caKeySz = LARGE_TEMP_SZ;
  863. byte sapkiBuf[LARGE_TEMP_SZ];
  864. word32 sapkiSz = LARGE_TEMP_SZ;
  865. byte altPrivBuf[LARGE_TEMP_SZ];
  866. word32 altPrivSz = LARGE_TEMP_SZ;
  867. byte altSigAlgBuf[LARGE_TEMP_SZ];
  868. word32 altSigAlgSz = LARGE_TEMP_SZ;
  869. byte scratchBuf[LARGE_TEMP_SZ];
  870. word32 scratchSz = LARGE_TEMP_SZ;
  871. byte preTbsBuf[LARGE_TEMP_SZ];
  872. word32 preTbsSz = LARGE_TEMP_SZ;
  873. byte altSigValBuf[LARGE_TEMP_SZ];
  874. word32 altSigValSz = LARGE_TEMP_SZ;
  875. byte *outBuf = NULL;
  876. word32 outSz = LARGE_TEMP_SZ;
  877. WC_RNG rng;
  878. RsaKey caKey;
  879. ecc_key altCaKey;
  880. word32 idx = 0;
  881. XMEMSET(&rng, 0, sizeof(WC_RNG));
  882. XMEMSET(&caKey, 0, sizeof(RsaKey));
  883. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  884. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  885. DYNAMIC_TYPE_TMP_BUFFER));
  886. ExpectIntEQ(wc_InitRng(&rng), 0);
  887. XMEMSET(caKeyBuf, 0, caKeySz);
  888. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  889. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  890. if (file) {
  891. fclose(file);
  892. file = NULL;
  893. }
  894. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  895. idx = 0;
  896. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  897. 0);
  898. XMEMSET(sapkiBuf, 0, sapkiSz);
  899. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  900. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  901. if (file) {
  902. fclose(file);
  903. file = NULL;
  904. }
  905. XMEMSET(altPrivBuf, 0, altPrivSz);
  906. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  907. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  908. if (file) {
  909. fclose(file);
  910. file = NULL;
  911. }
  912. wc_ecc_init(&altCaKey);
  913. idx = 0;
  914. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  915. (word32)altPrivSz), 0);
  916. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  917. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  918. oidSigType, 0), 0);
  919. wc_InitCert(&newCert);
  920. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  921. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  922. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  923. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  924. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  925. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  926. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  927. newCert.sigType = CTC_SHA256wRSA;
  928. newCert.isCA = 1;
  929. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  930. (const byte *)"This is NOT a critical extension", 32), 0);
  931. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  932. sapkiSz), 0);
  933. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  934. altSigAlgSz), 0);
  935. XMEMSET(scratchBuf, 0, scratchSz);
  936. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  937. &caKey, &rng), 0);
  938. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  939. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  940. XMEMSET(preTbsBuf, 0, preTbsSz);
  941. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  942. XMEMSET(altSigValBuf, 0, altSigValSz);
  943. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  944. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  945. &rng), 0);
  946. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  947. altSigValSz), 0);
  948. /* Finally, generate the new certificate. */
  949. if (outBuf != NULL) {
  950. XMEMSET(outBuf, 0, outSz);
  951. }
  952. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  953. 0);
  954. *out = outBuf;
  955. wc_FreeRsaKey(&caKey);
  956. wc_FreeRng(&rng);
  957. wc_FreeDecodedCert(&preTBS);
  958. return outSz;
  959. }
  960. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  961. char *sapkiFile, char *altPrivFile,
  962. char *serverKeyFile,
  963. byte *caCertBuf, int caCertSz)
  964. {
  965. EXPECT_DECLS;
  966. FILE* file = NULL;
  967. Cert newCert;
  968. DecodedCert preTBS;
  969. byte serverKeyBuf[LARGE_TEMP_SZ];
  970. word32 serverKeySz = LARGE_TEMP_SZ;
  971. byte caKeyBuf[LARGE_TEMP_SZ];
  972. word32 caKeySz = LARGE_TEMP_SZ;
  973. byte sapkiBuf[LARGE_TEMP_SZ];
  974. word32 sapkiSz = LARGE_TEMP_SZ;
  975. byte altPrivBuf[LARGE_TEMP_SZ];
  976. word32 altPrivSz = LARGE_TEMP_SZ;
  977. byte altSigAlgBuf[LARGE_TEMP_SZ];
  978. word32 altSigAlgSz = LARGE_TEMP_SZ;
  979. byte scratchBuf[LARGE_TEMP_SZ];
  980. word32 scratchSz = LARGE_TEMP_SZ;
  981. byte preTbsBuf[LARGE_TEMP_SZ];
  982. word32 preTbsSz = LARGE_TEMP_SZ;
  983. byte altSigValBuf[LARGE_TEMP_SZ];
  984. word32 altSigValSz = LARGE_TEMP_SZ;
  985. byte *outBuf = NULL;
  986. word32 outSz = LARGE_TEMP_SZ;
  987. WC_RNG rng;
  988. RsaKey caKey;
  989. RsaKey serverKey;
  990. ecc_key altCaKey;
  991. word32 idx = 0;
  992. XMEMSET(&rng, 0, sizeof(WC_RNG));
  993. XMEMSET(&caKey, 0, sizeof(RsaKey));
  994. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  995. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  996. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  997. DYNAMIC_TYPE_TMP_BUFFER));
  998. ExpectIntEQ(wc_InitRng(&rng), 0);
  999. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1000. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1001. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1002. 0);
  1003. if (file) {
  1004. fclose(file);
  1005. file = NULL;
  1006. }
  1007. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1008. idx = 0;
  1009. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1010. (word32)serverKeySz), 0);
  1011. XMEMSET(caKeyBuf, 0, caKeySz);
  1012. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1013. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1014. if (file) {
  1015. fclose(file);
  1016. file = NULL;
  1017. }
  1018. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1019. idx = 0;
  1020. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1021. (word32)caKeySz), 0);
  1022. XMEMSET(sapkiBuf, 0, sapkiSz);
  1023. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1024. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1025. if (file) {
  1026. fclose(file);
  1027. file = NULL;
  1028. }
  1029. XMEMSET(altPrivBuf, 0, altPrivSz);
  1030. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1031. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1032. if (file) {
  1033. fclose(file);
  1034. file = NULL;
  1035. }
  1036. wc_ecc_init(&altCaKey);
  1037. idx = 0;
  1038. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1039. (word32)altPrivSz), 0);
  1040. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1041. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1042. oidSigType, 0), 0);
  1043. wc_InitCert(&newCert);
  1044. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1045. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1046. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1047. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1048. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1049. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1050. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1051. newCert.sigType = CTC_SHA256wRSA;
  1052. newCert.isCA = 0;
  1053. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1054. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1055. sapkiSz), 0);
  1056. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1057. altSigAlgSz), 0);
  1058. XMEMSET(scratchBuf, 0, scratchSz);
  1059. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1060. &rng), 0);
  1061. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1062. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1063. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1064. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1065. XMEMSET(preTbsBuf, 0, preTbsSz);
  1066. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1067. XMEMSET(altSigValBuf, 0, altSigValSz);
  1068. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1069. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1070. &rng), 0);
  1071. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1072. altSigValBuf, altSigValSz), 0);
  1073. /* Finally, generate the new certificate. */
  1074. if (outBuf != NULL) {
  1075. XMEMSET(outBuf, 0, outSz);
  1076. }
  1077. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1078. 0);
  1079. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1080. outSz, &caKey, NULL, &rng), 0);
  1081. *out = outBuf;
  1082. wc_FreeRsaKey(&caKey);
  1083. wc_FreeRsaKey(&serverKey);
  1084. wc_FreeRng(&rng);
  1085. wc_FreeDecodedCert(&preTBS);
  1086. return outSz;
  1087. }
  1088. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1089. byte *serverCert, word32 serverCertSz,
  1090. byte *serverKey, word32 serverKeySz,
  1091. int negative_test)
  1092. {
  1093. EXPECT_DECLS;
  1094. WOLFSSL_CTX *ctx_c = NULL;
  1095. WOLFSSL_CTX *ctx_s = NULL;
  1096. WOLFSSL *ssl_c = NULL;
  1097. WOLFSSL *ssl_s = NULL;
  1098. struct test_memio_ctx test_ctx;
  1099. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1100. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1101. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1102. caCert, caCertSz, serverCert, serverCertSz,
  1103. serverKey, serverKeySz), 0);
  1104. if (negative_test) {
  1105. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1106. }
  1107. else {
  1108. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1109. }
  1110. wolfSSL_free(ssl_c);
  1111. wolfSSL_free(ssl_s);
  1112. wolfSSL_CTX_free(ctx_c);
  1113. wolfSSL_CTX_free(ctx_s);
  1114. return EXPECT_RESULT();
  1115. }
  1116. static int test_dual_alg_support(void)
  1117. {
  1118. EXPECT_DECLS;
  1119. /* Root CA and server keys will be the same. This is only appropriate for
  1120. * testing. */
  1121. char keyFile[] = "./certs/ca-key.der";
  1122. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1123. char altPrivFile[] = "./certs/ecc-key.der";
  1124. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1125. byte *serverKey = NULL;
  1126. size_t serverKeySz = 0;
  1127. byte *root = NULL;
  1128. int rootSz = 0;
  1129. byte *server = NULL;
  1130. int serverSz = 0;
  1131. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1132. /* Base normal case. */
  1133. if (EXPECT_SUCCESS()) {
  1134. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1135. altPrivFile);
  1136. }
  1137. ExpectNotNull(root);
  1138. ExpectIntGT(rootSz, 0);
  1139. if (EXPECT_SUCCESS()) {
  1140. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1141. altPrivFile, keyFile, root, rootSz);
  1142. }
  1143. ExpectNotNull(server);
  1144. ExpectIntGT(serverSz, 0);
  1145. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1146. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1147. TEST_SUCCESS);
  1148. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1149. root = NULL;
  1150. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1151. server = NULL;
  1152. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1153. * the alternative signature and then set negative_test to true for the
  1154. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1155. * because the signature won't verify. The exception is if
  1156. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1157. * and this is no longer a negative test. */
  1158. if (EXPECT_SUCCESS()) {
  1159. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1160. wrongPrivFile);
  1161. }
  1162. ExpectNotNull(root);
  1163. ExpectIntGT(rootSz, 0);
  1164. if (EXPECT_SUCCESS()) {
  1165. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1166. wrongPrivFile, keyFile, root, rootSz);
  1167. }
  1168. ExpectNotNull(server);
  1169. ExpectIntGT(serverSz, 0);
  1170. #ifdef WOLFSSL_TRUST_PEER_CERT
  1171. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1172. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1173. TEST_SUCCESS);
  1174. #else
  1175. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1176. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1177. TEST_SUCCESS);
  1178. #endif
  1179. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1180. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1181. free(serverKey);
  1182. return EXPECT_RESULT();
  1183. }
  1184. #else
  1185. static int test_dual_alg_support(void)
  1186. {
  1187. return TEST_SKIPPED;
  1188. }
  1189. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1190. /*----------------------------------------------------------------------------*
  1191. | Context
  1192. *----------------------------------------------------------------------------*/
  1193. #ifndef NO_WOLFSSL_SERVER
  1194. static int test_wolfSSL_CTX_new(void)
  1195. {
  1196. EXPECT_DECLS;
  1197. WOLFSSL_CTX *ctx;
  1198. WOLFSSL_METHOD* method;
  1199. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1200. ExpectNotNull(method = wolfSSLv23_server_method());
  1201. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1202. wolfSSL_CTX_free(ctx);
  1203. return EXPECT_RESULT();
  1204. }
  1205. #endif
  1206. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1207. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1208. static int test_for_double_Free(void)
  1209. {
  1210. EXPECT_DECLS;
  1211. WOLFSSL_CTX* ctx = NULL;
  1212. WOLFSSL* ssl = NULL;
  1213. int skipTest = 0;
  1214. const char* testCertFile;
  1215. const char* testKeyFile;
  1216. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1217. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1218. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1219. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1220. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1221. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1222. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1223. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1224. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1225. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1226. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1227. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1228. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1229. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1230. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1231. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1232. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1233. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1234. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1235. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1236. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1237. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1238. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1239. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1240. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1241. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1242. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1243. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1244. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1245. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1246. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1247. #ifdef OPENSSL_EXTRA
  1248. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1249. "!SRP:!kRSA:!aNULL:!eNULL";
  1250. #endif
  1251. #ifndef NO_RSA
  1252. testCertFile = svrCertFile;
  1253. testKeyFile = svrKeyFile;
  1254. #elif defined(HAVE_ECC)
  1255. testCertFile = eccCertFile;
  1256. testKeyFile = eccKeyFile;
  1257. #else
  1258. skipTest = 1;
  1259. #endif
  1260. if (skipTest != 1) {
  1261. #ifndef NO_WOLFSSL_SERVER
  1262. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1263. #else
  1264. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1265. #endif
  1266. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1267. WOLFSSL_FILETYPE_PEM));
  1268. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1269. WOLFSSL_FILETYPE_PEM));
  1270. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1271. /* First test freeing SSL, then CTX */
  1272. wolfSSL_free(ssl);
  1273. ssl = NULL;
  1274. wolfSSL_CTX_free(ctx);
  1275. ctx = NULL;
  1276. #ifndef NO_WOLFSSL_CLIENT
  1277. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1278. #else
  1279. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1280. #endif
  1281. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1282. WOLFSSL_FILETYPE_PEM));
  1283. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1284. WOLFSSL_FILETYPE_PEM));
  1285. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1286. /* Next test freeing CTX then SSL */
  1287. wolfSSL_CTX_free(ctx);
  1288. ctx = NULL;
  1289. wolfSSL_free(ssl);
  1290. ssl = NULL;
  1291. #ifndef NO_WOLFSSL_SERVER
  1292. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1293. #else
  1294. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1295. #endif
  1296. /* Test setting ciphers at ctx level */
  1297. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1298. WOLFSSL_FILETYPE_PEM));
  1299. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1300. WOLFSSL_FILETYPE_PEM));
  1301. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1302. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1303. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1304. /* only update TLSv13 suites */
  1305. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1306. #endif
  1307. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1308. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1309. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1310. /* only update pre-TLSv13 suites */
  1311. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1312. "ECDHE-RSA-AES128-GCM-SHA256"));
  1313. #endif
  1314. #ifdef OPENSSL_EXTRA
  1315. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1316. #endif
  1317. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1318. wolfSSL_CTX_free(ctx);
  1319. ctx = NULL;
  1320. wolfSSL_free(ssl);
  1321. ssl = NULL;
  1322. #ifndef NO_WOLFSSL_CLIENT
  1323. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1324. #else
  1325. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1326. #endif
  1327. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1328. WOLFSSL_FILETYPE_PEM));
  1329. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1330. WOLFSSL_FILETYPE_PEM));
  1331. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1332. /* test setting ciphers at SSL level */
  1333. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1334. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1335. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1336. /* only update TLSv13 suites */
  1337. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1338. #endif
  1339. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1340. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1341. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1342. /* only update pre-TLSv13 suites */
  1343. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1344. #endif
  1345. wolfSSL_CTX_free(ctx);
  1346. ctx = NULL;
  1347. wolfSSL_free(ssl);
  1348. ssl = NULL;
  1349. }
  1350. return EXPECT_RESULT();
  1351. }
  1352. #endif
  1353. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1354. {
  1355. EXPECT_DECLS;
  1356. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1357. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1358. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1359. const char* testCertFile;
  1360. const char* testKeyFile;
  1361. WOLFSSL_CTX* ctx = NULL;
  1362. WOLFSSL* ssl = NULL;
  1363. const byte cipherList[] =
  1364. {
  1365. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1366. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1367. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1368. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1369. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1370. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1371. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1372. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1373. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1374. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1375. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1376. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1377. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1378. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1379. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1380. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1381. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1382. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1383. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1384. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1385. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1386. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1387. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1388. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1389. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1390. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1391. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1392. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1393. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1394. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1395. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1396. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1397. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1398. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1399. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1400. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1401. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1402. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1403. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1404. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1405. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1406. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1407. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1408. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1409. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1410. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1411. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1412. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1413. /* SHA256 */
  1414. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1415. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1416. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1417. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1418. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1419. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1420. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1421. /* SHA384 */
  1422. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1423. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1424. /* AES-GCM */
  1425. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1426. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1427. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1428. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1429. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1430. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1431. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1432. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1433. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1434. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1435. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1436. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1437. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1438. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1439. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1440. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1441. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1442. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1443. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1444. * also, in some of the other AES-CCM suites
  1445. * there will be second byte number conflicts
  1446. * with non-ECC AES-GCM */
  1447. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1448. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1449. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1450. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1451. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1452. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1453. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1454. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1455. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1456. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1457. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1458. /* Camellia */
  1459. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1460. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1461. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1462. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1463. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1464. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1465. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1466. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1467. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1468. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1469. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1470. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1471. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1472. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1473. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1474. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1475. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1476. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1477. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1478. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1479. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1480. /* TLS v1.3 cipher suites */
  1481. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1482. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1483. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1484. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1485. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1486. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1487. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1488. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1489. };
  1490. #ifndef NO_RSA
  1491. testCertFile = svrCertFile;
  1492. testKeyFile = svrKeyFile;
  1493. #elif defined(HAVE_ECC)
  1494. testCertFile = eccCertFile;
  1495. testKeyFile = eccKeyFile;
  1496. #endif
  1497. #ifndef NO_WOLFSSL_SERVER
  1498. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1499. #else
  1500. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1501. #endif
  1502. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1503. sizeof(cipherList)));
  1504. wolfSSL_CTX_free(ctx);
  1505. ctx = NULL;
  1506. #ifndef NO_WOLFSSL_SERVER
  1507. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1508. #else
  1509. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1510. #endif
  1511. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1512. WOLFSSL_FILETYPE_PEM));
  1513. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1514. WOLFSSL_FILETYPE_PEM));
  1515. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1516. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1517. sizeof(cipherList)));
  1518. wolfSSL_free(ssl);
  1519. wolfSSL_CTX_free(ctx);
  1520. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1521. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1522. return EXPECT_RESULT();
  1523. }
  1524. static int test_wolfSSL_CTX_use_certificate(void)
  1525. {
  1526. EXPECT_DECLS;
  1527. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1528. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1529. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1530. defined(WOLFSSL_HAPROXY)
  1531. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1532. WOLFSSL_CTX* ctx = NULL;
  1533. X509* x509 = NULL;
  1534. #ifndef NO_WOLFSSL_SERVER
  1535. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1536. #else
  1537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1538. #endif
  1539. ExpectNotNull(x509 = wolfSSL_X509_new());
  1540. /* Negative tests. */
  1541. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1542. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1543. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1544. /* Empty certificate */
  1545. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1546. wolfSSL_X509_free(x509);
  1547. wolfSSL_CTX_free(ctx);
  1548. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1549. #endif
  1550. return EXPECT_RESULT();
  1551. }
  1552. static int test_wolfSSL_CTX_use_certificate_file(void)
  1553. {
  1554. EXPECT_DECLS;
  1555. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1556. WOLFSSL_CTX *ctx = NULL;
  1557. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1558. /* invalid context */
  1559. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1560. WOLFSSL_FILETYPE_PEM));
  1561. /* invalid cert file */
  1562. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1563. WOLFSSL_FILETYPE_PEM));
  1564. /* invalid cert type */
  1565. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1566. #ifdef NO_RSA
  1567. /* rsa needed */
  1568. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1569. WOLFSSL_FILETYPE_PEM));
  1570. #else
  1571. /* success */
  1572. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1573. WOLFSSL_FILETYPE_PEM));
  1574. #endif
  1575. wolfSSL_CTX_free(ctx);
  1576. #endif
  1577. return EXPECT_RESULT();
  1578. }
  1579. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1580. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1581. {
  1582. EXPECT_DECLS;
  1583. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1584. WOLFSSL_CTX* ctx = NULL;
  1585. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1586. /* Failure cases. */
  1587. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1588. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1589. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1590. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1591. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1592. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1593. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1594. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1595. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1596. server_cert_der_2048), WOLFSSL_SUCCESS);
  1597. wolfSSL_CTX_free(ctx);
  1598. #endif
  1599. return EXPECT_RESULT();
  1600. }
  1601. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1602. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1603. * context using buffer.
  1604. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1605. * --enable-testcert flag.
  1606. */
  1607. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1608. {
  1609. EXPECT_DECLS;
  1610. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1611. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1612. WOLFSSL_CTX* ctx = NULL;
  1613. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1614. /* Invalid parameters. */
  1615. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1616. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1617. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1618. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1619. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1620. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1621. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1622. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1623. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1624. server_cert_der_2048, sizeof_server_cert_der_2048,
  1625. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1626. wolfSSL_CTX_free(ctx);
  1627. #endif
  1628. return EXPECT_RESULT();
  1629. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1630. static int test_wolfSSL_use_certificate_buffer(void)
  1631. {
  1632. EXPECT_DECLS;
  1633. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1634. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1635. WOLFSSL_CTX* ctx = NULL;
  1636. WOLFSSL* ssl = NULL;
  1637. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1638. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1639. /* Invalid parameters. */
  1640. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1641. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1642. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1643. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1644. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1645. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1646. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1647. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1648. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1649. client_cert_der_2048, sizeof_client_cert_der_2048,
  1650. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1651. wolfSSL_free(ssl);
  1652. wolfSSL_CTX_free(ctx);
  1653. #endif
  1654. return EXPECT_RESULT();
  1655. }
  1656. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1657. {
  1658. EXPECT_DECLS;
  1659. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1660. WOLFSSL_CTX *ctx = NULL;
  1661. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1662. /* invalid context */
  1663. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1664. WOLFSSL_FILETYPE_PEM));
  1665. /* invalid key file */
  1666. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1667. WOLFSSL_FILETYPE_PEM));
  1668. /* invalid key type */
  1669. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1670. /* success */
  1671. #ifdef NO_RSA
  1672. /* rsa needed */
  1673. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1674. WOLFSSL_FILETYPE_PEM));
  1675. #else
  1676. /* success */
  1677. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1678. WOLFSSL_FILETYPE_PEM));
  1679. #endif
  1680. wolfSSL_CTX_free(ctx);
  1681. #endif
  1682. return EXPECT_RESULT();
  1683. }
  1684. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1685. {
  1686. EXPECT_DECLS;
  1687. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1688. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1689. WOLFSSL_CTX *ctx = NULL;
  1690. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1691. /* invalid context */
  1692. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1693. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1694. /* invalid key file */
  1695. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1696. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1697. /* invalid key type */
  1698. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1699. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1700. /* success */
  1701. #ifdef NO_RSA
  1702. /* rsa needed */
  1703. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1704. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1705. #else
  1706. /* success */
  1707. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1708. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1709. #endif
  1710. wolfSSL_CTX_free(ctx);
  1711. #endif
  1712. return EXPECT_RESULT();
  1713. }
  1714. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1715. {
  1716. EXPECT_DECLS;
  1717. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1718. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1719. WOLFSSL_CTX* ctx = NULL;
  1720. WOLFSSL* ssl = NULL;
  1721. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1722. ExpectNotNull(ssl = SSL_new(ctx));
  1723. /* invalid context */
  1724. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1725. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1726. /* invalid key file */
  1727. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1728. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1729. /* invalid key type */
  1730. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1731. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1732. /* success */
  1733. #ifdef NO_RSA
  1734. /* rsa needed */
  1735. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1736. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1737. #else
  1738. /* success */
  1739. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1740. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1741. #endif
  1742. wolfSSL_free(ssl);
  1743. wolfSSL_CTX_free(ctx);
  1744. #endif
  1745. return EXPECT_RESULT();
  1746. }
  1747. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1748. {
  1749. EXPECT_DECLS;
  1750. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1751. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1752. WOLFSSL_CTX *ctx = NULL;
  1753. WOLFSSL_EVP_PKEY* pkey = NULL;
  1754. const unsigned char* p;
  1755. (void)p;
  1756. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1757. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1758. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1759. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1760. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1761. /* No data. */
  1762. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1763. wolfSSL_EVP_PKEY_free(pkey);
  1764. pkey = NULL;
  1765. #if defined(USE_CERT_BUFFERS_2048)
  1766. #if !defined(NO_RSA)
  1767. p = client_key_der_2048;
  1768. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1769. sizeof_client_key_der_2048));
  1770. #if defined(WOLFSSL_KEY_GEN)
  1771. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1772. #else
  1773. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1774. #endif
  1775. wolfSSL_EVP_PKEY_free(pkey);
  1776. pkey = NULL;
  1777. #endif
  1778. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1779. #ifndef NO_DSA
  1780. p = dsa_key_der_2048;
  1781. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1782. sizeof_dsa_key_der_2048));
  1783. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1784. defined(WOLFSSL_CERT_GEN))
  1785. /* Not supported in ProcessBuffer. */
  1786. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  1787. #else
  1788. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1789. #endif
  1790. wolfSSL_EVP_PKEY_free(pkey);
  1791. pkey = NULL;
  1792. #endif
  1793. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  1794. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  1795. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  1796. p = dh_ffdhe_statickey_der_2048;
  1797. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  1798. sizeof_dh_ffdhe_statickey_der_2048));
  1799. /* Not supported. */
  1800. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1801. wolfSSL_EVP_PKEY_free(pkey);
  1802. pkey = NULL;
  1803. #endif
  1804. #endif /* USE_CERT_BUFFERS_2048 */
  1805. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  1806. p = ecc_clikey_der_256;
  1807. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  1808. sizeof_ecc_clikey_der_256));
  1809. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1810. wolfSSL_EVP_PKEY_free(pkey);
  1811. pkey = NULL;
  1812. #endif
  1813. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  1814. (unsigned char*)"01234567012345670123456701234567", 32));
  1815. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1816. wolfSSL_EVP_PKEY_free(pkey);
  1817. pkey = NULL;
  1818. wolfSSL_CTX_free(ctx);
  1819. #endif
  1820. return EXPECT_RESULT();
  1821. }
  1822. /* test both file and buffer versions along with unloading trusted peer certs */
  1823. static int test_wolfSSL_CTX_trust_peer_cert(void)
  1824. {
  1825. EXPECT_DECLS;
  1826. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  1827. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  1828. WOLFSSL_CTX *ctx = NULL;
  1829. WOLFSSL* ssl = NULL;
  1830. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1831. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1832. #if !defined(NO_FILESYSTEM)
  1833. /* invalid file */
  1834. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  1835. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1836. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  1837. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1838. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  1839. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1840. /* success */
  1841. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  1842. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1843. /* unload cert */
  1844. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1845. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  1846. /* invalid file */
  1847. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  1848. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1849. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  1850. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1851. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  1852. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1853. /* success */
  1854. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  1855. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1856. #ifdef WOLFSSL_LOCAL_X509_STORE
  1857. /* unload cert */
  1858. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1859. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  1860. #endif
  1861. #endif
  1862. /* Test of loading certs from buffers */
  1863. /* invalid buffer */
  1864. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  1865. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1866. /* success */
  1867. #ifdef USE_CERT_BUFFERS_1024
  1868. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  1869. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1870. #endif
  1871. #ifdef USE_CERT_BUFFERS_2048
  1872. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  1873. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1874. #endif
  1875. /* unload cert */
  1876. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  1877. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  1878. wolfSSL_free(ssl);
  1879. wolfSSL_CTX_free(ctx);
  1880. #endif
  1881. return EXPECT_RESULT();
  1882. }
  1883. static int test_wolfSSL_CTX_load_verify_locations(void)
  1884. {
  1885. EXPECT_DECLS;
  1886. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  1887. WOLFSSL_CTX *ctx = NULL;
  1888. #ifndef NO_RSA
  1889. WOLFSSL_CERT_MANAGER* cm = NULL;
  1890. #ifdef PERSIST_CERT_CACHE
  1891. int cacheSz = 0;
  1892. unsigned char* cache = NULL;
  1893. int used = 0;
  1894. #ifndef NO_FILESYSTEM
  1895. const char* cacheFile = "./tests/cert_cache.tmp";
  1896. #endif
  1897. int i;
  1898. int t;
  1899. int* p;
  1900. #endif
  1901. #endif
  1902. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  1903. const char* load_certs_path = "./certs/external";
  1904. const char* load_no_certs_path = "./examples";
  1905. const char* load_expired_path = "./certs/test/expired";
  1906. #endif
  1907. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1908. /* invalid arguments */
  1909. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  1910. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1911. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  1912. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1913. /* invalid ca file */
  1914. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  1915. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  1916. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1917. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  1918. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  1919. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  1920. /* invalid path */
  1921. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  1922. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1923. #endif
  1924. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  1925. /* test ignoring the invalid path */
  1926. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  1927. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  1928. #endif
  1929. /* load ca cert */
  1930. #ifdef NO_RSA
  1931. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  1932. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  1933. #else /* Skip the following test without RSA certs. */
  1934. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  1935. WOLFSSL_SUCCESS);
  1936. #ifdef PERSIST_CERT_CACHE
  1937. /* Get cert cache size */
  1938. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  1939. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  1940. DYNAMIC_TYPE_TMP_BUFFER));
  1941. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  1942. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1943. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  1944. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1945. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  1946. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1947. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  1948. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1949. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  1950. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1951. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  1952. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1953. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  1954. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1955. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  1956. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1957. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  1958. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1959. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  1960. WC_NO_ERR_TRACE(BUFFER_E));
  1961. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  1962. ExpectIntEQ(cacheSz, used);
  1963. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  1964. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1965. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  1966. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1967. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  1968. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1969. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  1970. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1971. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  1972. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1973. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  1974. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1975. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  1976. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1977. /* Smaller than header. */
  1978. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  1979. for (i = 1; i < cacheSz; i++) {
  1980. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  1981. WC_NO_ERR_TRACE(BUFFER_E));
  1982. }
  1983. if (EXPECT_SUCCESS()) {
  1984. /* Modify header for bad results! */
  1985. p = (int*)cache;
  1986. /* version */
  1987. t = p[0]; p[0] = 0xff;
  1988. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1989. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  1990. p[0] = t; p++;
  1991. /* rows */
  1992. t = p[0]; p[0] = 0xff;
  1993. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1994. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  1995. p[0] = t; p++;
  1996. /* columns[0] */
  1997. t = p[0]; p[0] = -1;
  1998. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  1999. WC_NO_ERR_TRACE(PARSE_ERROR));
  2000. p[0] = t; p += CA_TABLE_SIZE;
  2001. /* signerSz*/
  2002. t = p[0]; p[0] = 0xff;
  2003. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2004. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2005. p[0] = t;
  2006. }
  2007. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2008. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2009. #ifndef NO_FILESYSTEM
  2010. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2011. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2012. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2013. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2014. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2015. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2016. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2017. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2018. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2019. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2020. /* File contents is not a cache. */
  2021. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2022. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2023. #endif
  2024. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2025. #endif
  2026. /* Test unloading CA's */
  2027. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2028. #ifdef PERSIST_CERT_CACHE
  2029. /* Verify no certs (result is less than cacheSz) */
  2030. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2031. #endif
  2032. /* load ca cert again */
  2033. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2034. WOLFSSL_SUCCESS);
  2035. /* Test getting CERT_MANAGER */
  2036. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2037. /* Test unloading CA's using CM */
  2038. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2039. #ifdef PERSIST_CERT_CACHE
  2040. /* Verify no certs (result is less than cacheSz) */
  2041. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2042. #endif
  2043. #endif
  2044. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2045. /* Test loading CA certificates using a path */
  2046. #ifdef NO_RSA
  2047. /* failure here okay since certs in external directory are RSA */
  2048. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2049. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2050. #else
  2051. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2052. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2053. #endif
  2054. /* Test loading path with no files */
  2055. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2056. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2057. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2058. /* Test loading expired CA certificates */
  2059. #ifdef NO_RSA
  2060. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2061. load_expired_path,
  2062. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2063. WOLFSSL_SUCCESS);
  2064. #else
  2065. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2066. load_expired_path,
  2067. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2068. WOLFSSL_SUCCESS);
  2069. #endif
  2070. /* Test loading CA certificates and ignoring all errors */
  2071. #ifdef NO_RSA
  2072. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2073. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2074. #else
  2075. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2076. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2077. #endif
  2078. #endif
  2079. wolfSSL_CTX_free(ctx);
  2080. #endif
  2081. return EXPECT_RESULT();
  2082. }
  2083. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2084. {
  2085. int res = TEST_SKIPPED;
  2086. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2087. (!defined(NO_RSA) || defined(HAVE_ECC))
  2088. WOLFSSL_CTX* ctx;
  2089. byte dirValid = 0;
  2090. int ret = 0;
  2091. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2092. if (ctx == NULL) {
  2093. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2094. ret = -1;
  2095. }
  2096. if (ret == 0) {
  2097. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2098. dirValid = 1;
  2099. #else
  2100. word32 numDirs;
  2101. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2102. if (caDirs == NULL || numDirs == 0) {
  2103. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2104. ret = -1;
  2105. }
  2106. else {
  2107. ReadDirCtx dirCtx;
  2108. word32 i;
  2109. for (i = 0; i < numDirs; ++i) {
  2110. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2111. /* Directory isn't empty. */
  2112. dirValid = 1;
  2113. wc_ReadDirClose(&dirCtx);
  2114. break;
  2115. }
  2116. }
  2117. }
  2118. #endif
  2119. }
  2120. /*
  2121. * If the directory isn't empty, we should be able to load CA
  2122. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2123. * usable.
  2124. */
  2125. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2126. WOLFSSL_SUCCESS) {
  2127. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2128. ret = -1;
  2129. }
  2130. #ifdef OPENSSL_EXTRA
  2131. if (ret == 0 &&
  2132. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2133. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2134. ret = -1;
  2135. }
  2136. #endif /* OPENSSL_EXTRA */
  2137. wolfSSL_CTX_free(ctx);
  2138. res = TEST_RES_CHECK(ret == 0);
  2139. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2140. return res;
  2141. }
  2142. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2143. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2144. int file_type)
  2145. {
  2146. int ret;
  2147. WOLFSSL_CERT_MANAGER* cm;
  2148. cm = wolfSSL_CertManagerNew();
  2149. if (cm == NULL) {
  2150. fprintf(stderr, "test_cm_load_ca failed\n");
  2151. return -1;
  2152. }
  2153. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, cert_sz, file_type);
  2154. wolfSSL_CertManagerFree(cm);
  2155. return ret;
  2156. }
  2157. static int test_cm_load_ca_file(const char* ca_cert_file)
  2158. {
  2159. int ret = 0;
  2160. byte* cert_buf = NULL;
  2161. size_t cert_sz = 0;
  2162. #if defined(WOLFSSL_PEM_TO_DER)
  2163. DerBuffer* pDer = NULL;
  2164. #endif
  2165. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2166. if (ret == 0) {
  2167. /* normal test */
  2168. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2169. if (ret == WOLFSSL_SUCCESS) {
  2170. /* test including null terminator in length */
  2171. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2172. if (tmp == NULL) {
  2173. ret = MEMORY_E;
  2174. }
  2175. else {
  2176. cert_buf = tmp;
  2177. cert_buf[cert_sz] = '\0';
  2178. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2179. WOLFSSL_FILETYPE_PEM);
  2180. }
  2181. }
  2182. #if defined(WOLFSSL_PEM_TO_DER)
  2183. if (ret == WOLFSSL_SUCCESS) {
  2184. /* test loading DER */
  2185. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2186. if (ret == 0 && pDer != NULL) {
  2187. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2188. WOLFSSL_FILETYPE_ASN1);
  2189. wc_FreeDer(&pDer);
  2190. }
  2191. }
  2192. #endif
  2193. }
  2194. free(cert_buf);
  2195. return ret;
  2196. }
  2197. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2198. int file_type, word32 flags)
  2199. {
  2200. int ret;
  2201. WOLFSSL_CERT_MANAGER* cm;
  2202. cm = wolfSSL_CertManagerNew();
  2203. if (cm == NULL) {
  2204. fprintf(stderr, "test_cm_load_ca failed\n");
  2205. return -1;
  2206. }
  2207. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, cert_sz, file_type,
  2208. 0, flags);
  2209. wolfSSL_CertManagerFree(cm);
  2210. return ret;
  2211. }
  2212. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2213. {
  2214. int ret = 0;
  2215. byte* cert_buf = NULL;
  2216. size_t cert_sz = 0;
  2217. #if defined(WOLFSSL_PEM_TO_DER)
  2218. DerBuffer* pDer = NULL;
  2219. #endif
  2220. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2221. if (ret == 0) {
  2222. /* normal test */
  2223. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2224. WOLFSSL_FILETYPE_PEM, flags);
  2225. if (ret == WOLFSSL_SUCCESS) {
  2226. /* test including null terminator in length */
  2227. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2228. if (tmp == NULL) {
  2229. ret = MEMORY_E;
  2230. }
  2231. else {
  2232. cert_buf = tmp;
  2233. cert_buf[cert_sz] = '\0';
  2234. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2235. WOLFSSL_FILETYPE_PEM, flags);
  2236. }
  2237. }
  2238. #if defined(WOLFSSL_PEM_TO_DER)
  2239. if (ret == WOLFSSL_SUCCESS) {
  2240. /* test loading DER */
  2241. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2242. if (ret == 0 && pDer != NULL) {
  2243. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2244. WOLFSSL_FILETYPE_ASN1, flags);
  2245. wc_FreeDer(&pDer);
  2246. }
  2247. }
  2248. #endif
  2249. }
  2250. free(cert_buf);
  2251. return ret;
  2252. }
  2253. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2254. static int test_wolfSSL_CertManagerAPI(void)
  2255. {
  2256. EXPECT_DECLS;
  2257. #ifndef NO_CERTS
  2258. WOLFSSL_CERT_MANAGER* cm = NULL;
  2259. unsigned char c;
  2260. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2261. wolfSSL_CertManagerFree(NULL);
  2262. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2263. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2264. #ifdef WOLFSSL_TRUST_PEER_CERT
  2265. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2266. #endif
  2267. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2268. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2269. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2270. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2271. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2272. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2273. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2274. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2275. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2276. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1,
  2277. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2278. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1,
  2279. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2280. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1,
  2281. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2282. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2283. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2284. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2285. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2286. #endif
  2287. #if !defined(NO_FILESYSTEM)
  2288. {
  2289. const char* ca_cert = "./certs/ca-cert.pem";
  2290. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2291. const char* ca_cert_der = "./certs/ca-cert.der";
  2292. #endif
  2293. const char* ca_path = "./certs";
  2294. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2295. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2296. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2297. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2298. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2299. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2300. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2301. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2302. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2303. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2304. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2305. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2306. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2307. #endif
  2308. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2309. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2310. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2311. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2312. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2313. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2314. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2315. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2316. }
  2317. #endif
  2318. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2319. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2320. #elif !defined(HAVE_CRL)
  2321. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2322. #endif
  2323. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2324. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2325. #ifdef HAVE_CRL
  2326. /* Test APIs when CRL is disabled. */
  2327. #ifdef HAVE_CRL_IO
  2328. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2329. #endif
  2330. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2331. sizeof_server_cert_der_2048), 1);
  2332. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2333. #endif
  2334. /* OCSP */
  2335. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2336. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2337. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2338. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2339. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2340. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2341. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2342. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2343. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2344. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2345. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2346. #endif
  2347. #ifdef HAVE_OCSP
  2348. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2349. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2350. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2351. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2352. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2353. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2354. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2355. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2356. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2357. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2358. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2359. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2360. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2361. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2363. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2364. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2365. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2366. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2367. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2368. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2369. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2370. /* Test APIs when OCSP is disabled. */
  2371. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2372. NULL, NULL, NULL, NULL), 1);
  2373. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2374. #endif
  2375. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2376. if (EXPECT_SUCCESS()) {
  2377. wolfSSL_CertManagerFree(cm);
  2378. }
  2379. wolfSSL_CertManagerFree(cm);
  2380. cm = NULL;
  2381. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2382. #ifdef HAVE_OCSP
  2383. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2384. WOLFSSL_OCSP_CHECKALL), 1);
  2385. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2386. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2387. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2388. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2389. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2390. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2391. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2392. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2393. #endif
  2394. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2395. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2396. #endif
  2397. #ifdef WOLFSSL_TRUST_PEER_CERT
  2398. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2399. #endif
  2400. wolfSSL_CertManagerFree(cm);
  2401. #endif
  2402. return EXPECT_RESULT();
  2403. }
  2404. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2405. {
  2406. EXPECT_DECLS;
  2407. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2408. const char* ca_cert = "./certs/ca-cert.pem";
  2409. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2410. int ret;
  2411. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2412. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2413. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2414. #elif defined(NO_RSA)
  2415. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2416. #else
  2417. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2418. #endif
  2419. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2420. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2421. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2422. #elif defined(NO_RSA)
  2423. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2424. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2425. !defined(NO_ASN_TIME)
  2426. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2427. #else
  2428. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2429. #endif
  2430. #endif
  2431. return EXPECT_RESULT();
  2432. }
  2433. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2434. {
  2435. EXPECT_DECLS;
  2436. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2437. const char* ca_cert = "./certs/ca-cert.pem";
  2438. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2439. int ret;
  2440. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2441. 1);
  2442. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2443. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2444. #elif defined(NO_RSA)
  2445. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2446. #else
  2447. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2448. #endif
  2449. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2450. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2451. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2452. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2453. #elif defined(NO_RSA)
  2454. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2455. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2456. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2457. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2458. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2459. #else
  2460. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2461. #endif
  2462. #endif
  2463. return EXPECT_RESULT();
  2464. }
  2465. static int test_wolfSSL_CertManagerGetCerts(void)
  2466. {
  2467. EXPECT_DECLS;
  2468. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2469. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2470. defined(WOLFSSL_SIGNER_DER_CERT)
  2471. WOLFSSL_CERT_MANAGER* cm = NULL;
  2472. WOLFSSL_STACK* sk = NULL;
  2473. X509* x509 = NULL;
  2474. X509* cert1 = NULL;
  2475. FILE* file1 = NULL;
  2476. #ifdef DEBUG_WOLFSSL_VERBOSE
  2477. WOLFSSL_BIO* bio = NULL;
  2478. #endif
  2479. int i = 0;
  2480. int ret = 0;
  2481. const byte* der = NULL;
  2482. int derSz = 0;
  2483. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2484. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2485. if (file1 != NULL) {
  2486. fclose(file1);
  2487. }
  2488. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2489. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2490. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2491. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2492. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2493. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2494. * and full OpenSSL compatibility */
  2495. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2496. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2497. #else
  2498. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2499. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2500. #endif
  2501. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2502. "./certs/ca-cert.pem", NULL));
  2503. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2504. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2505. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2506. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2507. #ifdef DEBUG_WOLFSSL_VERBOSE
  2508. bio = BIO_new(wolfSSL_BIO_s_file());
  2509. if (bio != NULL) {
  2510. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2511. X509_print(bio, x509);
  2512. BIO_free(bio);
  2513. }
  2514. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2515. }
  2516. wolfSSL_X509_free(cert1);
  2517. sk_X509_pop_free(sk, NULL);
  2518. wolfSSL_CertManagerFree(cm);
  2519. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2520. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2521. defined(WOLFSSL_SIGNER_DER_CERT) */
  2522. return EXPECT_RESULT();
  2523. }
  2524. static int test_wolfSSL_CertManagerSetVerify(void)
  2525. {
  2526. EXPECT_DECLS;
  2527. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2528. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2529. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2530. WOLFSSL_CERT_MANAGER* cm = NULL;
  2531. int tmp = myVerifyAction;
  2532. const char* ca_cert = "./certs/ca-cert.pem";
  2533. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2534. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2535. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2536. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2537. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2538. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2539. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2540. #else
  2541. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2542. WOLFSSL_SUCCESS);
  2543. #endif
  2544. /* Use the test CB that always accepts certs */
  2545. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2546. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2547. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2548. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2549. {
  2550. const char* verifyCert = "./certs/server-cert.der";
  2551. /* Use the test CB that always fails certs */
  2552. myVerifyAction = VERIFY_FORCE_FAIL;
  2553. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2554. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2555. }
  2556. #endif
  2557. wolfSSL_CertManagerFree(cm);
  2558. myVerifyAction = tmp;
  2559. #endif
  2560. return EXPECT_RESULT();
  2561. }
  2562. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2563. defined(DEBUG_UNIT_TEST_CERTS)
  2564. /* Used when debugging name constraint tests. Not static to allow use in
  2565. * multiple locations with complex define guards. */
  2566. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2567. {
  2568. BIO* out = BIO_new_file(fileName, "wb");
  2569. if (out != NULL) {
  2570. PEM_write_bio_X509(out, x509);
  2571. BIO_free(out);
  2572. }
  2573. }
  2574. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2575. {
  2576. BIO* out = BIO_new_file(fileName, "wb");
  2577. if (out != NULL) {
  2578. BIO_write(out, der, derSz);
  2579. BIO_free(out);
  2580. }
  2581. }
  2582. #else
  2583. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2584. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2585. #endif
  2586. static int test_wolfSSL_CertManagerNameConstraint(void)
  2587. {
  2588. EXPECT_DECLS;
  2589. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2590. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2591. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2592. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2593. !defined(NO_SHA256)
  2594. WOLFSSL_CERT_MANAGER* cm = NULL;
  2595. WOLFSSL_EVP_PKEY *priv = NULL;
  2596. WOLFSSL_X509_NAME* name = NULL;
  2597. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2598. const char* server_cert = "./certs/test/server-goodcn.pem";
  2599. int i = 0;
  2600. static const byte extNameConsOid[] = {85, 29, 30};
  2601. RsaKey key;
  2602. WC_RNG rng;
  2603. byte *der = NULL;
  2604. int derSz = 0;
  2605. word32 idx = 0;
  2606. byte *pt;
  2607. WOLFSSL_X509 *x509 = NULL;
  2608. WOLFSSL_X509 *ca = NULL;
  2609. wc_InitRng(&rng);
  2610. /* load in CA private key for signing */
  2611. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2612. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2613. sizeof_server_key_der_2048), 0);
  2614. /* get ca certificate then alter it */
  2615. ExpectNotNull(der =
  2616. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2617. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2618. WOLFSSL_FILETYPE_ASN1));
  2619. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2620. if (EXPECT_SUCCESS() && (der != NULL)) {
  2621. XMEMCPY(der, pt, derSz);
  2622. /* find the name constraint extension and alter it */
  2623. pt = der;
  2624. for (i = 0; i < derSz - 3; i++) {
  2625. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2626. pt += 3;
  2627. break;
  2628. }
  2629. pt++;
  2630. }
  2631. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2632. /* go to the length value and set it to 0 */
  2633. while (i < derSz && *pt != 0x81) {
  2634. pt++;
  2635. i++;
  2636. }
  2637. ExpectIntNE(i, derSz); /* did not place to alter */
  2638. pt++;
  2639. *pt = 0x00;
  2640. }
  2641. /* resign the altered certificate */
  2642. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2643. FOURK_BUF, &key, NULL, &rng)), 0);
  2644. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2645. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2646. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2647. wolfSSL_CertManagerFree(cm);
  2648. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2649. wolfSSL_X509_free(x509);
  2650. wc_FreeRsaKey(&key);
  2651. wc_FreeRng(&rng);
  2652. /* add email alt name to satisfy constraint */
  2653. pt = (byte*)server_key_der_2048;
  2654. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2655. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2656. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2657. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2658. WOLFSSL_FILETYPE_ASN1));
  2659. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2660. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2661. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2662. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2663. /* Good cert test with proper alt email name */
  2664. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2665. WOLFSSL_FILETYPE_PEM));
  2666. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2667. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2668. name = NULL;
  2669. ExpectNotNull(name = X509_NAME_new());
  2670. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2671. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2672. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2673. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2674. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2675. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2676. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2677. X509_NAME_free(name);
  2678. name = NULL;
  2679. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2680. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2681. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2682. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2683. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2684. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2685. wolfSSL_X509_free(x509);
  2686. x509 = NULL;
  2687. /* Cert with bad alt name list */
  2688. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2689. WOLFSSL_FILETYPE_PEM));
  2690. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2691. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2692. name = NULL;
  2693. ExpectNotNull(name = X509_NAME_new());
  2694. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2695. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2696. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2697. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2698. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2699. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2700. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2701. X509_NAME_free(name);
  2702. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2703. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2704. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2705. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2706. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2707. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2708. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2709. wolfSSL_CertManagerFree(cm);
  2710. wolfSSL_X509_free(x509);
  2711. wolfSSL_X509_free(ca);
  2712. wolfSSL_EVP_PKEY_free(priv);
  2713. #endif
  2714. return EXPECT_RESULT();
  2715. }
  2716. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2717. {
  2718. EXPECT_DECLS;
  2719. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2720. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2721. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2722. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2723. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2724. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2725. const char* server_cert = "./certs/server-cert.pem";
  2726. WOLFSSL_CERT_MANAGER* cm = NULL;
  2727. WOLFSSL_X509 *x509 = NULL;
  2728. WOLFSSL_X509 *ca = NULL;
  2729. const unsigned char *der = NULL;
  2730. const unsigned char *pt;
  2731. WOLFSSL_EVP_PKEY *priv = NULL;
  2732. WOLFSSL_X509_NAME* name = NULL;
  2733. int derSz = 0;
  2734. /* C=US*/
  2735. char altName[] = {
  2736. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2737. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2738. };
  2739. /* C=ID */
  2740. char altNameFail[] = {
  2741. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2742. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2743. };
  2744. /* C=US ST=California*/
  2745. char altNameExc[] = {
  2746. 0x30, 0x22,
  2747. 0x31, 0x0B,
  2748. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2749. 0x31, 0x13,
  2750. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2751. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2752. };
  2753. /* load in CA private key for signing */
  2754. pt = ca_key_der_2048;
  2755. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2756. sizeof_ca_key_der_2048));
  2757. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2758. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2759. WOLFSSL_FILETYPE_ASN1));
  2760. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2761. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2762. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2763. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2764. WOLFSSL_FILETYPE_PEM));
  2765. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2766. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2767. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2768. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2769. #else
  2770. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2771. #endif
  2772. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2773. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2774. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2775. /* add in matching DIR alt name and resign */
  2776. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2777. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2778. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2779. #else
  2780. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2781. #endif
  2782. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2783. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2784. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2785. wolfSSL_X509_free(x509);
  2786. x509 = NULL;
  2787. /* check verify fail */
  2788. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2789. WOLFSSL_FILETYPE_PEM));
  2790. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2791. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2792. /* add in miss matching DIR alt name and resign */
  2793. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2794. ASN_DIR_TYPE);
  2795. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2796. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2797. #else
  2798. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2799. #endif
  2800. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2801. #ifndef WOLFSSL_NO_ASN_STRICT
  2802. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2803. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2804. #else
  2805. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2806. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2807. #endif
  2808. /* check that it still fails if one bad altname and one good altname is in
  2809. * the certificate */
  2810. wolfSSL_X509_free(x509);
  2811. x509 = NULL;
  2812. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2813. WOLFSSL_FILETYPE_PEM));
  2814. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2815. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2816. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2817. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2818. ASN_DIR_TYPE);
  2819. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2820. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2821. #else
  2822. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2823. #endif
  2824. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2825. #ifndef WOLFSSL_NO_ASN_STRICT
  2826. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2827. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2828. #else
  2829. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2830. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2831. #endif
  2832. /* check it fails with switching position of bad altname */
  2833. wolfSSL_X509_free(x509);
  2834. x509 = NULL;
  2835. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2836. WOLFSSL_FILETYPE_PEM));
  2837. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2838. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2839. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  2840. ASN_DIR_TYPE);
  2841. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2842. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2843. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2844. #else
  2845. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2846. #endif
  2847. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2848. #ifndef WOLFSSL_NO_ASN_STRICT
  2849. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2850. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2851. #else
  2852. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2853. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2854. #endif
  2855. wolfSSL_CertManagerFree(cm);
  2856. wolfSSL_X509_free(x509);
  2857. x509 = NULL;
  2858. wolfSSL_X509_free(ca);
  2859. ca = NULL;
  2860. /* now test with excluded name constraint */
  2861. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2862. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  2863. WOLFSSL_FILETYPE_ASN1));
  2864. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2865. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2866. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2867. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2868. WOLFSSL_FILETYPE_PEM));
  2869. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  2870. ASN_DIR_TYPE);
  2871. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2872. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2873. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2874. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2875. #else
  2876. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2877. #endif
  2878. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2879. #ifndef WOLFSSL_NO_ASN_STRICT
  2880. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2881. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2882. #else
  2883. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2884. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2885. #endif
  2886. wolfSSL_CertManagerFree(cm);
  2887. wolfSSL_X509_free(x509);
  2888. wolfSSL_X509_free(ca);
  2889. wolfSSL_EVP_PKEY_free(priv);
  2890. #endif
  2891. return EXPECT_RESULT();
  2892. }
  2893. static int test_wolfSSL_CertManagerNameConstraint3(void)
  2894. {
  2895. EXPECT_DECLS;
  2896. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2897. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2898. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2899. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2900. !defined(NO_SHA256)
  2901. WOLFSSL_CERT_MANAGER* cm = NULL;
  2902. WOLFSSL_EVP_PKEY *priv = NULL;
  2903. WOLFSSL_X509_NAME* name = NULL;
  2904. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  2905. const char* server_cert = "./certs/test/server-goodcn.pem";
  2906. byte *der = NULL;
  2907. int derSz = 0;
  2908. byte *pt;
  2909. WOLFSSL_X509 *x509 = NULL;
  2910. WOLFSSL_X509 *ca = NULL;
  2911. pt = (byte*)server_key_der_2048;
  2912. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2913. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2914. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2915. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2916. WOLFSSL_FILETYPE_ASN1));
  2917. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2918. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2919. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2920. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2921. /* check satisfying .wolfssl.com constraint passes */
  2922. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2923. WOLFSSL_FILETYPE_PEM));
  2924. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2925. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2926. name = NULL;
  2927. ExpectNotNull(name = X509_NAME_new());
  2928. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2929. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2930. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2931. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2932. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2933. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2934. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2935. X509_NAME_free(name);
  2936. name = NULL;
  2937. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2938. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2939. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  2940. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2941. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2942. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2943. wolfSSL_X509_free(x509);
  2944. x509 = NULL;
  2945. /* check satisfying .random.com constraint passes */
  2946. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2947. WOLFSSL_FILETYPE_PEM));
  2948. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2949. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2950. name = NULL;
  2951. ExpectNotNull(name = X509_NAME_new());
  2952. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2953. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2954. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2955. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2956. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2957. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  2958. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2959. X509_NAME_free(name);
  2960. name = NULL;
  2961. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  2962. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2963. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  2964. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2965. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2966. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2967. wolfSSL_X509_free(x509);
  2968. x509 = NULL;
  2969. /* check fail case when neither constraint is matched */
  2970. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2971. WOLFSSL_FILETYPE_PEM));
  2972. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2973. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2974. name = NULL;
  2975. ExpectNotNull(name = X509_NAME_new());
  2976. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2977. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2978. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2979. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2980. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2981. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  2982. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2983. X509_NAME_free(name);
  2984. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2985. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2986. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2987. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2988. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2989. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2990. wolfSSL_CertManagerFree(cm);
  2991. wolfSSL_X509_free(x509);
  2992. wolfSSL_X509_free(ca);
  2993. wolfSSL_EVP_PKEY_free(priv);
  2994. #endif
  2995. return EXPECT_RESULT();
  2996. }
  2997. static int test_wolfSSL_CertManagerNameConstraint4(void)
  2998. {
  2999. EXPECT_DECLS;
  3000. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3001. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3002. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3003. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3004. !defined(NO_SHA256)
  3005. WOLFSSL_CERT_MANAGER* cm = NULL;
  3006. WOLFSSL_EVP_PKEY *priv = NULL;
  3007. WOLFSSL_X509_NAME* name = NULL;
  3008. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3009. const char* server_cert = "./certs/test/server-goodcn.pem";
  3010. byte *der = NULL;
  3011. int derSz;
  3012. byte *pt;
  3013. WOLFSSL_X509 *x509 = NULL;
  3014. WOLFSSL_X509 *ca = NULL;
  3015. pt = (byte*)server_key_der_2048;
  3016. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3017. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3018. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3019. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3020. WOLFSSL_FILETYPE_ASN1));
  3021. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3022. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3023. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3024. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3025. /* check satisfying wolfssl.com constraint passes */
  3026. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3027. WOLFSSL_FILETYPE_PEM));
  3028. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3029. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3030. name = NULL;
  3031. ExpectNotNull(name = X509_NAME_new());
  3032. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3033. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3034. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3035. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3036. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3037. X509_NAME_free(name);
  3038. name = NULL;
  3039. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3040. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3041. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3042. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3043. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3044. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3045. wolfSSL_X509_free(x509);
  3046. x509 = NULL;
  3047. /* check satisfying example.com constraint passes */
  3048. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3049. WOLFSSL_FILETYPE_PEM));
  3050. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3051. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3052. name = NULL;
  3053. ExpectNotNull(name = X509_NAME_new());
  3054. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3055. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3056. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3057. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3058. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3059. X509_NAME_free(name);
  3060. name = NULL;
  3061. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3062. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3063. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3064. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3065. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3066. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3067. wolfSSL_X509_free(x509);
  3068. x509 = NULL;
  3069. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3070. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3071. WOLFSSL_FILETYPE_PEM));
  3072. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3073. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3074. name = NULL;
  3075. ExpectNotNull(name = X509_NAME_new());
  3076. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3077. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3078. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3079. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3080. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3081. X509_NAME_free(name);
  3082. name = NULL;
  3083. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3084. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3085. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3086. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3087. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3088. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3089. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3090. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3091. wolfSSL_X509_free(x509);
  3092. x509 = NULL;
  3093. /* check fail when one DNS in the list is bad */
  3094. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3095. WOLFSSL_FILETYPE_PEM));
  3096. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3097. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3098. name = NULL;
  3099. ExpectNotNull(name = X509_NAME_new());
  3100. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3101. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3102. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3103. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3104. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3105. X509_NAME_free(name);
  3106. name = NULL;
  3107. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3108. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3109. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3110. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3111. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3112. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3113. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3114. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3115. wolfSSL_X509_free(x509);
  3116. x509 = NULL;
  3117. /* check fail case when neither constraint is matched */
  3118. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3119. WOLFSSL_FILETYPE_PEM));
  3120. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3121. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3122. name = NULL;
  3123. ExpectNotNull(name = X509_NAME_new());
  3124. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3125. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3126. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3127. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3128. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3129. X509_NAME_free(name);
  3130. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3131. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3132. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3133. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3134. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3135. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3136. wolfSSL_CertManagerFree(cm);
  3137. wolfSSL_X509_free(x509);
  3138. wolfSSL_X509_free(ca);
  3139. wolfSSL_EVP_PKEY_free(priv);
  3140. #endif
  3141. return EXPECT_RESULT();
  3142. }
  3143. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3144. {
  3145. EXPECT_DECLS;
  3146. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3147. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3148. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3149. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3150. !defined(NO_SHA256)
  3151. WOLFSSL_CERT_MANAGER* cm = NULL;
  3152. WOLFSSL_EVP_PKEY *priv = NULL;
  3153. WOLFSSL_X509_NAME* name = NULL;
  3154. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3155. const char* server_cert = "./certs/test/server-goodcn.pem";
  3156. byte *der = NULL;
  3157. int derSz;
  3158. byte *pt;
  3159. WOLFSSL_X509 *x509 = NULL;
  3160. WOLFSSL_X509 *ca = NULL;
  3161. pt = (byte*)server_key_der_2048;
  3162. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3163. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3164. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3165. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3166. WOLFSSL_FILETYPE_ASN1));
  3167. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3168. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3169. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3170. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3171. /* check satisfying wolfssl.com constraint passes */
  3172. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3173. WOLFSSL_FILETYPE_PEM));
  3174. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3175. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3176. name = NULL;
  3177. ExpectNotNull(name = X509_NAME_new());
  3178. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3179. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3180. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3181. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3182. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3183. X509_NAME_free(name);
  3184. name = NULL;
  3185. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3186. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3187. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3188. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3189. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3190. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3191. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3192. wolfSSL_X509_free(x509);
  3193. x509 = NULL;
  3194. /* fail with DNS check because of common name */
  3195. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3196. WOLFSSL_FILETYPE_PEM));
  3197. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3198. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3199. name = NULL;
  3200. ExpectNotNull(name = X509_NAME_new());
  3201. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3202. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3203. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3204. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3205. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3206. X509_NAME_free(name);
  3207. name = NULL;
  3208. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3209. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3210. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3211. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3212. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3213. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3214. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3215. wolfSSL_X509_free(x509);
  3216. x509 = NULL;
  3217. /* fail on permitted DNS name constraint */
  3218. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3219. WOLFSSL_FILETYPE_PEM));
  3220. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3221. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3222. name = NULL;
  3223. ExpectNotNull(name = X509_NAME_new());
  3224. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3225. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3226. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3227. X509_NAME_free(name);
  3228. name = NULL;
  3229. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3230. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3231. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3232. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3233. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3234. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3235. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3236. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3237. wolfSSL_X509_free(x509);
  3238. x509 = NULL;
  3239. /* fail on permitted email name constraint */
  3240. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3241. WOLFSSL_FILETYPE_PEM));
  3242. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3243. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3244. name = NULL;
  3245. ExpectNotNull(name = X509_NAME_new());
  3246. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3247. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3248. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3249. X509_NAME_free(name);
  3250. name = NULL;
  3251. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3252. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3253. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3254. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3255. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3256. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3257. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3258. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3259. wolfSSL_X509_free(x509);
  3260. x509 = NULL;
  3261. /* success with empty email name */
  3262. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3263. WOLFSSL_FILETYPE_PEM));
  3264. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3265. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3266. name = NULL;
  3267. ExpectNotNull(name = X509_NAME_new());
  3268. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3269. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3270. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3271. X509_NAME_free(name);
  3272. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3273. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3274. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3275. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3276. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3277. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3278. wolfSSL_X509_free(x509);
  3279. wolfSSL_CertManagerFree(cm);
  3280. wolfSSL_X509_free(ca);
  3281. wolfSSL_EVP_PKEY_free(priv);
  3282. #endif
  3283. return EXPECT_RESULT();
  3284. }
  3285. static int test_wolfSSL_CertManagerCRL(void)
  3286. {
  3287. EXPECT_DECLS;
  3288. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3289. !defined(NO_RSA)
  3290. const char* ca_cert = "./certs/ca-cert.pem";
  3291. const char* crl1 = "./certs/crl/crl.pem";
  3292. const char* crl2 = "./certs/crl/crl2.pem";
  3293. #ifdef WC_RSA_PSS
  3294. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3295. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3296. #endif
  3297. const unsigned char crl_buff[] = {
  3298. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3299. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3300. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3301. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3302. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3303. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3304. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3305. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3306. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3307. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3308. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3309. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3310. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3311. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3312. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3313. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3314. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3315. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3316. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3317. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3318. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3319. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3320. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3321. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3322. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3323. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3324. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3325. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3326. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3327. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3328. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3329. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3330. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3331. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3332. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3333. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3334. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3335. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3336. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3337. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3338. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3339. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3340. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3341. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3342. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3343. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3344. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3345. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3346. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3347. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3348. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3349. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3350. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3351. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3352. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3353. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3354. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3355. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3356. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3357. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3358. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3359. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3360. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3361. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3362. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3363. };
  3364. WOLFSSL_CERT_MANAGER* cm = NULL;
  3365. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3366. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3367. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3368. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3369. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3370. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3371. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3372. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3373. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3374. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3375. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3376. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3377. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3378. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3379. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3380. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3381. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3382. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3383. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3384. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3385. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3386. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3387. #ifdef HAVE_CRL_IO
  3388. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3389. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3390. #endif
  3391. #ifndef NO_FILESYSTEM
  3392. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3393. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3394. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3395. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3396. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3397. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3398. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3399. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3400. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3401. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3402. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3403. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3404. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3405. #endif
  3406. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3407. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3408. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3409. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3410. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3411. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3412. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1,
  3413. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3414. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1,
  3415. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3416. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1,
  3417. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3418. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3419. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3420. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3421. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3422. ExpectIntEQ(WOLFSSL_SUCCESS,
  3423. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3424. ExpectIntEQ(WOLFSSL_SUCCESS,
  3425. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3426. ExpectIntEQ(WOLFSSL_SUCCESS,
  3427. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3428. wolfSSL_CertManagerFreeCRL(cm);
  3429. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3430. ExpectIntEQ(WOLFSSL_SUCCESS,
  3431. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3432. ExpectIntEQ(WOLFSSL_SUCCESS,
  3433. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3434. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3435. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3436. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3437. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3438. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3439. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3440. WOLFSSL_FILETYPE_ASN1), 1);
  3441. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3442. /* loading should fail without the CA set */
  3443. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3444. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3445. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3446. ExpectIntEQ(WOLFSSL_SUCCESS,
  3447. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3448. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3449. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3450. #endif
  3451. wolfSSL_CertManagerFree(cm);
  3452. #endif
  3453. return EXPECT_RESULT();
  3454. }
  3455. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3456. {
  3457. EXPECT_DECLS;
  3458. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3459. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3460. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3461. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3462. defined(HAVE_LIGHTY)
  3463. WOLFSSL_CERT_MANAGER* cm = NULL;
  3464. /* Raw OCSP response bytes captured using the following setup:
  3465. * - Run responder with
  3466. * openssl ocsp -port 9999 -ndays 9999
  3467. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3468. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3469. * -rkey certs/ocsp/ocsp-responder-key.pem
  3470. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3471. * - Run client with
  3472. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3473. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3474. * -cert certs/ocsp/server1-cert.pem
  3475. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3476. * - Select the response packet in Wireshark, and export it using
  3477. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3478. * packets only". After importing into the editor, remove the initial
  3479. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3480. */
  3481. static const byte response[] = {
  3482. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3483. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3484. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3485. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3486. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3487. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3488. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3489. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3490. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3491. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3492. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3493. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3494. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3495. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3496. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3497. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3498. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3499. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3500. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3501. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3502. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3503. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3504. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3505. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3506. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3507. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3508. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3509. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3510. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3511. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3512. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3513. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3514. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3515. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3516. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3517. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3518. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3519. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3520. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3521. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3522. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3523. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3524. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3525. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3526. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3527. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3528. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3529. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3530. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3531. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3532. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3533. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3534. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3535. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3536. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3537. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3538. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3539. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3540. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3541. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3542. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3543. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3544. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3545. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3546. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3547. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3548. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3549. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3550. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3551. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3552. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3553. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3554. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3555. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3556. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3557. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3558. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3559. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3560. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3561. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3562. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3563. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3564. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3565. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3566. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3567. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3568. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3569. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3570. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3571. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3572. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3573. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3574. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3575. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3576. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3577. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3578. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3579. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3580. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3581. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3582. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3583. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3584. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3585. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3586. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3587. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3588. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3589. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3590. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3591. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3592. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3593. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3594. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3595. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3596. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3597. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3598. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3599. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3600. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3601. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3602. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3603. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3604. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3605. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3606. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3607. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3608. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3609. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3610. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3611. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3612. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3613. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3614. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3615. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3616. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3617. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3618. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3619. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3620. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3621. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3622. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3623. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3624. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3625. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3626. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3627. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3628. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3629. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3630. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3631. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3632. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3633. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3634. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3635. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3636. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3637. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3638. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3639. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3640. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3641. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3642. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3643. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3644. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3645. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3646. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3647. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3648. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3649. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3650. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3651. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3652. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3653. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3654. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3655. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3656. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3657. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3658. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3659. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3660. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3661. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3662. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3663. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3664. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3665. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3666. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3667. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3668. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3669. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3670. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3671. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3672. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3673. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3674. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3675. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3676. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3677. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3678. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3679. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3680. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3681. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3682. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3683. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3684. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3685. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3686. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3687. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3688. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3689. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3690. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3691. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3692. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3693. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3694. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3695. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3696. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3697. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3698. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3699. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3700. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3701. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3702. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3703. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3704. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3705. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3706. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3707. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3708. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3709. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3710. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3711. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3712. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3713. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3714. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3715. };
  3716. OcspEntry entry[1];
  3717. CertStatus status[1];
  3718. OcspRequest* request = NULL;
  3719. #ifndef NO_FILESYSTEM
  3720. const char* ca_cert = "./certs/ca-cert.pem";
  3721. #endif
  3722. byte serial[] = {0x05};
  3723. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3724. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3725. XMEMSET(entry, 0, sizeof(OcspEntry));
  3726. XMEMSET(status, 0, sizeof(CertStatus));
  3727. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3728. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3729. DYNAMIC_TYPE_OCSP_REQUEST));
  3730. if ((request != NULL) && (request->serial != NULL)) {
  3731. request->serialSz = sizeof(serial);
  3732. XMEMCPY(request->serial, serial, sizeof(serial));
  3733. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3734. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3735. }
  3736. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3737. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3738. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3739. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3740. /* Response should be valid. */
  3741. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3742. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3743. /* Flip a byte in the request serial number, response should be invalid
  3744. * now. */
  3745. if ((request != NULL) && (request->serial != NULL))
  3746. request->serial[0] ^= request->serial[0];
  3747. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3748. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3749. #ifndef NO_FILESYSTEM
  3750. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3751. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3752. ExpectIntEQ(WOLFSSL_SUCCESS,
  3753. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3754. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3755. sizeof(server_cert_der_2048)), 1);
  3756. #endif
  3757. wolfSSL_OCSP_REQUEST_free(request);
  3758. wolfSSL_CertManagerFree(cm);
  3759. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3760. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3761. #endif /* HAVE_OCSP */
  3762. return EXPECT_RESULT();
  3763. }
  3764. static int test_wolfSSL_CheckOCSPResponse(void)
  3765. {
  3766. EXPECT_DECLS;
  3767. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3768. !defined(NO_RSA) && !defined(NO_SHA)
  3769. const char* responseFile = "./certs/ocsp/test-response.der";
  3770. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3771. const char* responseNoInternFile =
  3772. "./certs/ocsp/test-response-nointern.der";
  3773. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3774. OcspResponse* res = NULL;
  3775. byte data[4096];
  3776. const unsigned char* pt;
  3777. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3778. * gcc sanitizer with --enable-heapmath.
  3779. */
  3780. XFILE f = XBADFILE;
  3781. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3782. WOLFSSL_X509_STORE* st = NULL;
  3783. WOLFSSL_X509* issuer = NULL;
  3784. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  3785. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3786. if (f != XBADFILE) {
  3787. XFCLOSE(f);
  3788. f = XBADFILE;
  3789. }
  3790. pt = data;
  3791. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3792. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  3793. SSL_FILETYPE_PEM));
  3794. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  3795. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  3796. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  3797. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  3798. wolfSSL_OCSP_BASICRESP_free(bs);
  3799. bs = NULL;
  3800. wolfSSL_OCSP_RESPONSE_free(res);
  3801. res = NULL;
  3802. wolfSSL_X509_STORE_free(st);
  3803. st = NULL;
  3804. wolfSSL_X509_free(issuer);
  3805. issuer = NULL;
  3806. /* check loading a response with optional certs */
  3807. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  3808. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3809. if (f != XBADFILE)
  3810. XFCLOSE(f);
  3811. f = XBADFILE;
  3812. pt = data;
  3813. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3814. wolfSSL_OCSP_RESPONSE_free(res);
  3815. res = NULL;
  3816. /* check loading a response with multiple certs */
  3817. {
  3818. WOLFSSL_CERT_MANAGER* cm = NULL;
  3819. OcspEntry *entry = NULL;
  3820. CertStatus* status = NULL;
  3821. OcspRequest* request = NULL;
  3822. byte serial1[] = {0x01};
  3823. byte serial[] = {0x02};
  3824. byte issuerHash[] = {
  3825. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  3826. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  3827. 0x37, 0x15, 0x8A, 0x88
  3828. };
  3829. byte issuerKeyHash[] = {
  3830. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  3831. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  3832. 0x7E, 0x72, 0x15, 0x21
  3833. };
  3834. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  3835. DYNAMIC_TYPE_OPENSSL));
  3836. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  3837. DYNAMIC_TYPE_OPENSSL));
  3838. if (entry != NULL)
  3839. XMEMSET(entry, 0, sizeof(OcspEntry));
  3840. if (status != NULL)
  3841. XMEMSET(status, 0, sizeof(CertStatus));
  3842. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3843. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3844. DYNAMIC_TYPE_OCSP_REQUEST));
  3845. if (request != NULL && request->serial != NULL) {
  3846. request->serialSz = sizeof(serial);
  3847. XMEMCPY(request->serial, serial, sizeof(serial));
  3848. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3849. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  3850. sizeof(issuerKeyHash));
  3851. }
  3852. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3853. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3854. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  3855. WOLFSSL_SUCCESS);
  3856. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  3857. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3858. if (f != XBADFILE)
  3859. XFCLOSE(f);
  3860. f = XBADFILE;
  3861. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3862. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  3863. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3864. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  3865. ExpectNotNull(entry->status);
  3866. if (request != NULL && request->serial != NULL)
  3867. XMEMCPY(request->serial, serial1, sizeof(serial1));
  3868. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3869. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  3870. /* store both status's in the entry to check that "next" is not
  3871. * overwritten */
  3872. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  3873. status->next = entry->status;
  3874. entry->status = status;
  3875. }
  3876. if (request != NULL && request->serial != NULL)
  3877. XMEMCPY(request->serial, serial, sizeof(serial));
  3878. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  3879. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  3880. ExpectNotNull(entry->status->next);
  3881. /* compare the status found */
  3882. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  3883. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  3884. status->serialSz), 0);
  3885. if (status != NULL && entry != NULL && entry->status != status) {
  3886. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  3887. }
  3888. wolfSSL_OCSP_CERTID_free(entry);
  3889. wolfSSL_OCSP_REQUEST_free(request);
  3890. wolfSSL_CertManagerFree(cm);
  3891. }
  3892. #if defined(WC_RSA_PSS)
  3893. {
  3894. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  3895. /* check loading a response with RSA-PSS signature */
  3896. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  3897. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3898. if (f != XBADFILE)
  3899. XFCLOSE(f);
  3900. pt = data;
  3901. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  3902. /* try to verify the response */
  3903. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  3904. SSL_FILETYPE_PEM));
  3905. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  3906. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  3907. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  3908. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  3909. WOLFSSL_SUCCESS);
  3910. wolfSSL_OCSP_BASICRESP_free(bs);
  3911. wolfSSL_OCSP_RESPONSE_free(res);
  3912. wolfSSL_X509_STORE_free(st);
  3913. wolfSSL_X509_free(issuer);
  3914. }
  3915. #endif
  3916. #endif /* HAVE_OCSP */
  3917. return EXPECT_RESULT();
  3918. }
  3919. static int test_wolfSSL_FPKI(void)
  3920. {
  3921. EXPECT_DECLS;
  3922. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  3923. XFILE f = XBADFILE;
  3924. const char* fpkiCert = "./certs/fpki-cert.der";
  3925. DecodedCert cert;
  3926. byte buf[4096];
  3927. byte* uuid = NULL;
  3928. byte* fascn = NULL;
  3929. word32 fascnSz;
  3930. word32 uuidSz;
  3931. int bytes = 0;
  3932. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  3933. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  3934. if (f != XBADFILE)
  3935. XFCLOSE(f);
  3936. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  3937. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  3938. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  3939. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  3940. DYNAMIC_TYPE_TMP_BUFFER));
  3941. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  3942. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  3943. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  3944. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  3945. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  3946. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  3947. wc_FreeDecodedCert(&cert);
  3948. #endif
  3949. return EXPECT_RESULT();
  3950. }
  3951. /* use RID in confuncture with other names to test parsing of unknown other
  3952. * names */
  3953. static int test_wolfSSL_OtherName(void)
  3954. {
  3955. EXPECT_DECLS;
  3956. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  3957. XFILE f = XBADFILE;
  3958. const char* ridCert = "./certs/rid-cert.der";
  3959. DecodedCert cert;
  3960. byte buf[4096];
  3961. int bytes = 0;
  3962. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  3963. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  3964. if (f != XBADFILE)
  3965. XFCLOSE(f);
  3966. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  3967. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  3968. wc_FreeDecodedCert(&cert);
  3969. #endif
  3970. return EXPECT_RESULT();
  3971. }
  3972. #ifdef HAVE_CERT_CHAIN_VALIDATION
  3973. static int test_wolfSSL_CertRsaPss(void)
  3974. {
  3975. EXPECT_DECLS;
  3976. /* FIPS v2 and below don't support long salts. */
  3977. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  3978. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  3979. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  3980. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  3981. XFILE f = XBADFILE;
  3982. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  3983. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  3984. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  3985. RSA_MAX_SIZE >= 3072
  3986. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  3987. #endif
  3988. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  3989. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  3990. #endif
  3991. DecodedCert cert;
  3992. byte buf[4096];
  3993. int bytes = 0;
  3994. WOLFSSL_CERT_MANAGER* cm = NULL;
  3995. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3996. ExpectIntEQ(WOLFSSL_SUCCESS,
  3997. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  3998. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  3999. ExpectIntEQ(WOLFSSL_SUCCESS,
  4000. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4001. #endif
  4002. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4003. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4004. if (f != XBADFILE) {
  4005. XFCLOSE(f);
  4006. f = XBADFILE;
  4007. }
  4008. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4009. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4010. wc_FreeDecodedCert(&cert);
  4011. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4012. RSA_MAX_SIZE >= 3072
  4013. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4014. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4015. if (f != XBADFILE)
  4016. XFCLOSE(f);
  4017. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4018. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4019. wc_FreeDecodedCert(&cert);
  4020. #endif
  4021. wolfSSL_CertManagerFree(cm);
  4022. #endif
  4023. return EXPECT_RESULT();
  4024. }
  4025. #endif
  4026. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4027. {
  4028. EXPECT_DECLS;
  4029. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4030. !defined(NO_WOLFSSL_CLIENT)
  4031. WOLFSSL_CTX* ctx = NULL;
  4032. const char* ca_cert = "./certs/ca-cert.pem";
  4033. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4034. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4035. /* test good CA */
  4036. ExpectTrue(WOLFSSL_SUCCESS ==
  4037. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4038. WOLFSSL_LOAD_FLAG_NONE));
  4039. /* test expired CA */
  4040. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4041. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4042. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4043. #else
  4044. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4045. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4046. #endif
  4047. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4048. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4049. wolfSSL_CTX_free(ctx);
  4050. #endif
  4051. return EXPECT_RESULT();
  4052. }
  4053. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4054. {
  4055. EXPECT_DECLS;
  4056. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4057. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4058. WOLFSSL_CTX* ctx;
  4059. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4060. byte ca_expired_cert[TWOK_BUF];
  4061. word32 sizeof_ca_expired_cert = 0;
  4062. XFILE fp = XBADFILE;
  4063. #ifndef NO_WOLFSSL_CLIENT
  4064. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4065. #else
  4066. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4067. #endif
  4068. ExpectNotNull(ctx);
  4069. #if defined(USE_CERT_BUFFERS_2048)
  4070. /* test good CA */
  4071. ExpectTrue(WOLFSSL_SUCCESS ==
  4072. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4073. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4074. WOLFSSL_LOAD_FLAG_NONE));
  4075. #endif
  4076. /* load expired CA */
  4077. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4078. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4079. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4080. sizeof(ca_expired_cert), fp), 0);
  4081. if (fp != XBADFILE)
  4082. XFCLOSE(fp);
  4083. /* test expired CA failure */
  4084. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4085. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4086. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4087. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4088. #else
  4089. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4090. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4091. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4092. #endif
  4093. /* test expired CA success */
  4094. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4095. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4096. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4097. /* Fail when ctx is NULL. */
  4098. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4099. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4100. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4101. /* Load as modified cert - bad initial length. */
  4102. ca_expired_cert[2] = 0x7f;
  4103. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4104. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4105. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4106. wolfSSL_CTX_free(ctx);
  4107. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4108. #endif
  4109. return EXPECT_RESULT();
  4110. }
  4111. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4112. {
  4113. EXPECT_DECLS;
  4114. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4115. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4116. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4117. WOLFSSL_CTX* ctx = NULL;
  4118. #ifndef NO_WOLFSSL_CLIENT
  4119. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4120. #else
  4121. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4122. #endif
  4123. /* Public key 140 bytes??? */
  4124. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4125. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4126. WOLFSSL_SUCCESS);
  4127. wolfSSL_CTX_free(ctx);
  4128. #endif
  4129. return EXPECT_RESULT();
  4130. }
  4131. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4132. {
  4133. EXPECT_DECLS;
  4134. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4135. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4136. WOLFSSL_CTX* ctx;
  4137. WOLFSSL* ssl = NULL;
  4138. const char *certChain[] = {
  4139. "./certs/intermediate/client-int-cert.pem",
  4140. "./certs/intermediate/ca-int2-cert.pem",
  4141. "./certs/intermediate/ca-int-cert.pem",
  4142. "./certs/ca-cert.pem",
  4143. NULL
  4144. };
  4145. const char** cert;
  4146. WOLFSSL_X509* x509 = NULL;
  4147. WOLF_STACK_OF(X509)* chain = NULL;
  4148. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4149. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4150. ExpectNotNull(x509 = wolfSSL_X509_new());
  4151. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4152. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4153. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4154. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4155. wolfSSL_X509_free(x509);
  4156. x509 = NULL;
  4157. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4158. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4159. WOLFSSL_FILETYPE_PEM));
  4160. /* Do negative tests once */
  4161. if (cert == certChain) {
  4162. /* Negative tests. */
  4163. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4164. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4165. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4166. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4167. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4168. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4169. }
  4170. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4171. X509_free(x509);
  4172. x509 = NULL;
  4173. }
  4174. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4175. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4176. WOLFSSL_FILETYPE_PEM));
  4177. /* Do negative tests once */
  4178. if (cert == certChain) {
  4179. /* Negative tests. */
  4180. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4181. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4182. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4183. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4184. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4185. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4186. }
  4187. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4188. X509_free(x509);
  4189. x509 = NULL;
  4190. }
  4191. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4192. ExpectIntEQ(sk_X509_num(chain), 3);
  4193. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4194. ExpectIntEQ(sk_X509_num(chain), 3);
  4195. SSL_free(ssl);
  4196. SSL_CTX_free(ctx);
  4197. #endif
  4198. return EXPECT_RESULT();
  4199. }
  4200. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4201. {
  4202. EXPECT_DECLS;
  4203. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4204. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4205. WOLFSSL_CTX* ctx = NULL;
  4206. WOLFSSL* ssl = NULL;
  4207. const char* cert = "./certs/server-cert.pem";
  4208. unsigned char* buf = NULL;
  4209. size_t len;
  4210. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4211. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4212. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4213. /* Invalid parameters. */
  4214. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4215. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4216. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4217. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4218. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4219. server_cert_der_2048, sizeof_server_cert_der_2048,
  4220. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4221. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4222. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4223. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4224. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4225. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (long)len),
  4226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4227. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4229. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4230. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4231. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (long)len),
  4232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4233. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4234. server_cert_der_2048, sizeof_server_cert_der_2048,
  4235. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4236. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4237. (long)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4238. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (long)len),
  4239. WOLFSSL_SUCCESS);
  4240. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4241. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4242. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (long)len),
  4243. WOLFSSL_SUCCESS);
  4244. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4245. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4246. wolfSSL_free(ssl);
  4247. wolfSSL_CTX_free(ctx);
  4248. if (buf != NULL) {
  4249. free(buf);
  4250. }
  4251. #endif
  4252. return EXPECT_RESULT();
  4253. }
  4254. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4255. {
  4256. EXPECT_DECLS;
  4257. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4258. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4259. const char* server_chain_der = "./certs/server-cert-chain.der";
  4260. const char* client_single_pem = "./certs/client-cert.pem";
  4261. WOLFSSL_CTX* ctx = NULL;
  4262. (void)server_chain_der;
  4263. (void)client_single_pem;
  4264. (void)ctx;
  4265. #ifndef NO_WOLFSSL_CLIENT
  4266. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4267. #else
  4268. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4269. #endif
  4270. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4271. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4272. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4273. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4274. wolfSSL_CTX_free(ctx);
  4275. #endif
  4276. return EXPECT_RESULT();
  4277. }
  4278. static int test_wolfSSL_use_certificate_chain_file(void)
  4279. {
  4280. EXPECT_DECLS;
  4281. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4282. !defined(NO_WOLFSSL_CLIENT)
  4283. const char* server_chain_der = "./certs/server-cert-chain.der";
  4284. const char* client_single_pem = "./certs/client-cert.pem";
  4285. WOLFSSL_CTX* ctx = NULL;
  4286. WOLFSSL* ssl = NULL;
  4287. (void)server_chain_der;
  4288. (void)client_single_pem;
  4289. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4290. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4291. /* Invalid parameters. */
  4292. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4293. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4294. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4295. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4296. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4297. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4298. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4299. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4300. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4301. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4303. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4304. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4305. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4306. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4307. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4308. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4309. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4310. WOLFSSL_SUCCESS);
  4311. wolfSSL_free(ssl);
  4312. wolfSSL_CTX_free(ctx);
  4313. #endif
  4314. return EXPECT_RESULT();
  4315. }
  4316. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4317. {
  4318. EXPECT_DECLS;
  4319. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4320. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4321. WOLFSSL_CTX *ctx = NULL;
  4322. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4323. const char* dsaParamFile = "./certs/dsaparams.pem";
  4324. #endif
  4325. (void)ctx;
  4326. #ifndef NO_WOLFSSL_CLIENT
  4327. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4328. #else
  4329. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4330. #endif
  4331. /* invalid context */
  4332. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4333. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4334. /* invalid dhParamFile file */
  4335. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4336. NULL, WOLFSSL_FILETYPE_PEM));
  4337. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4338. bogusFile, WOLFSSL_FILETYPE_PEM));
  4339. /* success */
  4340. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4341. WOLFSSL_FILETYPE_PEM));
  4342. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4343. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4344. WOLFSSL_FILETYPE_PEM));
  4345. #endif
  4346. wolfSSL_CTX_free(ctx);
  4347. #endif
  4348. return EXPECT_RESULT();
  4349. }
  4350. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4351. {
  4352. EXPECT_DECLS;
  4353. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4354. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4355. WOLFSSL_CTX *ctx = NULL;
  4356. #ifndef NO_WOLFSSL_CLIENT
  4357. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4358. #else
  4359. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4360. #endif
  4361. /* invalid context */
  4362. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4363. dh_key_der_2048, sizeof_dh_key_der_2048,
  4364. WOLFSSL_FILETYPE_ASN1));
  4365. /* invalid dhParamFile file */
  4366. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4367. 0, WOLFSSL_FILETYPE_ASN1));
  4368. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4369. 0, WOLFSSL_FILETYPE_ASN1));
  4370. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4371. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4372. WOLFSSL_FILETYPE_ASN1));
  4373. /* invalid file format */
  4374. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4375. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4376. /* success */
  4377. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4378. dh_key_der_2048, sizeof_dh_key_der_2048,
  4379. WOLFSSL_FILETYPE_ASN1));
  4380. wolfSSL_CTX_free(ctx);
  4381. #endif
  4382. return EXPECT_RESULT();
  4383. }
  4384. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4385. {
  4386. EXPECT_DECLS;
  4387. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4388. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4389. WOLFSSL_CTX *ctx;
  4390. (void)ctx;
  4391. #ifndef NO_WOLFSSL_CLIENT
  4392. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4393. #else
  4394. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4395. #endif
  4396. ExpectNotNull(ctx);
  4397. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4398. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4399. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4400. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4401. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4402. dh_key_der_2048, sizeof_dh_key_der_2048,
  4403. WOLFSSL_FILETYPE_ASN1));
  4404. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4405. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4406. dh_key_der_2048, sizeof_dh_key_der_2048,
  4407. WOLFSSL_FILETYPE_ASN1));
  4408. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 2048));
  4409. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4410. dh_key_der_2048, sizeof_dh_key_der_2048,
  4411. WOLFSSL_FILETYPE_ASN1));
  4412. wolfSSL_CTX_free(ctx);
  4413. #endif
  4414. return EXPECT_RESULT();
  4415. }
  4416. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4417. {
  4418. EXPECT_DECLS;
  4419. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4420. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4421. WOLFSSL_CTX* ctx = NULL;
  4422. const char* derCert = "./certs/server-cert.der";
  4423. const char* nullPath = NULL;
  4424. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4425. const char* emptyPath = "";
  4426. /* der load Case 1 ctx NULL */
  4427. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4428. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4429. #ifndef NO_WOLFSSL_CLIENT
  4430. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4431. #else
  4432. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4433. #endif
  4434. /* Case 2 filePath NULL */
  4435. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4436. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4437. /* Case 3 invalid format */
  4438. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4439. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4440. /* Case 4 filePath not valid */
  4441. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4442. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4443. /* Case 5 filePath empty */
  4444. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4445. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4446. #ifndef NO_RSA
  4447. /* Case 6 success case */
  4448. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4449. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4450. #endif
  4451. wolfSSL_CTX_free(ctx);
  4452. #endif
  4453. return EXPECT_RESULT();
  4454. }
  4455. static int test_wolfSSL_CTX_enable_disable(void)
  4456. {
  4457. EXPECT_DECLS;
  4458. #ifndef NO_CERTS
  4459. WOLFSSL_CTX* ctx = NULL;
  4460. #ifdef HAVE_CRL
  4461. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4462. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4463. #endif
  4464. #ifdef HAVE_OCSP
  4465. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4466. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4467. #endif
  4468. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4469. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4470. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4471. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4472. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4473. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4474. #endif
  4475. #ifndef NO_WOLFSSL_CLIENT
  4476. #ifdef HAVE_EXTENDED_MASTER
  4477. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4478. #endif
  4479. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4480. #ifdef HAVE_EXTENDED_MASTER
  4481. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4482. #endif
  4483. #elif !defined(NO_WOLFSSL_SERVER)
  4484. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4485. #endif
  4486. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4487. #ifdef HAVE_CRL
  4488. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4489. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4490. #endif
  4491. #ifdef HAVE_OCSP
  4492. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4493. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4494. WOLFSSL_SUCCESS);
  4495. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4496. WOLFSSL_SUCCESS);
  4497. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4498. WOLFSSL_SUCCESS);
  4499. #endif
  4500. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4501. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4502. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4503. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4504. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4505. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4506. #endif
  4507. wolfSSL_CTX_free(ctx);
  4508. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4509. #endif /* NO_CERTS */
  4510. return EXPECT_RESULT();
  4511. }
  4512. static int test_wolfSSL_CTX_ticket_API(void)
  4513. {
  4514. EXPECT_DECLS;
  4515. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4516. WOLFSSL_CTX* ctx = NULL;
  4517. void *userCtx = (void*)"this is my ctx";
  4518. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4519. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4520. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4521. wolfSSL_CTX_free(ctx);
  4522. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4523. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4524. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4525. return EXPECT_RESULT();
  4526. }
  4527. static int test_wolfSSL_set_minmax_proto_version(void)
  4528. {
  4529. EXPECT_DECLS;
  4530. #ifdef OPENSSL_EXTRA
  4531. WOLFSSL_CTX *ctx = NULL;
  4532. WOLFSSL *ssl = NULL;
  4533. (void)ssl;
  4534. #ifndef NO_WOLFSSL_CLIENT
  4535. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4536. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4537. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4538. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4539. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4540. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4541. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4542. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4543. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4544. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4545. wolfSSL_free(ssl);
  4546. wolfSSL_CTX_free(ctx);
  4547. ctx = NULL;
  4548. #endif
  4549. #ifndef NO_WOLFSSL_SERVER
  4550. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4551. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4552. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4553. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4554. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4555. wolfSSL_CTX_free(ctx);
  4556. #endif
  4557. #endif
  4558. return EXPECT_RESULT();
  4559. }
  4560. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4561. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4562. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4563. {
  4564. EXPECT_DECLS;
  4565. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4566. return EXPECT_RESULT();
  4567. }
  4568. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4569. {
  4570. EXPECT_DECLS;
  4571. /* Set TLS 1.2 */
  4572. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4573. WOLFSSL_SUCCESS);
  4574. return EXPECT_RESULT();
  4575. }
  4576. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4577. * what was set at ctx creation. */
  4578. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4579. {
  4580. EXPECT_DECLS;
  4581. test_ssl_cbf client_cbs;
  4582. test_ssl_cbf server_cbs;
  4583. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4584. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4585. client_cbs.method = wolfTLS_client_method;
  4586. server_cbs.method = wolfTLS_server_method;
  4587. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4588. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4589. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4590. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4591. &server_cbs, NULL), TEST_SUCCESS);
  4592. return EXPECT_RESULT();
  4593. }
  4594. #else
  4595. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4596. {
  4597. return TEST_SKIPPED;
  4598. }
  4599. #endif
  4600. /*----------------------------------------------------------------------------*
  4601. | SSL
  4602. *----------------------------------------------------------------------------*/
  4603. static int test_server_wolfSSL_new(void)
  4604. {
  4605. EXPECT_DECLS;
  4606. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4607. !defined(NO_WOLFSSL_SERVER)
  4608. WOLFSSL_CTX *ctx = NULL;
  4609. WOLFSSL_CTX *ctx_nocert = NULL;
  4610. WOLFSSL *ssl = NULL;
  4611. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4612. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4613. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4614. WOLFSSL_FILETYPE_PEM));
  4615. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4616. WOLFSSL_FILETYPE_PEM));
  4617. /* invalid context */
  4618. ExpectNull(ssl = wolfSSL_new(NULL));
  4619. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4620. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4621. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4622. #endif
  4623. /* success */
  4624. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4625. wolfSSL_free(ssl);
  4626. wolfSSL_CTX_free(ctx);
  4627. wolfSSL_CTX_free(ctx_nocert);
  4628. #endif
  4629. return EXPECT_RESULT();
  4630. }
  4631. static int test_client_wolfSSL_new(void)
  4632. {
  4633. EXPECT_DECLS;
  4634. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4635. !defined(NO_WOLFSSL_CLIENT)
  4636. WOLFSSL_CTX *ctx = NULL;
  4637. WOLFSSL_CTX *ctx_nocert = NULL;
  4638. WOLFSSL *ssl = NULL;
  4639. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4640. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4641. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4642. /* invalid context */
  4643. ExpectNull(ssl = wolfSSL_new(NULL));
  4644. /* success */
  4645. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4646. wolfSSL_free(ssl);
  4647. ssl = NULL;
  4648. /* success */
  4649. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4650. wolfSSL_free(ssl);
  4651. wolfSSL_CTX_free(ctx);
  4652. wolfSSL_CTX_free(ctx_nocert);
  4653. #endif
  4654. return EXPECT_RESULT();
  4655. }
  4656. static int test_wolfSSL_SetTmpDH_file(void)
  4657. {
  4658. EXPECT_DECLS;
  4659. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4660. !defined(NO_WOLFSSL_SERVER)
  4661. WOLFSSL_CTX *ctx = NULL;
  4662. WOLFSSL *ssl = NULL;
  4663. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4664. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4665. const char* dsaParamFile = "./certs/dsaparams.pem";
  4666. #endif
  4667. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4668. #ifndef NO_RSA
  4669. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4670. WOLFSSL_FILETYPE_PEM));
  4671. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4672. WOLFSSL_FILETYPE_PEM));
  4673. #elif defined(HAVE_ECC)
  4674. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4675. WOLFSSL_FILETYPE_PEM));
  4676. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4677. WOLFSSL_FILETYPE_PEM));
  4678. #elif defined(HAVE_ED25519)
  4679. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4680. WOLFSSL_FILETYPE_PEM));
  4681. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4682. WOLFSSL_FILETYPE_PEM));
  4683. #elif defined(HAVE_ED448)
  4684. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4685. WOLFSSL_FILETYPE_PEM));
  4686. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4687. WOLFSSL_FILETYPE_PEM));
  4688. #endif
  4689. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4690. /* invalid ssl */
  4691. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4692. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4693. /* invalid dhParamFile file */
  4694. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4695. NULL, WOLFSSL_FILETYPE_PEM));
  4696. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4697. bogusFile, WOLFSSL_FILETYPE_PEM));
  4698. /* success */
  4699. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4700. WOLFSSL_FILETYPE_PEM));
  4701. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4702. WOLFSSL_FILETYPE_PEM));
  4703. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4704. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4705. WOLFSSL_FILETYPE_PEM));
  4706. #endif
  4707. wolfSSL_free(ssl);
  4708. wolfSSL_CTX_free(ctx);
  4709. #endif
  4710. return EXPECT_RESULT();
  4711. }
  4712. static int test_wolfSSL_SetTmpDH_buffer(void)
  4713. {
  4714. EXPECT_DECLS;
  4715. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4716. WOLFSSL_CTX *ctx = NULL;
  4717. WOLFSSL *ssl = NULL;
  4718. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4719. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4720. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4721. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4722. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4723. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4724. /* invalid ssl */
  4725. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4726. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4727. /* invalid dhParamFile file */
  4728. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4729. 0, WOLFSSL_FILETYPE_ASN1));
  4730. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4731. WOLFSSL_FILETYPE_ASN1));
  4732. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4733. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4734. /* success */
  4735. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4736. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4737. wolfSSL_free(ssl);
  4738. wolfSSL_CTX_free(ctx);
  4739. #endif
  4740. return EXPECT_RESULT();
  4741. }
  4742. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4743. {
  4744. EXPECT_DECLS;
  4745. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4746. WOLFSSL_CTX *ctx = NULL;
  4747. WOLFSSL_CTX *ctx2 = NULL;
  4748. WOLFSSL *ssl = NULL;
  4749. WOLFSSL *ssl2 = NULL;
  4750. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4751. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4752. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4753. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4754. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4755. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4756. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4757. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4758. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4759. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4760. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4761. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4762. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4763. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4764. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4765. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4766. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4767. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4768. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4769. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4770. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4771. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4772. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4773. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4774. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4775. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4776. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4777. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4778. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4779. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4780. wolfSSL_free(ssl2);
  4781. wolfSSL_CTX_free(ctx2);
  4782. wolfSSL_free(ssl);
  4783. wolfSSL_CTX_free(ctx);
  4784. #endif
  4785. return EXPECT_RESULT();
  4786. }
  4787. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  4788. * allowed.
  4789. * POST: return 1 on success.
  4790. */
  4791. static int test_wolfSSL_SetMinVersion(void)
  4792. {
  4793. int res = TEST_SKIPPED;
  4794. #ifndef NO_WOLFSSL_CLIENT
  4795. int failFlag = WOLFSSL_SUCCESS;
  4796. WOLFSSL_CTX* ctx = NULL;
  4797. WOLFSSL* ssl = NULL;
  4798. int itr;
  4799. #ifndef NO_OLD_TLS
  4800. const int versions[] = {
  4801. #ifdef WOLFSSL_ALLOW_TLSV10
  4802. WOLFSSL_TLSV1,
  4803. #endif
  4804. WOLFSSL_TLSV1_1,
  4805. WOLFSSL_TLSV1_2};
  4806. #elif !defined(WOLFSSL_NO_TLS12)
  4807. const int versions[] = { WOLFSSL_TLSV1_2 };
  4808. #else
  4809. const int versions[] = { WOLFSSL_TLSV1_3 };
  4810. #endif
  4811. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4812. ssl = wolfSSL_new(ctx);
  4813. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  4814. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  4815. failFlag = WOLFSSL_FAILURE;
  4816. }
  4817. }
  4818. wolfSSL_free(ssl);
  4819. wolfSSL_CTX_free(ctx);
  4820. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  4821. #endif
  4822. return res;
  4823. } /* END test_wolfSSL_SetMinVersion */
  4824. #ifdef OPENSSL_EXTRA
  4825. static int test_EC25519(void)
  4826. {
  4827. EXPECT_DECLS;
  4828. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  4829. byte priv[CURVE25519_KEYSIZE];
  4830. unsigned int privSz = CURVE25519_KEYSIZE;
  4831. byte pub[CURVE25519_KEYSIZE];
  4832. unsigned int pubSz = CURVE25519_KEYSIZE;
  4833. byte priv2[CURVE25519_KEYSIZE];
  4834. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  4835. byte pub2[CURVE25519_KEYSIZE];
  4836. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  4837. byte shared[CURVE25519_KEYSIZE];
  4838. unsigned int sharedSz = CURVE25519_KEYSIZE;
  4839. byte shared2[CURVE25519_KEYSIZE];
  4840. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  4841. /* Bad parameter testing of key generation. */
  4842. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  4843. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  4844. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  4845. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  4846. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  4847. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  4848. /* Bad length */
  4849. privSz = 1;
  4850. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4851. privSz = CURVE25519_KEYSIZE;
  4852. pubSz = 1;
  4853. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4854. pubSz = CURVE25519_KEYSIZE;
  4855. /* Good case of generating key. */
  4856. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  4857. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  4858. 1);
  4859. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  4860. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  4861. /* Bad parameter testing of shared key. */
  4862. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  4863. NULL, pubSz), 0);
  4864. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  4865. NULL, pubSz), 0);
  4866. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  4867. pub, pubSz), 0);
  4868. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  4869. pub, pubSz), 0);
  4870. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4871. NULL, pubSz), 0);
  4872. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  4873. pub, pubSz), 0);
  4874. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  4875. pub, pubSz), 0);
  4876. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  4877. pub, pubSz), 0);
  4878. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4879. NULL, pubSz), 0);
  4880. /* Bad length. */
  4881. sharedSz = 1;
  4882. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4883. pub, pubSz), 0);
  4884. sharedSz = CURVE25519_KEYSIZE;
  4885. privSz = 1;
  4886. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4887. pub, pubSz), 0);
  4888. privSz = CURVE25519_KEYSIZE;
  4889. pubSz = 1;
  4890. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4891. pub, pubSz), 0);
  4892. pubSz = CURVE25519_KEYSIZE;
  4893. /* Good case of shared key. */
  4894. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  4895. pub2, pub2Sz), 1);
  4896. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  4897. pub, pubSz), 1);
  4898. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  4899. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  4900. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  4901. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  4902. return EXPECT_RESULT();
  4903. }
  4904. static int test_ED25519(void)
  4905. {
  4906. EXPECT_DECLS;
  4907. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  4908. defined(WOLFSSL_KEY_GEN)
  4909. byte priv[ED25519_PRV_KEY_SIZE];
  4910. unsigned int privSz = (unsigned int)sizeof(priv);
  4911. byte pub[ED25519_PUB_KEY_SIZE];
  4912. unsigned int pubSz = (unsigned int)sizeof(pub);
  4913. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  4914. const char* msg = TEST_STRING;
  4915. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  4916. byte sig[ED25519_SIG_SIZE];
  4917. unsigned int sigSz = (unsigned int)sizeof(sig);
  4918. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  4919. /* Bad parameter testing of key generation. */
  4920. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  4921. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  4922. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  4923. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  4924. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  4925. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  4926. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  4927. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  4928. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  4929. /* Bad length. */
  4930. privSz = 1;
  4931. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4932. privSz = ED25519_PRV_KEY_SIZE;
  4933. pubSz = 1;
  4934. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  4935. pubSz = ED25519_PUB_KEY_SIZE;
  4936. /* Good case of generating key. */
  4937. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  4938. 1);
  4939. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  4940. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  4941. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  4942. /* Bad parameter testing of signing. */
  4943. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  4944. NULL), 0);
  4945. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  4946. NULL), 0);
  4947. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  4948. NULL), 0);
  4949. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  4950. NULL), 0);
  4951. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  4952. &sigSz), 0);
  4953. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  4954. &sigSz), 0);
  4955. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  4956. &sigSz), 0);
  4957. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  4958. &sigSz), 0);
  4959. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4960. NULL), 0);
  4961. /* Bad length. */
  4962. privSz = 1;
  4963. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4964. &sigSz), 0);
  4965. privSz = ED25519_PRV_KEY_SIZE;
  4966. sigSz = 1;
  4967. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4968. &sigSz), 0);
  4969. sigSz = ED25519_SIG_SIZE;
  4970. /* Good case of signing. */
  4971. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  4972. &sigSz), 1);
  4973. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  4974. #ifdef HAVE_ED25519_VERIFY
  4975. /* Bad parameter testing of verification. */
  4976. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  4977. sigSz), 0);
  4978. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  4979. sigSz), 0);
  4980. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  4981. sigSz), 0);
  4982. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  4983. sigSz), 0);
  4984. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  4985. sigSz), 0);
  4986. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  4987. sigSz), 0);
  4988. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  4989. sigSz), 0);
  4990. /* Bad length. */
  4991. pubSz = 1;
  4992. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  4993. sigSz), 0);
  4994. pubSz = ED25519_PUB_KEY_SIZE;
  4995. sigSz = 1;
  4996. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  4997. sigSz), 0);
  4998. sigSz = ED25519_SIG_SIZE;
  4999. /* Good case of verification. */
  5000. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5001. sigSz), 1);
  5002. /* Bad signature. */
  5003. if (EXPECT_SUCCESS()) {
  5004. sig[1] ^= 0x80;
  5005. }
  5006. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5007. sigSz), 0);
  5008. #endif /* HAVE_ED25519_VERIFY */
  5009. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5010. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5011. return EXPECT_RESULT();
  5012. }
  5013. static int test_EC448(void)
  5014. {
  5015. EXPECT_DECLS;
  5016. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5017. byte priv[CURVE448_KEY_SIZE];
  5018. unsigned int privSz = CURVE448_KEY_SIZE;
  5019. byte pub[CURVE448_KEY_SIZE];
  5020. unsigned int pubSz = CURVE448_KEY_SIZE;
  5021. byte priv2[CURVE448_KEY_SIZE];
  5022. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5023. byte pub2[CURVE448_KEY_SIZE];
  5024. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5025. byte shared[CURVE448_KEY_SIZE];
  5026. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5027. byte shared2[CURVE448_KEY_SIZE];
  5028. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5029. /* Bad parameter testing of key generation. */
  5030. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5031. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5032. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5033. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5034. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5035. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5036. /* Bad length. */
  5037. privSz = 1;
  5038. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5039. privSz = CURVE448_KEY_SIZE;
  5040. pubSz = 1;
  5041. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5042. pubSz = CURVE448_KEY_SIZE;
  5043. /* Good case of generating key. */
  5044. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5045. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5046. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5047. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5048. /* Bad parameter testing of shared key. */
  5049. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5050. NULL, pubSz), 0);
  5051. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5052. NULL, pubSz), 0);
  5053. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5054. pub, pubSz), 0);
  5055. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5056. pub, pubSz), 0);
  5057. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5058. NULL, pubSz), 0);
  5059. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5060. pub, pubSz), 0);
  5061. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5062. pub, pubSz), 0);
  5063. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5064. pub, pubSz), 0);
  5065. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5066. NULL, pubSz), 0);
  5067. /* Bad length. */
  5068. sharedSz = 1;
  5069. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5070. pub, pubSz), 0);
  5071. sharedSz = CURVE448_KEY_SIZE;
  5072. privSz = 1;
  5073. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5074. pub, pubSz), 0);
  5075. privSz = CURVE448_KEY_SIZE;
  5076. pubSz = 1;
  5077. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5078. pub, pubSz), 0);
  5079. pubSz = CURVE448_KEY_SIZE;
  5080. /* Good case of shared key. */
  5081. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5082. pub2, pub2Sz), 1);
  5083. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5084. pub, pubSz), 1);
  5085. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5086. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5087. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5088. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5089. return EXPECT_RESULT();
  5090. }
  5091. static int test_ED448(void)
  5092. {
  5093. EXPECT_DECLS;
  5094. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5095. defined(WOLFSSL_KEY_GEN)
  5096. byte priv[ED448_PRV_KEY_SIZE];
  5097. unsigned int privSz = (unsigned int)sizeof(priv);
  5098. byte pub[ED448_PUB_KEY_SIZE];
  5099. unsigned int pubSz = (unsigned int)sizeof(pub);
  5100. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5101. const char* msg = TEST_STRING;
  5102. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5103. byte sig[ED448_SIG_SIZE];
  5104. unsigned int sigSz = (unsigned int)sizeof(sig);
  5105. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5106. /* Bad parameter testing of key generation. */
  5107. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5108. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5109. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5110. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5111. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5112. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5113. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5114. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5115. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5116. /* Bad length. */
  5117. privSz = 1;
  5118. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5119. privSz = ED448_PRV_KEY_SIZE;
  5120. pubSz = 1;
  5121. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5122. pubSz = ED448_PUB_KEY_SIZE;
  5123. /* Good case of generating key. */
  5124. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5125. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5126. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5127. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5128. /* Bad parameter testing of signing. */
  5129. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5130. NULL), 0);
  5131. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5132. NULL), 0);
  5133. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5134. NULL), 0);
  5135. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5136. NULL), 0);
  5137. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5138. &sigSz), 0);
  5139. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5140. &sigSz), 0);
  5141. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5142. &sigSz), 0);
  5143. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5144. &sigSz), 0);
  5145. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5146. NULL), 0);
  5147. /* Bad length. */
  5148. privSz = 1;
  5149. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5150. &sigSz), 0);
  5151. privSz = ED448_PRV_KEY_SIZE;
  5152. sigSz = 1;
  5153. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5154. &sigSz), 0);
  5155. sigSz = ED448_SIG_SIZE;
  5156. /* Good case of signing. */
  5157. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5158. &sigSz), 1);
  5159. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5160. #ifdef HAVE_ED448_VERIFY
  5161. /* Bad parameter testing of verification. */
  5162. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5163. sigSz), 0);
  5164. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5165. sigSz), 0);
  5166. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5167. sigSz), 0);
  5168. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5169. sigSz), 0);
  5170. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5171. sigSz), 0);
  5172. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5173. sigSz), 0);
  5174. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5175. sigSz), 0);
  5176. /* Bad length. */
  5177. pubSz = 1;
  5178. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5179. sigSz), 0);
  5180. pubSz = ED448_PUB_KEY_SIZE;
  5181. sigSz = 1;
  5182. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5183. sigSz), 0);
  5184. sigSz = ED448_SIG_SIZE;
  5185. /* Good case of verification. */
  5186. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5187. sigSz), 1);
  5188. /* Bad signature. */
  5189. if (EXPECT_SUCCESS()) {
  5190. sig[1] ^= 0x80;
  5191. }
  5192. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5193. sigSz), 0);
  5194. #endif /* HAVE_ED448_VERIFY */
  5195. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5196. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5197. return EXPECT_RESULT();
  5198. }
  5199. #endif /* OPENSSL_EXTRA */
  5200. #include <wolfssl/openssl/pem.h>
  5201. /*----------------------------------------------------------------------------*
  5202. | EVP
  5203. *----------------------------------------------------------------------------*/
  5204. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5205. {
  5206. EXPECT_DECLS;
  5207. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5208. WOLFSSL_BIO* rbio = NULL;
  5209. WOLFSSL_BIO* wbio = NULL;
  5210. WOLFSSL_EVP_PKEY* pkey = NULL;
  5211. char line[256] = { 0 };
  5212. char line1[256] = { 0 };
  5213. int i = 0;
  5214. /* test error cases */
  5215. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5216. /*
  5217. * test RSA public key print
  5218. * in this test, pass '3' for indent
  5219. */
  5220. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5221. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5222. sizeof_client_keypub_der_1024));
  5223. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5224. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5225. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5226. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5227. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5228. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5229. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5230. strcpy(line1, " Modulus:\n");
  5231. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5232. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5233. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5234. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5235. /* skip to the end of modulus element*/
  5236. for (i = 0; i < 8 ;i++) {
  5237. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5238. }
  5239. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5240. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5241. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5242. /* should reach EOF */
  5243. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5244. EVP_PKEY_free(pkey);
  5245. pkey = NULL;
  5246. BIO_free(rbio);
  5247. BIO_free(wbio);
  5248. rbio = NULL;
  5249. wbio = NULL;
  5250. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5251. /*
  5252. * test DSA public key print
  5253. */
  5254. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5255. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5256. sizeof_dsa_pub_key_der_2048));
  5257. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5258. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5259. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5260. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5261. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5262. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5263. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5264. strcpy(line1, "pub:\n");
  5265. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5266. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5267. strcpy(line1,
  5268. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5269. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5270. /* skip to the end of pub element*/
  5271. for (i = 0; i < 17 ;i++) {
  5272. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5273. }
  5274. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5275. strcpy(line1, "P:\n");
  5276. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5277. /* skip to the end of P element*/
  5278. for (i = 0; i < 18 ;i++) {
  5279. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5280. }
  5281. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5282. strcpy(line1, "Q:\n");
  5283. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5284. /* skip to the end of Q element*/
  5285. for (i = 0; i < 3 ;i++) {
  5286. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5287. }
  5288. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5289. strcpy(line1, "G:\n");
  5290. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5291. /* skip to the end of G element*/
  5292. for (i = 0; i < 18 ;i++) {
  5293. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5294. }
  5295. /* should reach EOF */
  5296. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5297. EVP_PKEY_free(pkey);
  5298. pkey = NULL;
  5299. BIO_free(rbio);
  5300. BIO_free(wbio);
  5301. rbio = NULL;
  5302. wbio = NULL;
  5303. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5304. /*
  5305. * test ECC public key print
  5306. */
  5307. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5308. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5309. sizeof_ecc_clikeypub_der_256));
  5310. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5311. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5312. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5313. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5314. strcpy(line1, "Public-Key: (256 bit)\n");
  5315. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5316. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5317. strcpy(line1, "pub:\n");
  5318. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5319. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5320. strcpy(line1,
  5321. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5322. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5323. /* skip to the end of pub element*/
  5324. for (i = 0; i < 4 ;i++) {
  5325. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5326. }
  5327. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5328. strcpy(line1, "ASN1 OID: prime256v1\n");
  5329. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5330. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5331. strcpy(line1, "NIST CURVE: P-256\n");
  5332. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5333. /* should reach EOF */
  5334. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5335. EVP_PKEY_free(pkey);
  5336. pkey = NULL;
  5337. BIO_free(rbio);
  5338. BIO_free(wbio);
  5339. rbio = NULL;
  5340. wbio = NULL;
  5341. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5342. /*
  5343. * test DH public key print
  5344. */
  5345. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5346. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5347. sizeof_dh_pub_key_der_2048));
  5348. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5349. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5350. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5351. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5352. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5353. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5354. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5355. strcpy(line1, "public-key:\n");
  5356. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5357. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5358. strcpy(line1,
  5359. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5360. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5361. /* skip to the end of public-key element*/
  5362. for (i = 0; i < 17 ;i++) {
  5363. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5364. }
  5365. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5366. strcpy(line1, "prime:\n");
  5367. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5368. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5369. strcpy(line1,
  5370. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5371. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5372. /* skip to the end of prime element*/
  5373. for (i = 0; i < 17 ;i++) {
  5374. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5375. }
  5376. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5377. strcpy(line1, "generator: 2 (0x02)\n");
  5378. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5379. /* should reach EOF */
  5380. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5381. EVP_PKEY_free(pkey);
  5382. pkey = NULL;
  5383. BIO_free(rbio);
  5384. BIO_free(wbio);
  5385. rbio = NULL;
  5386. wbio = NULL;
  5387. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5388. /* to prevent "unused variable" warning */
  5389. (void)pkey;
  5390. (void)wbio;
  5391. (void)rbio;
  5392. (void)line;
  5393. (void)line1;
  5394. (void)i;
  5395. #endif /* OPENSSL_EXTRA */
  5396. return EXPECT_RESULT();
  5397. }
  5398. /* Test functions for base64 encode/decode */
  5399. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5400. {
  5401. EXPECT_DECLS;
  5402. #if defined(OPENSSL_EXTRA) && \
  5403. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5404. EVP_ENCODE_CTX* ctx = NULL;
  5405. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5406. ExpectIntEQ(ctx->remaining,0);
  5407. ExpectIntEQ(ctx->data[0],0);
  5408. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1],0);
  5409. EVP_ENCODE_CTX_free(ctx);
  5410. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5411. return EXPECT_RESULT();
  5412. }
  5413. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5414. {
  5415. EXPECT_DECLS;
  5416. #if defined(OPENSSL_EXTRA) && \
  5417. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5418. EVP_ENCODE_CTX* ctx = NULL;
  5419. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5420. EVP_ENCODE_CTX_free(ctx);
  5421. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5422. return EXPECT_RESULT();
  5423. }
  5424. static int test_wolfSSL_EVP_EncodeInit(void)
  5425. {
  5426. EXPECT_DECLS;
  5427. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5428. EVP_ENCODE_CTX* ctx = NULL;
  5429. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5430. ExpectIntEQ(ctx->remaining, 0);
  5431. ExpectIntEQ(ctx->data[0], 0);
  5432. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5433. if (ctx != NULL) {
  5434. /* make ctx dirty */
  5435. ctx->remaining = 10;
  5436. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5437. }
  5438. EVP_EncodeInit(ctx);
  5439. ExpectIntEQ(ctx->remaining, 0);
  5440. ExpectIntEQ(ctx->data[0], 0);
  5441. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5442. EVP_ENCODE_CTX_free(ctx);
  5443. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5444. return EXPECT_RESULT();
  5445. }
  5446. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5447. {
  5448. EXPECT_DECLS;
  5449. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5450. int outl;
  5451. int total;
  5452. const unsigned char plain0[] = {"Th"};
  5453. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5454. const unsigned char plain2[] = {"This is additional data."};
  5455. const unsigned char encBlock0[] = {"VGg="};
  5456. const unsigned char enc0[] = {"VGg=\n"};
  5457. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5458. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5459. const unsigned char enc2[] =
  5460. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5461. unsigned char encOutBuff[300];
  5462. EVP_ENCODE_CTX* ctx = NULL;
  5463. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5464. EVP_EncodeInit(ctx);
  5465. /* illegal parameter test */
  5466. ExpectIntEQ(
  5467. EVP_EncodeUpdate(
  5468. NULL, /* pass NULL as ctx */
  5469. encOutBuff,
  5470. &outl,
  5471. plain1,
  5472. sizeof(plain1)-1),
  5473. 0 /* expected result code 0: fail */
  5474. );
  5475. ExpectIntEQ(
  5476. EVP_EncodeUpdate(
  5477. ctx,
  5478. NULL, /* pass NULL as out buff */
  5479. &outl,
  5480. plain1,
  5481. sizeof(plain1)-1),
  5482. 0 /* expected result code 0: fail */
  5483. );
  5484. ExpectIntEQ(
  5485. EVP_EncodeUpdate(
  5486. ctx,
  5487. encOutBuff,
  5488. NULL, /* pass NULL as outl */
  5489. plain1,
  5490. sizeof(plain1)-1),
  5491. 0 /* expected result code 0: fail */
  5492. );
  5493. ExpectIntEQ(
  5494. EVP_EncodeUpdate(
  5495. ctx,
  5496. encOutBuff,
  5497. &outl,
  5498. NULL, /* pass NULL as in */
  5499. sizeof(plain1)-1),
  5500. 0 /* expected result code 0: fail */
  5501. );
  5502. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5503. /* meaningless parameter test */
  5504. ExpectIntEQ(
  5505. EVP_EncodeUpdate(
  5506. ctx,
  5507. encOutBuff,
  5508. &outl,
  5509. plain1,
  5510. 0), /* pass zero input */
  5511. 1 /* expected result code 1: success */
  5512. );
  5513. /* very small data encoding test */
  5514. EVP_EncodeInit(ctx);
  5515. ExpectIntEQ(
  5516. EVP_EncodeUpdate(
  5517. ctx,
  5518. encOutBuff,
  5519. &outl,
  5520. plain0,
  5521. sizeof(plain0)-1),
  5522. 1 /* expected result code 1: success */
  5523. );
  5524. ExpectIntEQ(outl,0);
  5525. if (EXPECT_SUCCESS()) {
  5526. EVP_EncodeFinal(
  5527. ctx,
  5528. encOutBuff + outl,
  5529. &outl);
  5530. }
  5531. ExpectIntEQ( outl, sizeof(enc0)-1);
  5532. ExpectIntEQ(
  5533. XSTRNCMP(
  5534. (const char*)encOutBuff,
  5535. (const char*)enc0,sizeof(enc0) ),
  5536. 0);
  5537. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5538. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5539. sizeof(encBlock0)-1);
  5540. ExpectStrEQ(encOutBuff, encBlock0);
  5541. /* pass small size( < 48bytes ) input, then make sure they are not
  5542. * encoded and just stored in ctx
  5543. */
  5544. EVP_EncodeInit(ctx);
  5545. total = 0;
  5546. outl = 0;
  5547. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5548. ExpectIntEQ(
  5549. EVP_EncodeUpdate(
  5550. ctx,
  5551. encOutBuff, /* buffer for output */
  5552. &outl, /* size of output */
  5553. plain1, /* input */
  5554. sizeof(plain1)-1), /* size of input */
  5555. 1); /* expected result code 1:success */
  5556. total += outl;
  5557. ExpectIntEQ(outl, 0); /* no output expected */
  5558. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5559. ExpectTrue(
  5560. XSTRNCMP((const char*)(ctx->data),
  5561. (const char*)plain1,
  5562. ctx->remaining) ==0 );
  5563. ExpectTrue(encOutBuff[0] == 0);
  5564. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5565. * the stored data and the new input together
  5566. */
  5567. ExpectIntEQ(
  5568. EVP_EncodeUpdate(
  5569. ctx,
  5570. encOutBuff + outl, /* buffer for output */
  5571. &outl, /* size of output */
  5572. plain2, /* additional input */
  5573. sizeof(plain2) -1), /* size of additional input */
  5574. 1); /* expected result code 1:success */
  5575. total += outl;
  5576. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5577. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5578. ExpectIntEQ(
  5579. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5580. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5581. EVP_EncodeFinal(
  5582. ctx,
  5583. encOutBuff + outl,
  5584. &outl);
  5585. total += outl;
  5586. ExpectIntNE(total,0);
  5587. ExpectIntNE(outl,0);
  5588. ExpectIntEQ(XSTRNCMP(
  5589. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5590. /* test with illeagal parameters */
  5591. outl = 1;
  5592. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5593. ExpectIntEQ(outl, 0);
  5594. outl = 1;
  5595. EVP_EncodeFinal(ctx, NULL, &outl);
  5596. ExpectIntEQ(outl, 0);
  5597. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5598. EVP_EncodeFinal(NULL, NULL, NULL);
  5599. EVP_ENCODE_CTX_free(ctx);
  5600. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5601. return EXPECT_RESULT();
  5602. }
  5603. static int test_wolfSSL_EVP_EncodeFinal(void)
  5604. {
  5605. int res = TEST_SKIPPED;
  5606. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5607. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5608. * test_wolfSSL_EVP_EncodeUpdate
  5609. */
  5610. res = TEST_SUCCESS;
  5611. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5612. return res;
  5613. }
  5614. static int test_wolfSSL_EVP_DecodeInit(void)
  5615. {
  5616. EXPECT_DECLS;
  5617. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5618. EVP_ENCODE_CTX* ctx = NULL;
  5619. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5620. ExpectIntEQ( ctx->remaining,0);
  5621. ExpectIntEQ( ctx->data[0],0);
  5622. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5623. if (ctx != NULL) {
  5624. /* make ctx dirty */
  5625. ctx->remaining = 10;
  5626. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5627. }
  5628. EVP_DecodeInit(ctx);
  5629. ExpectIntEQ( ctx->remaining,0);
  5630. ExpectIntEQ( ctx->data[0],0);
  5631. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5632. EVP_ENCODE_CTX_free(ctx);
  5633. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5634. return EXPECT_RESULT();
  5635. }
  5636. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5637. {
  5638. EXPECT_DECLS;
  5639. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5640. int outl;
  5641. unsigned char decOutBuff[300];
  5642. EVP_ENCODE_CTX* ctx = NULL;
  5643. static const unsigned char enc1[] =
  5644. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5645. /* const unsigned char plain1[] =
  5646. {"This is a base64 decoding test."} */
  5647. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5648. EVP_DecodeInit(ctx);
  5649. /* illegal parameter tests */
  5650. /* pass NULL as ctx */
  5651. ExpectIntEQ(
  5652. EVP_DecodeUpdate(
  5653. NULL, /* pass NULL as ctx */
  5654. decOutBuff,
  5655. &outl,
  5656. enc1,
  5657. sizeof(enc1)-1),
  5658. -1 /* expected result code -1: fail */
  5659. );
  5660. ExpectIntEQ( outl, 0);
  5661. /* pass NULL as output */
  5662. ExpectIntEQ(
  5663. EVP_DecodeUpdate(
  5664. ctx,
  5665. NULL, /* pass NULL as out buff */
  5666. &outl,
  5667. enc1,
  5668. sizeof(enc1)-1),
  5669. -1 /* expected result code -1: fail */
  5670. );
  5671. ExpectIntEQ( outl, 0);
  5672. /* pass NULL as outl */
  5673. ExpectIntEQ(
  5674. EVP_DecodeUpdate(
  5675. ctx,
  5676. decOutBuff,
  5677. NULL, /* pass NULL as outl */
  5678. enc1,
  5679. sizeof(enc1)-1),
  5680. -1 /* expected result code -1: fail */
  5681. );
  5682. /* pass NULL as input */
  5683. ExpectIntEQ(
  5684. EVP_DecodeUpdate(
  5685. ctx,
  5686. decOutBuff,
  5687. &outl,
  5688. NULL, /* pass NULL as in */
  5689. sizeof(enc1)-1),
  5690. -1 /* expected result code -1: fail */
  5691. );
  5692. ExpectIntEQ( outl, 0);
  5693. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5694. /* pass zero length input */
  5695. ExpectIntEQ(
  5696. EVP_DecodeUpdate(
  5697. ctx,
  5698. decOutBuff,
  5699. &outl,
  5700. enc1,
  5701. 0), /* pass zero as input len */
  5702. 1 /* expected result code 1: success */
  5703. );
  5704. /* decode correct base64 string */
  5705. {
  5706. static const unsigned char enc2[] =
  5707. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5708. static const unsigned char plain2[] =
  5709. {"This is a base64 decoding test."};
  5710. EVP_EncodeInit(ctx);
  5711. ExpectIntEQ(
  5712. EVP_DecodeUpdate(
  5713. ctx,
  5714. decOutBuff,
  5715. &outl,
  5716. enc2,
  5717. sizeof(enc2)-1),
  5718. 0 /* expected result code 0: success */
  5719. );
  5720. ExpectIntEQ(outl,sizeof(plain2) -1);
  5721. ExpectIntEQ(
  5722. EVP_DecodeFinal(
  5723. ctx,
  5724. decOutBuff + outl,
  5725. &outl),
  5726. 1 /* expected result code 1: success */
  5727. );
  5728. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5729. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5730. sizeof(plain2) -1 ),0);
  5731. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5732. sizeof(plain2)-1);
  5733. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5734. sizeof(plain2) -1 ),0);
  5735. }
  5736. /* decode correct base64 string which does not have '\n' in its last*/
  5737. {
  5738. static const unsigned char enc3[] =
  5739. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5740. static const unsigned char plain3[] =
  5741. {"This is a base64 decoding test."}; /* 31 chars */
  5742. EVP_EncodeInit(ctx);
  5743. ExpectIntEQ(
  5744. EVP_DecodeUpdate(
  5745. ctx,
  5746. decOutBuff,
  5747. &outl,
  5748. enc3,
  5749. sizeof(enc3)-1),
  5750. 0 /* expected result code 0: success */
  5751. );
  5752. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5753. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5754. sizeof(plain3) -1 ),0);
  5755. ExpectIntEQ(
  5756. EVP_DecodeFinal(
  5757. ctx,
  5758. decOutBuff + outl,
  5759. &outl),
  5760. 1 /* expected result code 1: success */
  5761. );
  5762. ExpectIntEQ(outl,0 );
  5763. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5764. sizeof(plain3)-1);
  5765. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5766. sizeof(plain3) -1 ),0);
  5767. }
  5768. /* decode string which has a padding char ('=') in the illegal position*/
  5769. {
  5770. static const unsigned char enc4[] =
  5771. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5772. EVP_EncodeInit(ctx);
  5773. ExpectIntEQ(
  5774. EVP_DecodeUpdate(
  5775. ctx,
  5776. decOutBuff,
  5777. &outl,
  5778. enc4,
  5779. sizeof(enc4)-1),
  5780. -1 /* expected result code -1: error */
  5781. );
  5782. ExpectIntEQ(outl,0);
  5783. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  5784. }
  5785. /* small data decode test */
  5786. {
  5787. static const unsigned char enc00[] = {"VG"};
  5788. static const unsigned char enc01[] = {"g=\n"};
  5789. static const unsigned char plain4[] = {"Th"};
  5790. EVP_EncodeInit(ctx);
  5791. ExpectIntEQ(
  5792. EVP_DecodeUpdate(
  5793. ctx,
  5794. decOutBuff,
  5795. &outl,
  5796. enc00,
  5797. sizeof(enc00)-1),
  5798. 1 /* expected result code 1: success */
  5799. );
  5800. ExpectIntEQ(outl,0);
  5801. ExpectIntEQ(
  5802. EVP_DecodeUpdate(
  5803. ctx,
  5804. decOutBuff + outl,
  5805. &outl,
  5806. enc01,
  5807. sizeof(enc01)-1),
  5808. 0 /* expected result code 0: success */
  5809. );
  5810. ExpectIntEQ(outl,sizeof(plain4)-1);
  5811. /* test with illegal parameters */
  5812. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  5813. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  5814. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  5815. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  5816. if (EXPECT_SUCCESS()) {
  5817. EVP_DecodeFinal(
  5818. ctx,
  5819. decOutBuff + outl,
  5820. &outl);
  5821. }
  5822. ExpectIntEQ( outl, 0);
  5823. ExpectIntEQ(
  5824. XSTRNCMP(
  5825. (const char*)decOutBuff,
  5826. (const char*)plain4,sizeof(plain4)-1 ),
  5827. 0);
  5828. }
  5829. EVP_ENCODE_CTX_free(ctx);
  5830. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5831. return EXPECT_RESULT();
  5832. }
  5833. static int test_wolfSSL_EVP_DecodeFinal(void)
  5834. {
  5835. int res = TEST_SKIPPED;
  5836. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5837. /* tests for wolfSSL_EVP_DecodeFinal are included in
  5838. * test_wolfSSL_EVP_DecodeUpdate
  5839. */
  5840. res = TEST_SUCCESS;
  5841. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5842. return res;
  5843. }
  5844. /* Test function for wolfSSL_EVP_get_cipherbynid.
  5845. */
  5846. #ifdef OPENSSL_EXTRA
  5847. static int test_wolfSSL_EVP_get_cipherbynid(void)
  5848. {
  5849. EXPECT_DECLS;
  5850. #ifndef NO_AES
  5851. const WOLFSSL_EVP_CIPHER* c;
  5852. c = wolfSSL_EVP_get_cipherbynid(419);
  5853. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5854. defined(WOLFSSL_AES_128)
  5855. ExpectNotNull(c);
  5856. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  5857. #else
  5858. ExpectNull(c);
  5859. #endif
  5860. c = wolfSSL_EVP_get_cipherbynid(423);
  5861. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5862. defined(WOLFSSL_AES_192)
  5863. ExpectNotNull(c);
  5864. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  5865. #else
  5866. ExpectNull(c);
  5867. #endif
  5868. c = wolfSSL_EVP_get_cipherbynid(427);
  5869. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  5870. defined(WOLFSSL_AES_256)
  5871. ExpectNotNull(c);
  5872. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  5873. #else
  5874. ExpectNull(c);
  5875. #endif
  5876. c = wolfSSL_EVP_get_cipherbynid(904);
  5877. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  5878. ExpectNotNull(c);
  5879. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  5880. #else
  5881. ExpectNull(c);
  5882. #endif
  5883. c = wolfSSL_EVP_get_cipherbynid(905);
  5884. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  5885. ExpectNotNull(c);
  5886. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  5887. #else
  5888. ExpectNull(c);
  5889. #endif
  5890. c = wolfSSL_EVP_get_cipherbynid(906);
  5891. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  5892. ExpectNotNull(c);
  5893. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  5894. #else
  5895. ExpectNull(c);
  5896. #endif
  5897. c = wolfSSL_EVP_get_cipherbynid(418);
  5898. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  5899. ExpectNotNull(c);
  5900. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  5901. #else
  5902. ExpectNull(c);
  5903. #endif
  5904. c = wolfSSL_EVP_get_cipherbynid(422);
  5905. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  5906. ExpectNotNull(c);
  5907. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  5908. #else
  5909. ExpectNull(c);
  5910. #endif
  5911. c = wolfSSL_EVP_get_cipherbynid(426);
  5912. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  5913. ExpectNotNull(c);
  5914. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  5915. #else
  5916. ExpectNull(c);
  5917. #endif
  5918. #endif /* !NO_AES */
  5919. #ifndef NO_DES3
  5920. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  5921. #ifdef WOLFSSL_DES_ECB
  5922. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  5923. #endif
  5924. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  5925. #ifdef WOLFSSL_DES_ECB
  5926. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  5927. #endif
  5928. #endif /* !NO_DES3 */
  5929. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5930. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  5931. #endif
  5932. /* test for nid is out of range */
  5933. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  5934. return EXPECT_RESULT();
  5935. }
  5936. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  5937. {
  5938. EXPECT_DECLS;
  5939. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  5940. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  5941. const EVP_CIPHER *init = EVP_aes_128_cbc();
  5942. const EVP_CIPHER *test;
  5943. byte key[AES_BLOCK_SIZE] = {0};
  5944. byte iv[AES_BLOCK_SIZE] = {0};
  5945. ExpectNotNull(ctx);
  5946. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  5947. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  5948. test = EVP_CIPHER_CTX_cipher(ctx);
  5949. ExpectTrue(init == test);
  5950. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  5951. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  5952. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  5953. EVP_CIPHER_CTX_free(ctx);
  5954. /* test EVP_CIPHER_CTX_cleanup with NULL */
  5955. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  5956. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  5957. return EXPECT_RESULT();
  5958. }
  5959. #endif /* OPENSSL_EXTRA */
  5960. /*----------------------------------------------------------------------------*
  5961. | IO
  5962. *----------------------------------------------------------------------------*/
  5963. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  5964. defined(HAVE_IO_TESTS_DEPENDENCIES)
  5965. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  5966. #ifdef WC_SHA512_DIGEST_SIZE
  5967. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  5968. #else
  5969. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  5970. #endif
  5971. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  5972. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  5973. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  5974. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  5975. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  5976. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  5977. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  5978. defined(HAVE_AES_CBC)
  5979. typedef struct openssl_key_ctx {
  5980. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  5981. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  5982. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  5983. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  5984. } openssl_key_ctx;
  5985. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  5986. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  5987. static WC_INLINE int OpenSSLTicketInit(void)
  5988. {
  5989. int ret = wc_InitRng(&myOpenSSLKey_rng);
  5990. if (ret != 0) return ret;
  5991. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  5992. sizeof(myOpenSSLKey_ctx.name));
  5993. if (ret != 0) return ret;
  5994. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  5995. sizeof(myOpenSSLKey_ctx.key));
  5996. if (ret != 0) return ret;
  5997. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  5998. sizeof(myOpenSSLKey_ctx.hmacKey));
  5999. if (ret != 0) return ret;
  6000. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6001. sizeof(myOpenSSLKey_ctx.iv));
  6002. if (ret != 0) return ret;
  6003. return 0;
  6004. }
  6005. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6006. byte name[WOLFSSL_TICKET_NAME_SZ],
  6007. byte iv[WOLFSSL_TICKET_IV_SZ],
  6008. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6009. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6010. (void)ssl;
  6011. if (enc) {
  6012. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6013. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6014. }
  6015. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6016. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6017. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6018. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6019. return 0;
  6020. }
  6021. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6022. if (enc)
  6023. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6024. else
  6025. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6026. return 1;
  6027. }
  6028. static WC_INLINE void OpenSSLTicketCleanup(void)
  6029. {
  6030. wc_FreeRng(&myOpenSSLKey_rng);
  6031. }
  6032. #endif
  6033. #endif
  6034. /* helper functions */
  6035. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6036. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6037. void *ctx)
  6038. {
  6039. struct test_ssl_memio_ctx *test_ctx;
  6040. byte *buf;
  6041. int *len;
  6042. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6043. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6044. buf = test_ctx->c_buff;
  6045. len = &test_ctx->c_len;
  6046. }
  6047. else {
  6048. buf = test_ctx->s_buff;
  6049. len = &test_ctx->s_len;
  6050. }
  6051. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6052. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6053. XMEMCPY(buf + *len, data, sz);
  6054. *len += sz;
  6055. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6056. {
  6057. /* This can be imported into Wireshark by transforming the file with
  6058. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6059. * And then loading test_output.dump.hex into Wireshark using the
  6060. * "Import from Hex Dump..." option ion and selecting the TCP
  6061. * encapsulation option. */
  6062. char dump_file_name[64];
  6063. WOLFSSL_BIO *dump_file;
  6064. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6065. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6066. if (dump_file != NULL) {
  6067. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6068. wolfSSL_BIO_free(dump_file);
  6069. }
  6070. }
  6071. #endif
  6072. return sz;
  6073. }
  6074. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6075. void *ctx)
  6076. {
  6077. struct test_ssl_memio_ctx *test_ctx;
  6078. int read_sz;
  6079. byte *buf;
  6080. int *len;
  6081. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6082. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6083. buf = test_ctx->s_buff;
  6084. len = &test_ctx->s_len;
  6085. }
  6086. else {
  6087. buf = test_ctx->c_buff;
  6088. len = &test_ctx->c_len;
  6089. }
  6090. if (*len == 0)
  6091. return WOLFSSL_CBIO_ERR_WANT_READ;
  6092. read_sz = sz < *len ? sz : *len;
  6093. XMEMCPY(data, buf, read_sz);
  6094. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6095. *len -= read_sz;
  6096. return read_sz;
  6097. }
  6098. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6099. {
  6100. EXPECT_DECLS;
  6101. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6102. int c_sharedCtx = 0;
  6103. int s_sharedCtx = 0;
  6104. #endif
  6105. const char* clientCertFile = cliCertFile;
  6106. const char* clientKeyFile = cliKeyFile;
  6107. const char* serverCertFile = svrCertFile;
  6108. const char* serverKeyFile = svrKeyFile;
  6109. /********************************
  6110. * Create WOLFSSL_CTX for client.
  6111. ********************************/
  6112. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6113. if (ctx->c_ctx != NULL) {
  6114. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6115. }
  6116. else
  6117. #endif
  6118. {
  6119. WOLFSSL_METHOD* method = NULL;
  6120. if (ctx->c_cb.method != NULL) {
  6121. method = ctx->c_cb.method();
  6122. }
  6123. else {
  6124. method = wolfSSLv23_client_method();
  6125. }
  6126. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6127. }
  6128. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6129. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6130. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6131. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6132. #endif
  6133. if (ctx->c_cb.caPemFile != NULL)
  6134. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6135. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6136. else
  6137. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6138. caCertFile, 0), WOLFSSL_SUCCESS);
  6139. if (ctx->c_cb.certPemFile != NULL) {
  6140. clientCertFile = ctx->c_cb.certPemFile;
  6141. }
  6142. if (ctx->c_cb.keyPemFile != NULL) {
  6143. clientKeyFile = ctx->c_cb.keyPemFile;
  6144. }
  6145. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6146. if (!c_sharedCtx)
  6147. #endif
  6148. {
  6149. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6150. clientCertFile), WOLFSSL_SUCCESS);
  6151. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6152. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6153. }
  6154. #ifdef HAVE_CRL
  6155. if (ctx->c_cb.crlPemFile != NULL) {
  6156. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6157. WOLFSSL_SUCCESS);
  6158. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6159. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6160. }
  6161. #endif
  6162. if (ctx->c_ciphers != NULL) {
  6163. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6164. WOLFSSL_SUCCESS);
  6165. }
  6166. if (ctx->c_cb.ctx_ready != NULL) {
  6167. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6168. }
  6169. /********************************
  6170. * Create WOLFSSL_CTX for server.
  6171. ********************************/
  6172. if (ctx->s_ctx != NULL) {
  6173. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6174. s_sharedCtx = 1;
  6175. #endif
  6176. ctx->s_cb.isSharedCtx = 1;
  6177. }
  6178. else
  6179. {
  6180. WOLFSSL_METHOD* method = NULL;
  6181. if (ctx->s_cb.method != NULL) {
  6182. method = ctx->s_cb.method();
  6183. }
  6184. else {
  6185. method = wolfSSLv23_server_method();
  6186. }
  6187. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6188. ctx->s_cb.isSharedCtx = 0;
  6189. }
  6190. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6191. #if defined(HAVE_SESSION_TICKET) && \
  6192. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6193. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6194. OpenSSLTicketInit();
  6195. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6196. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6197. TicketInit();
  6198. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6199. #endif
  6200. #endif
  6201. }
  6202. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6203. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6204. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6205. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6206. if (ctx->s_cb.caPemFile != NULL)
  6207. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6208. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6209. else
  6210. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6211. cliCertFile, 0), WOLFSSL_SUCCESS);
  6212. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6213. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6214. #endif
  6215. if (ctx->s_cb.certPemFile != NULL) {
  6216. serverCertFile = ctx->s_cb.certPemFile;
  6217. }
  6218. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6219. if (!s_sharedCtx)
  6220. #endif
  6221. {
  6222. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6223. serverCertFile), WOLFSSL_SUCCESS);
  6224. }
  6225. if (ctx->s_cb.keyPemFile != NULL) {
  6226. serverKeyFile = ctx->s_cb.keyPemFile;
  6227. }
  6228. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6229. if (!s_sharedCtx)
  6230. #endif
  6231. {
  6232. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6233. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6234. }
  6235. if (ctx->s_ciphers != NULL) {
  6236. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6237. WOLFSSL_SUCCESS);
  6238. }
  6239. if (ctx->s_cb.ctx_ready != NULL) {
  6240. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6241. }
  6242. /****************************
  6243. * Create WOLFSSL for client.
  6244. ****************************/
  6245. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6246. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6247. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6248. if (0
  6249. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6250. || c_sharedCtx
  6251. #endif
  6252. )
  6253. {
  6254. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6255. clientCertFile), WOLFSSL_SUCCESS);
  6256. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6257. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6258. }
  6259. if (ctx->c_cb.ssl_ready != NULL) {
  6260. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6261. }
  6262. /****************************
  6263. * Create WOLFSSL for server.
  6264. ****************************/
  6265. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6266. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6267. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6268. if (0
  6269. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6270. || s_sharedCtx
  6271. #endif
  6272. )
  6273. {
  6274. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6275. serverCertFile), WOLFSSL_SUCCESS);
  6276. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6277. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6278. }
  6279. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6280. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6281. #elif !defined(NO_DH)
  6282. /* will repick suites with DHE, higher priority than PSK */
  6283. SetDH(ctx->s_ssl);
  6284. #endif
  6285. if (ctx->s_cb.ssl_ready != NULL) {
  6286. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6287. }
  6288. return EXPECT_RESULT();
  6289. }
  6290. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6291. int* rounds)
  6292. {
  6293. int handshake_complete = 0;
  6294. int hs_c = 0;
  6295. int hs_s = 0;
  6296. int failing_s = 0;
  6297. int failing_c = 0;
  6298. int ret;
  6299. int err;
  6300. if (rounds != NULL) {
  6301. *rounds = 0;
  6302. }
  6303. while ((!handshake_complete) && (max_rounds > 0)) {
  6304. if (!hs_c) {
  6305. wolfSSL_SetLoggingPrefix("client");
  6306. ret = wolfSSL_connect(ctx->c_ssl);
  6307. wolfSSL_SetLoggingPrefix(NULL);
  6308. if (ret == WOLFSSL_SUCCESS) {
  6309. hs_c = 1;
  6310. }
  6311. else {
  6312. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6313. if (err != WOLFSSL_ERROR_WANT_READ &&
  6314. err != WOLFSSL_ERROR_WANT_WRITE) {
  6315. char buff[WOLFSSL_MAX_ERROR_SZ];
  6316. fprintf(stderr, "error = %d, %s\n", err,
  6317. wolfSSL_ERR_error_string(err, buff));
  6318. failing_c = 1;
  6319. hs_c = 1;
  6320. if (failing_c && failing_s) {
  6321. break;
  6322. }
  6323. }
  6324. }
  6325. }
  6326. if (!hs_s) {
  6327. wolfSSL_SetLoggingPrefix("server");
  6328. ret = wolfSSL_accept(ctx->s_ssl);
  6329. wolfSSL_SetLoggingPrefix(NULL);
  6330. if (ret == WOLFSSL_SUCCESS) {
  6331. hs_s = 1;
  6332. }
  6333. else {
  6334. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6335. if (err != WOLFSSL_ERROR_WANT_READ &&
  6336. err != WOLFSSL_ERROR_WANT_WRITE) {
  6337. char buff[WOLFSSL_MAX_ERROR_SZ];
  6338. fprintf(stderr, "error = %d, %s\n", err,
  6339. wolfSSL_ERR_error_string(err, buff));
  6340. failing_s = 1;
  6341. hs_s = 1;
  6342. if (failing_c && failing_s) {
  6343. break;
  6344. }
  6345. }
  6346. }
  6347. }
  6348. handshake_complete = hs_c && hs_s;
  6349. max_rounds--;
  6350. if (rounds != NULL) {
  6351. *rounds += 1;
  6352. }
  6353. }
  6354. if (!handshake_complete || failing_c || failing_s) {
  6355. return TEST_FAIL;
  6356. }
  6357. return TEST_SUCCESS;
  6358. }
  6359. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6360. {
  6361. EXPECT_DECLS;
  6362. char input[1024];
  6363. int idx = 0;
  6364. const char* msg_c = "hello wolfssl!";
  6365. int msglen_c = (int)XSTRLEN(msg_c);
  6366. const char* msg_s = "I hear you fa shizzle!";
  6367. int msglen_s = (int)XSTRLEN(msg_s);
  6368. if (ctx->c_msg != NULL) {
  6369. msg_c = ctx->c_msg;
  6370. msglen_c = ctx->c_msglen;
  6371. }
  6372. if (ctx->s_msg != NULL) {
  6373. msg_s = ctx->s_msg;
  6374. msglen_s = ctx->s_msglen;
  6375. }
  6376. wolfSSL_SetLoggingPrefix("client");
  6377. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6378. wolfSSL_SetLoggingPrefix("server");
  6379. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6380. if (idx >= 0) {
  6381. input[idx] = '\0';
  6382. }
  6383. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6384. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6385. ctx->s_cb.return_code = EXPECT_RESULT();
  6386. wolfSSL_SetLoggingPrefix("client");
  6387. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6388. wolfSSL_SetLoggingPrefix(NULL);
  6389. if (idx >= 0) {
  6390. input[idx] = '\0';
  6391. }
  6392. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6393. ctx->c_cb.return_code = EXPECT_RESULT();
  6394. if (ctx->c_cb.on_result != NULL) {
  6395. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6396. }
  6397. if (ctx->s_cb.on_result != NULL) {
  6398. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6399. }
  6400. return EXPECT_RESULT();
  6401. }
  6402. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6403. {
  6404. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6405. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6406. if (ctx->c_cb.on_cleanup != NULL) {
  6407. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6408. }
  6409. if (ctx->s_cb.on_cleanup != NULL) {
  6410. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6411. }
  6412. wolfSSL_shutdown(ctx->s_ssl);
  6413. wolfSSL_shutdown(ctx->c_ssl);
  6414. wolfSSL_free(ctx->s_ssl);
  6415. wolfSSL_free(ctx->c_ssl);
  6416. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6417. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6418. }
  6419. if (!ctx->c_cb.isSharedCtx) {
  6420. wolfSSL_CTX_free(ctx->c_ctx);
  6421. ctx->c_ctx = NULL;
  6422. }
  6423. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6424. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6425. }
  6426. if (!ctx->s_cb.isSharedCtx) {
  6427. wolfSSL_CTX_free(ctx->s_ctx);
  6428. ctx->s_ctx = NULL;
  6429. }
  6430. if (!ctx->s_cb.ticNoInit) {
  6431. #if defined(HAVE_SESSION_TICKET) && \
  6432. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6433. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6434. OpenSSLTicketCleanup();
  6435. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6436. TicketCleanup();
  6437. #endif
  6438. #endif
  6439. }
  6440. }
  6441. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6442. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6443. {
  6444. EXPECT_DECLS;
  6445. struct test_ssl_memio_ctx test_ctx;
  6446. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6447. size_t msg_len;
  6448. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6449. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6450. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6451. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6452. test_ctx.c_ctx = client_cb->ctx;
  6453. test_ctx.s_ctx = server_cb->ctx;
  6454. test_ctx.c_cb.return_code = TEST_FAIL;
  6455. test_ctx.s_cb.return_code = TEST_FAIL;
  6456. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6457. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6458. if (client_on_handshake != NULL) {
  6459. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6460. TEST_SUCCESS);
  6461. }
  6462. if (client_cb->on_handshake != NULL) {
  6463. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6464. TEST_SUCCESS);
  6465. }
  6466. if (server_cb->on_handshake != NULL) {
  6467. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6468. TEST_SUCCESS);
  6469. }
  6470. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6471. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6472. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6473. MD_MAX_SIZE);
  6474. ExpectIntGE(msg_len, 0);
  6475. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6476. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6477. MD_MAX_SIZE);
  6478. ExpectIntGE(msg_len, 0);
  6479. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6480. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6481. test_ssl_memio_cleanup(&test_ctx);
  6482. client_cb->return_code = test_ctx.c_cb.return_code;
  6483. client_cb->last_err = test_ctx.c_cb.last_err;
  6484. server_cb->return_code = test_ctx.s_cb.return_code;
  6485. server_cb->last_err = test_ctx.s_cb.last_err;
  6486. return EXPECT_RESULT();
  6487. }
  6488. #endif
  6489. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6490. #ifdef WOLFSSL_SESSION_EXPORT
  6491. #ifdef WOLFSSL_DTLS
  6492. /* set up function for sending session information */
  6493. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6494. {
  6495. WOLFSSL_CTX* ctx = NULL;
  6496. WOLFSSL* ssl = NULL;
  6497. AssertNotNull(inSsl);
  6498. AssertNotNull(buf);
  6499. AssertIntNE(0, sz);
  6500. /* Set ctx to DTLS 1.2 */
  6501. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6502. AssertNotNull(ctx);
  6503. ssl = wolfSSL_new(ctx);
  6504. AssertNotNull(ssl);
  6505. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6506. wolfSSL_free(ssl);
  6507. wolfSSL_CTX_free(ctx);
  6508. (void)userCtx;
  6509. return 0;
  6510. }
  6511. #endif
  6512. /* returns negative value on fail and positive (including 0) on success */
  6513. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6514. {
  6515. int ret, err, loop_count, count, timeout = 10;
  6516. char msg[] = "I hear you fa shizzle!";
  6517. char input[1024];
  6518. loop_count = ((func_args*)args)->argc;
  6519. #ifdef WOLFSSL_ASYNC_CRYPT
  6520. err = 0; /* Reset error */
  6521. #endif
  6522. do {
  6523. #ifdef WOLFSSL_ASYNC_CRYPT
  6524. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6525. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6526. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6527. }
  6528. #endif
  6529. ret = wolfSSL_accept(ssl);
  6530. err = wolfSSL_get_error(ssl, 0);
  6531. if (err == WOLFSSL_ERROR_WANT_READ ||
  6532. err == WOLFSSL_ERROR_WANT_WRITE) {
  6533. int select_ret;
  6534. err = WC_PENDING_E;
  6535. select_ret = tcp_select(*sockfd, timeout);
  6536. if (select_ret == TEST_TIMEOUT) {
  6537. return WOLFSSL_FATAL_ERROR;
  6538. }
  6539. }
  6540. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6541. if (ret != WOLFSSL_SUCCESS) {
  6542. char buff[WOLFSSL_MAX_ERROR_SZ];
  6543. fprintf(stderr, "error = %d, %s\n", err,
  6544. wolfSSL_ERR_error_string(err, buff));
  6545. return ret;
  6546. }
  6547. for (count = 0; count < loop_count; count++) {
  6548. int select_ret;
  6549. select_ret = tcp_select(*sockfd, timeout);
  6550. if (select_ret == TEST_TIMEOUT) {
  6551. ret = WOLFSSL_FATAL_ERROR;
  6552. break;
  6553. }
  6554. do {
  6555. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6556. if (ret > 0) {
  6557. input[ret] = '\0';
  6558. fprintf(stderr, "Client message: %s\n", input);
  6559. }
  6560. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6561. do {
  6562. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6563. return WOLFSSL_FATAL_ERROR;
  6564. }
  6565. err = wolfSSL_get_error(ssl, ret);
  6566. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6567. }
  6568. return ret;
  6569. }
  6570. #endif /* WOLFSSL_SESSION_EXPORT */
  6571. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6572. {
  6573. SOCKET_T sockfd = 0;
  6574. SOCKET_T clientfd = 0;
  6575. word16 port;
  6576. callback_functions* cbf;
  6577. WOLFSSL_CTX* ctx = NULL;
  6578. WOLFSSL* ssl = NULL;
  6579. func_args* opts = (func_args*)args;
  6580. char msg[] = "I hear you fa shizzle!";
  6581. char input[1024];
  6582. int idx;
  6583. int ret, err = 0;
  6584. int sharedCtx = 0;
  6585. int doUdp = 0;
  6586. SOCKADDR_IN_T cliAddr;
  6587. socklen_t cliLen;
  6588. const char* certFile = svrCertFile;
  6589. const char* keyFile = svrKeyFile;
  6590. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6591. size_t msg_len = 0;
  6592. #endif
  6593. wolfSSL_SetLoggingPrefix("server");
  6594. #ifdef WOLFSSL_TIRTOS
  6595. fdOpenSession(Task_self());
  6596. #endif
  6597. opts->return_code = TEST_FAIL;
  6598. cbf = opts->callbacks;
  6599. if (cbf != NULL && cbf->ctx) {
  6600. ctx = cbf->ctx;
  6601. sharedCtx = 1;
  6602. }
  6603. else
  6604. {
  6605. WOLFSSL_METHOD* method = NULL;
  6606. if (cbf != NULL && cbf->method != NULL) {
  6607. method = cbf->method();
  6608. }
  6609. else {
  6610. method = wolfSSLv23_server_method();
  6611. }
  6612. ctx = wolfSSL_CTX_new(method);
  6613. }
  6614. if (ctx == NULL) {
  6615. /* Release the wait for TCP ready. */
  6616. signal_ready(opts->signal);
  6617. goto done;
  6618. }
  6619. if (cbf == NULL || !cbf->ticNoInit) {
  6620. #if defined(HAVE_SESSION_TICKET) && \
  6621. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6622. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6623. OpenSSLTicketInit();
  6624. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6625. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6626. TicketInit();
  6627. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6628. #endif
  6629. #endif
  6630. }
  6631. #if defined(USE_WINDOWS_API)
  6632. port = opts->signal->port;
  6633. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6634. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6635. /* Let tcp_listen assign port */
  6636. port = 0;
  6637. #else
  6638. /* Use default port */
  6639. port = wolfSSLPort;
  6640. #endif
  6641. if (cbf != NULL)
  6642. doUdp = cbf->doUdp;
  6643. /* do it here to detect failure */
  6644. tcp_accept(
  6645. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6646. if (doUdp) {
  6647. cliLen = sizeof(cliAddr);
  6648. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6649. (struct sockaddr*)&cliAddr, &cliLen);
  6650. AssertIntGT(idx, 0);
  6651. }
  6652. else {
  6653. CloseSocket(sockfd);
  6654. }
  6655. wolfSSL_CTX_set_verify(ctx,
  6656. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6657. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6658. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6659. #endif
  6660. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6661. != WOLFSSL_SUCCESS) {
  6662. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6663. goto done;
  6664. }
  6665. if (cbf != NULL && cbf->certPemFile != NULL)
  6666. certFile = cbf->certPemFile;
  6667. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6668. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6669. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6670. #else
  6671. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6672. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6673. #endif
  6674. /*err_sys("can't load server cert chain file, "
  6675. "Please run from wolfSSL home dir");*/
  6676. goto done;
  6677. }
  6678. if (cbf != NULL && cbf->keyPemFile != NULL)
  6679. keyFile = cbf->keyPemFile;
  6680. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6681. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6682. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6683. #else
  6684. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6685. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6686. #endif
  6687. /*err_sys("can't load server key file, "
  6688. "Please run from wolfSSL home dir");*/
  6689. goto done;
  6690. }
  6691. #ifdef HAVE_CRL
  6692. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6693. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6694. goto done;
  6695. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6696. != WOLFSSL_SUCCESS)
  6697. goto done;
  6698. }
  6699. #endif
  6700. /* call ctx setup callback */
  6701. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6702. cbf->ctx_ready(ctx);
  6703. }
  6704. ssl = wolfSSL_new(ctx);
  6705. if (ssl == NULL) {
  6706. goto done;
  6707. }
  6708. if (doUdp) {
  6709. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6710. if (err != WOLFSSL_SUCCESS)
  6711. goto done;
  6712. }
  6713. #ifdef WOLFSSL_SESSION_EXPORT
  6714. /* only add in more complex nonblocking case with session export tests */
  6715. if (args && opts->argc > 0) {
  6716. /* set as nonblock and time out for waiting on read/write */
  6717. tcp_set_nonblocking(&clientfd);
  6718. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6719. }
  6720. #endif
  6721. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6722. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6723. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6724. #else
  6725. if (wolfSSL_use_certificate_file(ssl, certFile,
  6726. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6727. #endif
  6728. /*err_sys("can't load server cert chain file, "
  6729. "Please run from wolfSSL home dir");*/
  6730. goto done;
  6731. }
  6732. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6733. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6734. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6735. #else
  6736. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6737. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6738. #endif
  6739. /*err_sys("can't load server key file, "
  6740. "Please run from wolfSSL home dir");*/
  6741. goto done;
  6742. }
  6743. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6744. /*err_sys("SSL_set_fd failed");*/
  6745. goto done;
  6746. }
  6747. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6748. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6749. #elif !defined(NO_DH)
  6750. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6751. #endif
  6752. /* call ssl setup callback */
  6753. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6754. cbf->ssl_ready(ssl);
  6755. }
  6756. #ifdef WOLFSSL_SESSION_EXPORT
  6757. /* only add in more complex nonblocking case with session export tests */
  6758. if (opts->argc > 0) {
  6759. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6760. if (ret >= 0) {
  6761. opts->return_code = TEST_SUCCESS;
  6762. }
  6763. #ifdef WOLFSSL_TIRTOS
  6764. Task_yield();
  6765. #endif
  6766. goto done;
  6767. }
  6768. #endif
  6769. #ifdef WOLFSSL_ASYNC_CRYPT
  6770. err = 0; /* Reset error */
  6771. #endif
  6772. do {
  6773. #ifdef WOLFSSL_ASYNC_CRYPT
  6774. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6775. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6776. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6777. }
  6778. #endif
  6779. ret = wolfSSL_negotiate(ssl);
  6780. err = wolfSSL_get_error(ssl, 0);
  6781. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6782. if (ret != WOLFSSL_SUCCESS) {
  6783. char buff[WOLFSSL_MAX_ERROR_SZ];
  6784. fprintf(stderr, "error = %d, %s\n", err,
  6785. wolfSSL_ERR_error_string(err, buff));
  6786. /*err_sys("SSL_accept failed");*/
  6787. goto done;
  6788. }
  6789. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6790. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6791. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  6792. AssertIntGE(msg_len, 0);
  6793. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6794. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  6795. AssertIntGE(msg_len, 0);
  6796. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6797. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  6798. if (idx > 0) {
  6799. input[idx] = '\0';
  6800. fprintf(stderr, "Client message: %s\n", input);
  6801. }
  6802. else if (idx < 0) {
  6803. goto done;
  6804. }
  6805. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  6806. /*err_sys("SSL_write failed");*/
  6807. goto done;
  6808. }
  6809. if (cbf != NULL && cbf->on_result != NULL)
  6810. cbf->on_result(ssl);
  6811. #ifdef WOLFSSL_TIRTOS
  6812. Task_yield();
  6813. #endif
  6814. opts->return_code = TEST_SUCCESS;
  6815. done:
  6816. if (cbf != NULL)
  6817. cbf->last_err = err;
  6818. if (cbf != NULL && cbf->on_cleanup != NULL)
  6819. cbf->on_cleanup(ssl);
  6820. wolfSSL_shutdown(ssl);
  6821. wolfSSL_free(ssl);
  6822. if (!sharedCtx)
  6823. wolfSSL_CTX_free(ctx);
  6824. CloseSocket(clientfd);
  6825. #ifdef WOLFSSL_TIRTOS
  6826. fdCloseSession(Task_self());
  6827. #endif
  6828. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  6829. && defined(HAVE_THREAD_LS)
  6830. wc_ecc_fp_free(); /* free per thread cache */
  6831. #endif
  6832. if (cbf == NULL || !cbf->ticNoInit) {
  6833. #if defined(HAVE_SESSION_TICKET) && \
  6834. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6835. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6836. OpenSSLTicketCleanup();
  6837. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6838. TicketCleanup();
  6839. #endif
  6840. #endif
  6841. }
  6842. wolfSSL_SetLoggingPrefix(NULL);
  6843. WOLFSSL_RETURN_FROM_THREAD(0);
  6844. }
  6845. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  6846. !defined(WOLFSSL_NO_TLS12)
  6847. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  6848. {
  6849. SOCKET_T sockfd;
  6850. SOCKET_T clientfd = -1;
  6851. word16 port;
  6852. callback_functions* cbf;
  6853. WOLFSSL_CTX* ctx = 0;
  6854. WOLFSSL* ssl = 0;
  6855. char msg[] = "I hear you fa shizzle!";
  6856. char input[1024];
  6857. int idx;
  6858. int ret, err = 0;
  6859. int sharedCtx = 0;
  6860. func_args* opts = (func_args*)args;
  6861. int loop_count = opts->argc;
  6862. int count = 0;
  6863. #ifdef WOLFSSL_TIRTOS
  6864. fdOpenSession(Task_self());
  6865. #endif
  6866. opts->return_code = TEST_FAIL;
  6867. cbf = opts->callbacks;
  6868. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6869. if (cbf != NULL && cbf->ctx) {
  6870. ctx = cbf->ctx;
  6871. sharedCtx = 1;
  6872. }
  6873. else
  6874. #endif
  6875. {
  6876. WOLFSSL_METHOD* method = NULL;
  6877. if (cbf != NULL && cbf->method != NULL) {
  6878. method = cbf->method();
  6879. }
  6880. else {
  6881. method = wolfSSLv23_server_method();
  6882. }
  6883. ctx = wolfSSL_CTX_new(method);
  6884. }
  6885. #if defined(USE_WINDOWS_API)
  6886. port = opts->signal->port;
  6887. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6888. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6889. /* Let tcp_listen assign port */
  6890. port = 0;
  6891. #else
  6892. /* Use default port */
  6893. port = wolfSSLPort;
  6894. #endif
  6895. wolfSSL_CTX_set_verify(ctx,
  6896. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6897. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6898. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6899. #endif
  6900. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6901. != WOLFSSL_SUCCESS) {
  6902. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6903. /* Release the wait for TCP ready. */
  6904. signal_ready(opts->signal);
  6905. goto done;
  6906. }
  6907. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  6908. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6909. /*err_sys("can't load server cert chain file, "
  6910. "Please run from wolfSSL home dir");*/
  6911. /* Release the wait for TCP ready. */
  6912. signal_ready(opts->signal);
  6913. goto done;
  6914. }
  6915. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  6916. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6917. /*err_sys("can't load server key file, "
  6918. "Please run from wolfSSL home dir");*/
  6919. /* Release the wait for TCP ready. */
  6920. signal_ready(opts->signal);
  6921. goto done;
  6922. }
  6923. /* call ctx setup callback */
  6924. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6925. cbf->ctx_ready(ctx);
  6926. }
  6927. while (count != loop_count) {
  6928. ssl = wolfSSL_new(ctx);
  6929. if (ssl == NULL) {
  6930. signal_ready(opts->signal);
  6931. goto done;
  6932. }
  6933. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  6934. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6935. /*err_sys("can't load server cert chain file, "
  6936. "Please run from wolfSSL home dir");*/
  6937. /* Release the wait for TCP ready. */
  6938. signal_ready(opts->signal);
  6939. goto done;
  6940. }
  6941. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  6942. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6943. /*err_sys("can't load server key file, "
  6944. "Please run from wolfSSL home dir");*/
  6945. /* Release the wait for TCP ready. */
  6946. signal_ready(opts->signal);
  6947. goto done;
  6948. }
  6949. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6950. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6951. #elif !defined(NO_DH)
  6952. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6953. #endif
  6954. /* call ssl setup callback */
  6955. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6956. cbf->ssl_ready(ssl);
  6957. }
  6958. /* do it here to detect failure */
  6959. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  6960. 0);
  6961. CloseSocket(sockfd);
  6962. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6963. /*err_sys("SSL_set_fd failed");*/
  6964. goto done;
  6965. }
  6966. #ifdef WOLFSSL_ASYNC_CRYPT
  6967. err = 0; /* Reset error */
  6968. #endif
  6969. do {
  6970. #ifdef WOLFSSL_ASYNC_CRYPT
  6971. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6972. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6973. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6974. }
  6975. #endif
  6976. ret = wolfSSL_accept(ssl);
  6977. err = wolfSSL_get_error(ssl, 0);
  6978. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6979. if (ret != WOLFSSL_SUCCESS) {
  6980. char buff[WOLFSSL_MAX_ERROR_SZ];
  6981. fprintf(stderr, "error = %d, %s\n", err,
  6982. wolfSSL_ERR_error_string(err, buff));
  6983. /*err_sys("SSL_accept failed");*/
  6984. goto done;
  6985. }
  6986. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  6987. if (idx > 0) {
  6988. input[idx] = '\0';
  6989. fprintf(stderr, "Client message: %s\n", input);
  6990. }
  6991. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  6992. /*err_sys("SSL_write failed");*/
  6993. goto done;
  6994. }
  6995. /* free ssl for this connection */
  6996. wolfSSL_shutdown(ssl);
  6997. wolfSSL_free(ssl); ssl = NULL;
  6998. CloseSocket(clientfd);
  6999. clientfd = -1;
  7000. count++;
  7001. }
  7002. #ifdef WOLFSSL_TIRTOS
  7003. Task_yield();
  7004. #endif
  7005. opts->return_code = TEST_SUCCESS;
  7006. done:
  7007. if (ssl != NULL) {
  7008. wolfSSL_shutdown(ssl);
  7009. wolfSSL_free(ssl);
  7010. }
  7011. if (!sharedCtx)
  7012. wolfSSL_CTX_free(ctx);
  7013. if (clientfd >= 0)
  7014. CloseSocket(clientfd);
  7015. #ifdef WOLFSSL_TIRTOS
  7016. fdCloseSession(Task_self());
  7017. #endif
  7018. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7019. && defined(HAVE_THREAD_LS)
  7020. wc_ecc_fp_free(); /* free per thread cache */
  7021. #endif
  7022. WOLFSSL_RETURN_FROM_THREAD(0);
  7023. }
  7024. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7025. static int test_client_nofail(void* args, cbType cb)
  7026. {
  7027. #if !defined(NO_WOLFSSL_CLIENT)
  7028. SOCKET_T sockfd = 0;
  7029. callback_functions* cbf;
  7030. WOLFSSL_CTX* ctx = 0;
  7031. WOLFSSL* ssl = 0;
  7032. WOLFSSL_CIPHER* cipher;
  7033. char msg[64] = "hello wolfssl!";
  7034. char reply[1024];
  7035. int input;
  7036. int msgSz = (int)XSTRLEN(msg);
  7037. int ret, err = 0;
  7038. int cipherSuite;
  7039. int sharedCtx = 0;
  7040. int doUdp = 0;
  7041. const char* cipherName1, *cipherName2;
  7042. wolfSSL_SetLoggingPrefix("client");
  7043. #ifdef WOLFSSL_TIRTOS
  7044. fdOpenSession(Task_self());
  7045. #endif
  7046. ((func_args*)args)->return_code = TEST_FAIL;
  7047. cbf = ((func_args*)args)->callbacks;
  7048. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7049. if (cbf != NULL && cbf->ctx) {
  7050. ctx = cbf->ctx;
  7051. sharedCtx = cbf->isSharedCtx;
  7052. }
  7053. else
  7054. #endif
  7055. {
  7056. WOLFSSL_METHOD* method = NULL;
  7057. if (cbf != NULL && cbf->method != NULL) {
  7058. method = cbf->method();
  7059. }
  7060. else {
  7061. method = wolfSSLv23_client_method();
  7062. }
  7063. ctx = wolfSSL_CTX_new(method);
  7064. }
  7065. if (cbf != NULL)
  7066. doUdp = cbf->doUdp;
  7067. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7068. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7069. #endif
  7070. /* Do connect here so server detects failures */
  7071. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7072. doUdp, 0, NULL);
  7073. /* Connect the socket so that we don't have to set the peer later on */
  7074. if (doUdp)
  7075. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7076. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7077. {
  7078. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7079. goto done;
  7080. }
  7081. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7082. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7083. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7084. #else
  7085. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7086. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7087. #endif
  7088. /*err_sys("can't load client cert file, "
  7089. "Please run from wolfSSL home dir");*/
  7090. goto done;
  7091. }
  7092. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7093. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7094. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7095. #else
  7096. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7097. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7098. #endif
  7099. /*err_sys("can't load client key file, "
  7100. "Please run from wolfSSL home dir");*/
  7101. goto done;
  7102. }
  7103. #ifdef HAVE_CRL
  7104. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7105. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7106. goto done;
  7107. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7108. != WOLFSSL_SUCCESS)
  7109. goto done;
  7110. }
  7111. #endif
  7112. /* call ctx setup callback */
  7113. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7114. cbf->ctx_ready(ctx);
  7115. }
  7116. ssl = wolfSSL_new(ctx);
  7117. if (ssl == NULL) {
  7118. goto done;
  7119. }
  7120. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7121. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7122. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7123. #else
  7124. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7125. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7126. #endif
  7127. /*err_sys("can't load client cert file, "
  7128. "Please run from wolfSSL home dir");*/
  7129. goto done;
  7130. }
  7131. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7132. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7133. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7134. #else
  7135. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7136. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7137. #endif
  7138. /*err_sys("can't load client key file, "
  7139. "Please run from wolfSSL home dir");*/
  7140. goto done;
  7141. }
  7142. if (!doUdp) {
  7143. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7144. /*err_sys("SSL_set_fd failed");*/
  7145. goto done;
  7146. }
  7147. }
  7148. else {
  7149. #ifdef WOLFSSL_DTLS
  7150. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7151. /*err_sys("SSL_set_fd failed");*/
  7152. goto done;
  7153. }
  7154. #else
  7155. goto done;
  7156. #endif
  7157. }
  7158. /* call ssl setup callback */
  7159. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7160. cbf->ssl_ready(ssl);
  7161. }
  7162. #ifdef WOLFSSL_ASYNC_CRYPT
  7163. err = 0; /* Reset error */
  7164. #endif
  7165. do {
  7166. #ifdef WOLFSSL_ASYNC_CRYPT
  7167. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7168. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7169. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7170. }
  7171. #endif
  7172. ret = wolfSSL_negotiate(ssl);
  7173. err = wolfSSL_get_error(ssl, 0);
  7174. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7175. if (ret != WOLFSSL_SUCCESS) {
  7176. char buff[WOLFSSL_MAX_ERROR_SZ];
  7177. fprintf(stderr, "error = %d, %s\n", err,
  7178. wolfSSL_ERR_error_string(err, buff));
  7179. /*err_sys("SSL_connect failed");*/
  7180. goto done;
  7181. }
  7182. /* test the various get cipher methods */
  7183. /* Internal cipher suite names */
  7184. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7185. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7186. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7187. (cipherSuite >> 8), cipherSuite & 0xFF);
  7188. AssertStrEQ(cipherName1, cipherName2);
  7189. /* IANA Cipher Suites Names */
  7190. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7191. then it's the internal cipher suite name */
  7192. cipher = wolfSSL_get_current_cipher(ssl);
  7193. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7194. cipherName2 = wolfSSL_get_cipher(ssl);
  7195. AssertStrEQ(cipherName1, cipherName2);
  7196. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7197. !defined(WOLFSSL_QT)
  7198. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7199. (cipherSuite >> 8), cipherSuite & 0xFF);
  7200. AssertStrEQ(cipherName1, cipherName2);
  7201. #endif
  7202. if (cb != NULL)
  7203. (cb)(ctx, ssl);
  7204. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7205. /*err_sys("SSL_write failed");*/
  7206. goto done;
  7207. }
  7208. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7209. if (input > 0) {
  7210. reply[input] = '\0';
  7211. fprintf(stderr, "Server response: %s\n", reply);
  7212. }
  7213. if (cbf != NULL && cbf->on_result != NULL)
  7214. cbf->on_result(ssl);
  7215. ((func_args*)args)->return_code = TEST_SUCCESS;
  7216. done:
  7217. if (cbf != NULL)
  7218. cbf->last_err = err;
  7219. if (cbf != NULL && cbf->on_cleanup != NULL)
  7220. cbf->on_cleanup(ssl);
  7221. wolfSSL_free(ssl);
  7222. if (!sharedCtx)
  7223. wolfSSL_CTX_free(ctx);
  7224. CloseSocket(sockfd);
  7225. #ifdef WOLFSSL_TIRTOS
  7226. fdCloseSession(Task_self());
  7227. #endif
  7228. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7229. && defined(HAVE_THREAD_LS)
  7230. wc_ecc_fp_free(); /* free per thread cache */
  7231. #endif
  7232. #else
  7233. (void)args;
  7234. (void)cb;
  7235. #endif /* !NO_WOLFSSL_CLIENT */
  7236. wolfSSL_SetLoggingPrefix(NULL);
  7237. return 0;
  7238. }
  7239. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7240. callback_functions* server_cb, cbType client_on_handshake)
  7241. {
  7242. func_args client_args;
  7243. func_args server_args;
  7244. tcp_ready ready;
  7245. THREAD_TYPE serverThread;
  7246. XMEMSET(&client_args, 0, sizeof(func_args));
  7247. XMEMSET(&server_args, 0, sizeof(func_args));
  7248. #ifdef WOLFSSL_TIRTOS
  7249. fdOpenSession(Task_self());
  7250. #endif
  7251. StartTCP();
  7252. InitTcpReady(&ready);
  7253. #if defined(USE_WINDOWS_API)
  7254. /* use RNG to get random port if using windows */
  7255. ready.port = GetRandomPort();
  7256. #endif
  7257. server_args.signal = &ready;
  7258. server_args.callbacks = server_cb;
  7259. client_args.signal = &ready;
  7260. client_args.callbacks = client_cb;
  7261. start_thread(test_server_nofail, &server_args, &serverThread);
  7262. wait_tcp_ready(&server_args);
  7263. test_client_nofail(&client_args, client_on_handshake);
  7264. join_thread(serverThread);
  7265. client_cb->return_code = client_args.return_code;
  7266. server_cb->return_code = server_args.return_code;
  7267. FreeTcpReady(&ready);
  7268. #ifdef WOLFSSL_TIRTOS
  7269. fdOpenSession(Task_self());
  7270. #endif
  7271. }
  7272. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7273. callback_functions* server_cb)
  7274. {
  7275. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7276. }
  7277. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7278. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7279. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7280. void* server_args)
  7281. {
  7282. SOCKET_T sockfd = 0;
  7283. callback_functions* cbf;
  7284. WOLFSSL_CTX* ctx = 0;
  7285. WOLFSSL* ssl = 0;
  7286. WOLFSSL_SESSION* session = NULL;
  7287. char msg[64] = "hello wolfssl!";
  7288. char reply[1024];
  7289. int input;
  7290. int msgSz = (int)XSTRLEN(msg);
  7291. int ret, err = 0;
  7292. int sharedCtx = 0;
  7293. #ifdef WOLFSSL_TIRTOS
  7294. fdOpenSession(Task_self());
  7295. #endif
  7296. ((func_args*)args)->return_code = TEST_FAIL;
  7297. cbf = ((func_args*)args)->callbacks;
  7298. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7299. if (cbf != NULL && cbf->ctx) {
  7300. ctx = cbf->ctx;
  7301. sharedCtx = 1;
  7302. }
  7303. else
  7304. #endif
  7305. {
  7306. WOLFSSL_METHOD* method = NULL;
  7307. if (cbf != NULL && cbf->method != NULL) {
  7308. method = cbf->method();
  7309. }
  7310. else {
  7311. method = wolfSSLv23_client_method();
  7312. }
  7313. ctx = wolfSSL_CTX_new(method);
  7314. }
  7315. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7316. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7317. #endif
  7318. /* Do connect here so server detects failures */
  7319. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7320. 0, 0, NULL);
  7321. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7322. WOLFSSL_SUCCESS) {
  7323. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7324. goto done;
  7325. }
  7326. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7327. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7328. /*err_sys("can't load client cert file, "
  7329. "Please run from wolfSSL home dir");*/
  7330. goto done;
  7331. }
  7332. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7333. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7334. /*err_sys("can't load client key file, "
  7335. "Please run from wolfSSL home dir");*/
  7336. goto done;
  7337. }
  7338. /* call ctx setup callback */
  7339. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7340. cbf->ctx_ready(ctx);
  7341. }
  7342. ssl = wolfSSL_new(ctx);
  7343. if (ssl == NULL) {
  7344. goto done;
  7345. }
  7346. /* keep handshake resources for re-using WOLFSSL obj */
  7347. wolfSSL_KeepArrays(ssl);
  7348. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7349. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7350. goto done;
  7351. }
  7352. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7353. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7354. /*err_sys("can't load client cert file, "
  7355. "Please run from wolfSSL home dir");*/
  7356. goto done;
  7357. }
  7358. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7359. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7360. /*err_sys("can't load client key file, "
  7361. "Please run from wolfSSL home dir");*/
  7362. goto done;
  7363. }
  7364. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7365. /*err_sys("SSL_set_fd failed");*/
  7366. goto done;
  7367. }
  7368. /* call ssl setup callback */
  7369. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7370. cbf->ssl_ready(ssl);
  7371. }
  7372. #ifdef WOLFSSL_ASYNC_CRYPT
  7373. err = 0; /* Reset error */
  7374. #endif
  7375. do {
  7376. #ifdef WOLFSSL_ASYNC_CRYPT
  7377. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7378. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7379. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7380. }
  7381. #endif
  7382. ret = wolfSSL_connect(ssl);
  7383. err = wolfSSL_get_error(ssl, 0);
  7384. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7385. if (ret != WOLFSSL_SUCCESS) {
  7386. char buff[WOLFSSL_MAX_ERROR_SZ];
  7387. fprintf(stderr, "error = %d, %s\n", err,
  7388. wolfSSL_ERR_error_string(err, buff));
  7389. /*err_sys("SSL_connect failed");*/
  7390. goto done;
  7391. }
  7392. /* Build first session */
  7393. if (cb != NULL)
  7394. cb(ctx, ssl);
  7395. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7396. /*err_sys("SSL_write failed");*/
  7397. goto done;
  7398. }
  7399. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7400. if (input > 0) {
  7401. reply[input] = '\0';
  7402. fprintf(stderr, "Server response: %s\n", reply);
  7403. }
  7404. /* Session Resumption by re-using WOLFSSL object */
  7405. wolfSSL_set_quiet_shutdown(ssl, 1);
  7406. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7407. /* err_sys ("SSL shutdown failed"); */
  7408. goto done;
  7409. }
  7410. session = wolfSSL_get1_session(ssl);
  7411. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7412. wolfSSL_SESSION_free(session);
  7413. /* err_sys ("SSL_clear failed"); */
  7414. goto done;
  7415. }
  7416. wolfSSL_set_session(ssl, session);
  7417. wolfSSL_SESSION_free(session);
  7418. session = NULL;
  7419. /* close socket once */
  7420. CloseSocket(sockfd);
  7421. sockfd = 0;
  7422. /* wait until server ready */
  7423. wait_tcp_ready((func_args*)server_args);
  7424. fprintf(stderr, "session resumption\n");
  7425. /* Do re-connect */
  7426. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7427. 0, 0, NULL);
  7428. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7429. /*err_sys("SSL_set_fd failed");*/
  7430. goto done;
  7431. }
  7432. #ifdef WOLFSSL_ASYNC_CRYPT
  7433. err = 0; /* Reset error */
  7434. #endif
  7435. do {
  7436. #ifdef WOLFSSL_ASYNC_CRYPT
  7437. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7438. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7439. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7440. }
  7441. #endif
  7442. ret = wolfSSL_connect(ssl);
  7443. err = wolfSSL_get_error(ssl, 0);
  7444. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7445. if (ret != WOLFSSL_SUCCESS) {
  7446. char buff[WOLFSSL_MAX_ERROR_SZ];
  7447. fprintf(stderr, "error = %d, %s\n", err,
  7448. wolfSSL_ERR_error_string(err, buff));
  7449. /*err_sys("SSL_connect failed");*/
  7450. goto done;
  7451. }
  7452. /* Build first session */
  7453. if (cb != NULL)
  7454. cb(ctx, ssl);
  7455. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7456. /*err_sys("SSL_write failed");*/
  7457. goto done;
  7458. }
  7459. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7460. if (input > 0) {
  7461. reply[input] = '\0';
  7462. fprintf(stderr, "Server response: %s\n", reply);
  7463. }
  7464. ((func_args*)args)->return_code = TEST_SUCCESS;
  7465. done:
  7466. wolfSSL_free(ssl);
  7467. if (!sharedCtx)
  7468. wolfSSL_CTX_free(ctx);
  7469. CloseSocket(sockfd);
  7470. #ifdef WOLFSSL_TIRTOS
  7471. fdCloseSession(Task_self());
  7472. #endif
  7473. return;
  7474. }
  7475. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7476. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7477. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7478. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7479. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7480. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7481. #define HAVE_ALPN_PROTOS_SUPPORT
  7482. #endif
  7483. /* Generic TLS client / server with callbacks for API unit tests
  7484. * Used by SNI / ALPN / crypto callback helper functions */
  7485. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7486. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7487. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7488. #define ENABLE_TLS_CALLBACK_TEST
  7489. #endif
  7490. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7491. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7492. /* TLS server for API unit testing - generic */
  7493. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7494. {
  7495. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7496. WOLFSSL_CTX* ctx = NULL;
  7497. WOLFSSL* ssl = NULL;
  7498. SOCKET_T sfd = 0;
  7499. SOCKET_T cfd = 0;
  7500. word16 port;
  7501. char msg[] = "I hear you fa shizzle!";
  7502. int len = (int) XSTRLEN(msg);
  7503. char input[1024];
  7504. int idx;
  7505. int ret, err = 0;
  7506. ((func_args*)args)->return_code = TEST_FAIL;
  7507. #if defined(USE_WINDOWS_API)
  7508. port = ((func_args*)args)->signal->port;
  7509. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7510. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7511. /* Let tcp_listen assign port */
  7512. port = 0;
  7513. #else
  7514. /* Use default port */
  7515. port = wolfSSLPort;
  7516. #endif
  7517. #ifdef WOLFSSL_DTLS
  7518. if (callbacks->method == wolfDTLS_server_method
  7519. #ifdef WOLFSSL_STATIC_MEMORY
  7520. || callbacks->method_ex == wolfDTLS_server_method_ex
  7521. #endif
  7522. #ifndef NO_OLD_TLS
  7523. || callbacks->method == wolfDTLSv1_server_method
  7524. #ifdef WOLFSSL_STATIC_MEMORY
  7525. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7526. #endif
  7527. #endif
  7528. #ifndef WOLFSSL_NO_TLS12
  7529. || callbacks->method == wolfDTLSv1_2_server_method
  7530. #ifdef WOLFSSL_STATIC_MEMORY
  7531. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7532. #endif
  7533. #endif
  7534. #ifdef WOLFSSL_DTLS13
  7535. || callbacks->method == wolfDTLSv1_3_server_method
  7536. #ifdef WOLFSSL_STATIC_MEMORY
  7537. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7538. #endif
  7539. #endif
  7540. ) {
  7541. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7542. }
  7543. else
  7544. #endif
  7545. {
  7546. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7547. }
  7548. #ifdef WOLFSSL_STATIC_MEMORY
  7549. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7550. callbacks->memSz > 0) {
  7551. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7552. callbacks->mem, callbacks->memSz, 0, 1);
  7553. if (ret != WOLFSSL_SUCCESS) {
  7554. fprintf(stderr, "CTX static new failed %d\n", ret);
  7555. goto cleanup;
  7556. }
  7557. }
  7558. #else
  7559. ctx = wolfSSL_CTX_new(callbacks->method());
  7560. #endif
  7561. if (ctx == NULL) {
  7562. fprintf(stderr, "CTX new failed\n");
  7563. goto cleanup;
  7564. }
  7565. /* set defaults */
  7566. if (callbacks->caPemFile == NULL)
  7567. callbacks->caPemFile = cliCertFile;
  7568. if (callbacks->certPemFile == NULL)
  7569. callbacks->certPemFile = svrCertFile;
  7570. if (callbacks->keyPemFile == NULL)
  7571. callbacks->keyPemFile = svrKeyFile;
  7572. #ifdef WOLFSSL_TIRTOS
  7573. fdOpenSession(Task_self());
  7574. #endif
  7575. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7576. wolfSSL_CTX_set_verify(ctx,
  7577. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7578. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7579. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7580. #endif
  7581. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7582. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7583. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7584. goto cleanup;
  7585. }
  7586. #endif
  7587. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7588. WOLFSSL_SUCCESS) {
  7589. goto cleanup;
  7590. }
  7591. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7592. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7593. goto cleanup;
  7594. }
  7595. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7596. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7597. goto cleanup;
  7598. }
  7599. #ifdef HAVE_CRL
  7600. if (callbacks->crlPemFile != NULL) {
  7601. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7602. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7603. goto cleanup;
  7604. }
  7605. }
  7606. #endif
  7607. if (callbacks->ctx_ready)
  7608. callbacks->ctx_ready(ctx);
  7609. ssl = wolfSSL_new(ctx);
  7610. if (ssl == NULL) {
  7611. fprintf(stderr, "SSL new failed\n");
  7612. goto cleanup;
  7613. }
  7614. if (wolfSSL_dtls(ssl)) {
  7615. SOCKADDR_IN_T cliAddr;
  7616. socklen_t cliLen;
  7617. cliLen = sizeof(cliAddr);
  7618. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7619. (struct sockaddr*)&cliAddr, &cliLen);
  7620. if (idx <= 0) {
  7621. goto cleanup;
  7622. }
  7623. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7624. }
  7625. else {
  7626. CloseSocket(sfd);
  7627. }
  7628. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7629. goto cleanup;
  7630. }
  7631. if (callbacks->loadToSSL) {
  7632. wolfSSL_SetDevId(ssl, callbacks->devId);
  7633. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7634. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7635. goto cleanup;
  7636. }
  7637. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7638. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7639. goto cleanup;
  7640. }
  7641. }
  7642. #ifdef NO_PSK
  7643. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7644. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7645. #elif !defined(NO_DH)
  7646. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7647. #endif
  7648. #endif
  7649. if (callbacks->ssl_ready)
  7650. callbacks->ssl_ready(ssl);
  7651. #ifdef WOLFSSL_ASYNC_CRYPT
  7652. err = 0; /* Reset error */
  7653. #endif
  7654. do {
  7655. #ifdef WOLFSSL_ASYNC_CRYPT
  7656. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7657. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7658. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7659. }
  7660. #endif
  7661. ret = wolfSSL_accept(ssl);
  7662. err = wolfSSL_get_error(ssl, ret);
  7663. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7664. if (ret != WOLFSSL_SUCCESS) {
  7665. char buff[WOLFSSL_MAX_ERROR_SZ];
  7666. fprintf(stderr, "accept error = %d, %s\n", err,
  7667. wolfSSL_ERR_error_string(err, buff));
  7668. /*err_sys("SSL_accept failed");*/
  7669. }
  7670. else {
  7671. #ifdef WOLFSSL_ASYNC_CRYPT
  7672. err = 0; /* Reset error */
  7673. #endif
  7674. do {
  7675. #ifdef WOLFSSL_ASYNC_CRYPT
  7676. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7677. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7678. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7679. }
  7680. #endif
  7681. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7682. err = wolfSSL_get_error(ssl, idx);
  7683. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7684. if (idx > 0) {
  7685. input[idx] = 0;
  7686. fprintf(stderr, "Client message: %s\n", input);
  7687. }
  7688. #ifdef WOLFSSL_ASYNC_CRYPT
  7689. err = 0; /* Reset error */
  7690. #endif
  7691. do {
  7692. #ifdef WOLFSSL_ASYNC_CRYPT
  7693. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7694. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7695. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7696. }
  7697. #endif
  7698. ret = wolfSSL_write(ssl, msg, len);
  7699. err = wolfSSL_get_error(ssl, ret);
  7700. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7701. if (len != ret) {
  7702. goto cleanup;
  7703. }
  7704. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7705. defined(WOLFSSL_DTLS)
  7706. if (wolfSSL_dtls(ssl)) {
  7707. byte* import;
  7708. word32 sz;
  7709. wolfSSL_dtls_export(ssl, NULL, &sz);
  7710. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7711. if (import == NULL) {
  7712. goto cleanup;
  7713. }
  7714. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7715. if (idx < 0) {
  7716. goto cleanup;
  7717. }
  7718. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7719. goto cleanup;
  7720. }
  7721. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7722. }
  7723. #endif
  7724. #ifdef WOLFSSL_TIRTOS
  7725. Task_yield();
  7726. #endif
  7727. ((func_args*)args)->return_code = TEST_SUCCESS;
  7728. }
  7729. if (callbacks->on_result)
  7730. callbacks->on_result(ssl);
  7731. wolfSSL_shutdown(ssl);
  7732. cleanup:
  7733. wolfSSL_free(ssl);
  7734. wolfSSL_CTX_free(ctx);
  7735. CloseSocket(cfd);
  7736. #ifdef WOLFSSL_TIRTOS
  7737. fdCloseSession(Task_self());
  7738. #endif
  7739. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7740. && defined(HAVE_THREAD_LS)
  7741. wc_ecc_fp_free(); /* free per thread cache */
  7742. #endif
  7743. WOLFSSL_RETURN_FROM_THREAD(0);
  7744. }
  7745. /* TLS Client for API unit testing - generic */
  7746. static void run_wolfssl_client(void* args)
  7747. {
  7748. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7749. WOLFSSL_CTX* ctx = NULL;
  7750. WOLFSSL* ssl = NULL;
  7751. SOCKET_T sfd = 0;
  7752. char msg[] = "hello wolfssl server!";
  7753. int len = (int) XSTRLEN(msg);
  7754. char input[1024];
  7755. int ret, err = 0;
  7756. ((func_args*)args)->return_code = TEST_FAIL;
  7757. /* set defaults */
  7758. if (callbacks->caPemFile == NULL)
  7759. callbacks->caPemFile = caCertFile;
  7760. if (callbacks->certPemFile == NULL)
  7761. callbacks->certPemFile = cliCertFile;
  7762. if (callbacks->keyPemFile == NULL)
  7763. callbacks->keyPemFile = cliKeyFile;
  7764. #ifdef WOLFSSL_STATIC_MEMORY
  7765. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7766. callbacks->memSz > 0) {
  7767. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7768. callbacks->mem, callbacks->memSz, 0, 1);
  7769. if (ret != WOLFSSL_SUCCESS) {
  7770. fprintf(stderr, "CTX static new failed %d\n", ret);
  7771. goto cleanup;
  7772. }
  7773. }
  7774. #else
  7775. ctx = wolfSSL_CTX_new(callbacks->method());
  7776. #endif
  7777. if (ctx == NULL) {
  7778. fprintf(stderr, "CTX new failed\n");
  7779. goto cleanup;
  7780. }
  7781. #ifdef WOLFSSL_TIRTOS
  7782. fdOpenSession(Task_self());
  7783. #endif
  7784. if (!callbacks->loadToSSL) {
  7785. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7786. }
  7787. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7788. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7789. #endif
  7790. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7791. WOLFSSL_SUCCESS) {
  7792. goto cleanup;
  7793. }
  7794. if (!callbacks->loadToSSL) {
  7795. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7796. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7797. goto cleanup;
  7798. }
  7799. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7800. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7801. goto cleanup;
  7802. }
  7803. }
  7804. #ifdef HAVE_CRL
  7805. if (callbacks->crlPemFile != NULL) {
  7806. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7807. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7808. goto cleanup;
  7809. }
  7810. }
  7811. #endif
  7812. if (callbacks->ctx_ready)
  7813. callbacks->ctx_ready(ctx);
  7814. ssl = wolfSSL_new(ctx);
  7815. if (wolfSSL_dtls(ssl)) {
  7816. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7817. 1, 0, ssl);
  7818. }
  7819. else {
  7820. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7821. 0, 0, ssl);
  7822. }
  7823. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  7824. goto cleanup;
  7825. }
  7826. if (callbacks->loadToSSL) {
  7827. wolfSSL_SetDevId(ssl, callbacks->devId);
  7828. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7829. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7830. goto cleanup;
  7831. }
  7832. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7833. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7834. goto cleanup;
  7835. }
  7836. }
  7837. if (callbacks->ssl_ready)
  7838. callbacks->ssl_ready(ssl);
  7839. #ifdef WOLFSSL_ASYNC_CRYPT
  7840. err = 0; /* Reset error */
  7841. #endif
  7842. do {
  7843. #ifdef WOLFSSL_ASYNC_CRYPT
  7844. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7845. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7846. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7847. }
  7848. #endif
  7849. ret = wolfSSL_connect(ssl);
  7850. err = wolfSSL_get_error(ssl, ret);
  7851. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7852. if (ret != WOLFSSL_SUCCESS) {
  7853. char buff[WOLFSSL_MAX_ERROR_SZ];
  7854. fprintf(stderr, "error = %d, %s\n", err,
  7855. wolfSSL_ERR_error_string(err, buff));
  7856. /*err_sys("SSL_connect failed");*/
  7857. }
  7858. else {
  7859. #ifdef WOLFSSL_ASYNC_CRYPT
  7860. err = 0; /* Reset error */
  7861. #endif
  7862. do {
  7863. #ifdef WOLFSSL_ASYNC_CRYPT
  7864. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7865. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7866. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7867. }
  7868. #endif
  7869. ret = wolfSSL_write(ssl, msg, len);
  7870. err = wolfSSL_get_error(ssl, ret);
  7871. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7872. if (len != ret)
  7873. goto cleanup;
  7874. #ifdef WOLFSSL_ASYNC_CRYPT
  7875. err = 0; /* Reset error */
  7876. #endif
  7877. do {
  7878. #ifdef WOLFSSL_ASYNC_CRYPT
  7879. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7880. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7881. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7882. }
  7883. #endif
  7884. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  7885. err = wolfSSL_get_error(ssl, ret);
  7886. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7887. if (ret > 0) {
  7888. input[ret] = '\0'; /* null term */
  7889. fprintf(stderr, "Server response: %s\n", input);
  7890. }
  7891. ((func_args*)args)->return_code = TEST_SUCCESS;
  7892. }
  7893. if (callbacks->on_result)
  7894. callbacks->on_result(ssl);
  7895. cleanup:
  7896. wolfSSL_free(ssl);
  7897. wolfSSL_CTX_free(ctx);
  7898. CloseSocket(sfd);
  7899. #ifdef WOLFSSL_TIRTOS
  7900. fdCloseSession(Task_self());
  7901. #endif
  7902. }
  7903. #endif /* ENABLE_TLS_CALLBACK_TEST */
  7904. static int test_wolfSSL_read_write(void)
  7905. {
  7906. /* The unit testing for read and write shall happen simultaneously, since
  7907. * one can't do anything with one without the other. (Except for a failure
  7908. * test case.) This function will call all the others that will set up,
  7909. * execute, and report their test findings.
  7910. *
  7911. * Set up the success case first. This function will become the template
  7912. * for the other tests. This should eventually be renamed
  7913. *
  7914. * The success case isn't interesting, how can this fail?
  7915. * - Do not give the client context a CA certificate. The connect should
  7916. * fail. Do not need server for this?
  7917. * - Using NULL for the ssl object on server. Do not need client for this.
  7918. * - Using NULL for the ssl object on client. Do not need server for this.
  7919. * - Good ssl objects for client and server. Client write() without server
  7920. * read().
  7921. * - Good ssl objects for client and server. Server write() without client
  7922. * read().
  7923. * - Forgetting the password callback?
  7924. */
  7925. tcp_ready ready;
  7926. func_args client_args;
  7927. func_args server_args;
  7928. THREAD_TYPE serverThread;
  7929. EXPECT_DECLS;
  7930. XMEMSET(&client_args, 0, sizeof(func_args));
  7931. XMEMSET(&server_args, 0, sizeof(func_args));
  7932. #ifdef WOLFSSL_TIRTOS
  7933. fdOpenSession(Task_self());
  7934. #endif
  7935. StartTCP();
  7936. InitTcpReady(&ready);
  7937. #if defined(USE_WINDOWS_API)
  7938. /* use RNG to get random port if using windows */
  7939. ready.port = GetRandomPort();
  7940. #endif
  7941. server_args.signal = &ready;
  7942. client_args.signal = &ready;
  7943. start_thread(test_server_nofail, &server_args, &serverThread);
  7944. wait_tcp_ready(&server_args);
  7945. test_client_nofail(&client_args, NULL);
  7946. join_thread(serverThread);
  7947. ExpectTrue(client_args.return_code);
  7948. ExpectTrue(server_args.return_code);
  7949. FreeTcpReady(&ready);
  7950. #ifdef WOLFSSL_TIRTOS
  7951. fdOpenSession(Task_self());
  7952. #endif
  7953. return EXPECT_RESULT();
  7954. }
  7955. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  7956. {
  7957. EXPECT_DECLS;
  7958. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7959. !defined(WOLFSSL_NO_TLS12)
  7960. /* The unit test for session resumption by re-using WOLFSSL object.
  7961. * WOLFSSL object is not cleared after first session. It reuse the object
  7962. * for second connection.
  7963. */
  7964. tcp_ready ready;
  7965. func_args client_args;
  7966. func_args server_args;
  7967. THREAD_TYPE serverThread;
  7968. callback_functions client_cbf;
  7969. callback_functions server_cbf;
  7970. XMEMSET(&client_args, 0, sizeof(func_args));
  7971. XMEMSET(&server_args, 0, sizeof(func_args));
  7972. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  7973. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  7974. #ifdef WOLFSSL_TIRTOS
  7975. fdOpenSession(Task_self());
  7976. #endif
  7977. StartTCP();
  7978. InitTcpReady(&ready);
  7979. #if defined(USE_WINDOWS_API)
  7980. /* use RNG to get random port if using windows */
  7981. ready.port = GetRandomPort();
  7982. #endif
  7983. client_cbf.method = wolfTLSv1_2_client_method;
  7984. server_cbf.method = wolfTLSv1_2_server_method;
  7985. client_args.callbacks = &client_cbf;
  7986. server_args.callbacks = &server_cbf;
  7987. server_args.signal = &ready;
  7988. client_args.signal = &ready;
  7989. /* the var is used for loop number */
  7990. server_args.argc = 2;
  7991. start_thread(test_server_loop, &server_args, &serverThread);
  7992. wait_tcp_ready(&server_args);
  7993. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  7994. join_thread(serverThread);
  7995. ExpectTrue(client_args.return_code);
  7996. ExpectTrue(server_args.return_code);
  7997. FreeTcpReady(&ready);
  7998. #ifdef WOLFSSL_TIRTOS
  7999. fdOpenSession(Task_self());
  8000. #endif
  8001. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8002. * !defined(WOLFSSL_TLS13) */
  8003. return EXPECT_RESULT();
  8004. }
  8005. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8006. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8007. WOLFSSL_CTX* ctx)
  8008. {
  8009. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8010. myVerifyAction = VERIFY_USE_PREVERFIY;
  8011. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8012. return TEST_SUCCESS;
  8013. }
  8014. #endif
  8015. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8016. {
  8017. EXPECT_DECLS;
  8018. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8019. test_ssl_cbf client_cbf;
  8020. test_ssl_cbf server_cbf;
  8021. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8022. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8023. #ifdef WOLFSSL_TLS13
  8024. client_cbf.method = wolfTLSv1_3_client_method;
  8025. #endif /* WOLFSSL_TLS13 */
  8026. client_cbf.ctx_ready =
  8027. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8028. /* test case 1 verify depth is equal to peer chain */
  8029. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8030. &server_cbf, NULL), TEST_SUCCESS);
  8031. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8032. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8033. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8034. return EXPECT_RESULT();
  8035. }
  8036. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8037. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8038. WOLFSSL_CTX* ctx)
  8039. {
  8040. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8041. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8042. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8043. return TEST_SUCCESS;
  8044. }
  8045. #endif
  8046. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8047. {
  8048. EXPECT_DECLS;
  8049. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8050. test_ssl_cbf client_cbf;
  8051. test_ssl_cbf server_cbf;
  8052. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8053. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8054. #ifdef WOLFSSL_TLS13
  8055. client_cbf.method = wolfTLSv1_3_client_method;
  8056. #endif /* WOLFSSL_TLS13 */
  8057. client_cbf.ctx_ready =
  8058. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8059. /* test case 2
  8060. * verify depth is zero, number of peer's chain is 2.
  8061. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8062. * callback.
  8063. */
  8064. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8065. &server_cbf, NULL), TEST_SUCCESS);
  8066. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8067. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8068. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8069. return EXPECT_RESULT();
  8070. }
  8071. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8072. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8073. WOLFSSL_CTX* ctx)
  8074. {
  8075. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8076. myVerifyAction = VERIFY_USE_PREVERFIY;
  8077. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8078. return TEST_SUCCESS;
  8079. }
  8080. #endif
  8081. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8082. {
  8083. EXPECT_DECLS;
  8084. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8085. test_ssl_cbf client_cbf;
  8086. test_ssl_cbf server_cbf;
  8087. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8088. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8089. #ifdef WOLFSSL_TLS13
  8090. client_cbf.method = wolfTLSv1_3_client_method;
  8091. #endif /* WOLFSSL_TLS13 */
  8092. client_cbf.ctx_ready =
  8093. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8094. /* test case 3
  8095. * verify depth is zero, number of peer's chain is 2
  8096. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8097. * therefore, handshake becomes failure.
  8098. */
  8099. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8100. &server_cbf, NULL), TEST_FAIL);
  8101. ExpectIntEQ(client_cbf.return_code, TEST_FAIL);
  8102. ExpectIntEQ(server_cbf.return_code, TEST_FAIL);
  8103. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8104. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8105. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8106. return EXPECT_RESULT();
  8107. }
  8108. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8109. !defined(WOLFSSL_NO_TLS12) && \
  8110. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8111. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8112. {
  8113. EXPECT_DECLS;
  8114. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8115. return EXPECT_RESULT();
  8116. }
  8117. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8118. {
  8119. EXPECT_DECLS;
  8120. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8121. return EXPECT_RESULT();
  8122. }
  8123. #endif
  8124. static int test_wolfSSL_CTX_set_cipher_list(void)
  8125. {
  8126. EXPECT_DECLS;
  8127. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8128. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8129. #if !defined(WOLFSSL_NO_TLS12)
  8130. WOLFSSL_CTX* ctxClient = NULL;
  8131. WOLFSSL* sslClient = NULL;
  8132. test_ssl_cbf client_cbf;
  8133. test_ssl_cbf server_cbf;
  8134. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8135. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8136. server_cbf.method = wolfTLSv1_2_server_method;
  8137. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8138. client_cbf.method = wolfTLSv1_2_client_method;
  8139. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8140. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8141. &server_cbf, NULL), TEST_SUCCESS);
  8142. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8143. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8144. /* check with cipher string that has '+' */
  8145. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8146. /* Use trailing : with nothing to test for ASAN */
  8147. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8148. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8149. /* check for the existence of an ECDHE ECDSA cipher suite */
  8150. if (EXPECT_SUCCESS()) {
  8151. int i = 0;
  8152. int found = 0;
  8153. const char* suite;
  8154. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8155. WOLFSSL_CIPHER* current;
  8156. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8157. do {
  8158. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8159. if (current) {
  8160. suite = wolfSSL_CIPHER_get_name(current);
  8161. if (suite && XSTRSTR(suite, "ECDSA")) {
  8162. found = 1;
  8163. break;
  8164. }
  8165. }
  8166. } while (current);
  8167. ExpectIntEQ(found, 1);
  8168. }
  8169. wolfSSL_free(sslClient);
  8170. wolfSSL_CTX_free(ctxClient);
  8171. #endif /* !WOLFSSL_NO_TLS12 */
  8172. #endif
  8173. return EXPECT_RESULT();
  8174. }
  8175. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8176. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8177. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8178. WOLFSSL* ssl)
  8179. {
  8180. EXPECT_DECLS;
  8181. size_t msg_len;
  8182. (void)ctx;
  8183. /* get_finished test */
  8184. /* 1. get own sent message */
  8185. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8186. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8187. ExpectIntGE(msg_len, 0);
  8188. /* 2. get peer message */
  8189. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8190. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8191. ExpectIntGE(msg_len, 0);
  8192. return EXPECT_RESULT();
  8193. }
  8194. #endif
  8195. static int test_wolfSSL_get_finished(void)
  8196. {
  8197. EXPECT_DECLS;
  8198. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8199. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8200. test_ssl_cbf client_cbf;
  8201. test_ssl_cbf server_cbf;
  8202. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8203. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8204. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8205. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8206. TEST_SUCCESS);
  8207. /* test received msg vs sent msg */
  8208. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8209. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8210. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8211. return EXPECT_RESULT();
  8212. }
  8213. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8214. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8215. !defined(NO_SESSION_CACHE)
  8216. /* Sessions to restore/store */
  8217. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8218. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8219. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8220. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8221. {
  8222. /* Don't store sessions. Lookup is still enabled. */
  8223. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8224. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8225. #ifdef OPENSSL_EXTRA
  8226. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8227. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8228. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8229. #endif
  8230. /* Require both peers to provide certs */
  8231. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8232. }
  8233. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8234. {
  8235. WOLFSSL_SESSION** sess;
  8236. if (wolfSSL_is_server(ssl))
  8237. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8238. else
  8239. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8240. if (*sess == NULL) {
  8241. #ifdef NO_SESSION_CACHE_REF
  8242. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8243. #else
  8244. /* Test for backwards compatibility */
  8245. if (wolfSSL_is_server(ssl)) {
  8246. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8247. }
  8248. else {
  8249. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8250. }
  8251. #endif
  8252. /* Now save the session in the internal store to make it available
  8253. * for lookup. For TLS 1.3, we can't save the session without
  8254. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8255. * session from cache. */
  8256. if (wolfSSL_is_server(ssl)
  8257. #ifndef WOLFSSL_TICKET_HAVE_ID
  8258. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8259. #endif
  8260. )
  8261. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8262. *sess), WOLFSSL_SUCCESS);
  8263. }
  8264. else {
  8265. /* If we have a session retrieved then remaining connections should be
  8266. * resuming on that session */
  8267. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8268. }
  8269. /* Save CTX to be able to decrypt tickets */
  8270. if (wolfSSL_is_server(ssl) &&
  8271. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8272. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8273. = wolfSSL_get_SSL_CTX(ssl));
  8274. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8275. WOLFSSL_SUCCESS);
  8276. }
  8277. #ifdef SESSION_CERTS
  8278. #ifndef WOLFSSL_TICKET_HAVE_ID
  8279. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8280. wolfSSL_session_reused(ssl))
  8281. #endif
  8282. {
  8283. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8284. * for all connections. TLS 1.3 only has tickets so if we don't
  8285. * include the session id in the ticket then the certificates
  8286. * will not be available on resumption. */
  8287. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8288. AssertNotNull(peer);
  8289. wolfSSL_X509_free(peer);
  8290. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8291. #ifdef OPENSSL_EXTRA
  8292. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8293. #endif
  8294. }
  8295. #endif /* SESSION_CERTS */
  8296. }
  8297. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8298. {
  8299. /* Set the session to reuse for the client */
  8300. AssertIntEQ(wolfSSL_set_session(ssl,
  8301. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8302. }
  8303. #endif
  8304. static int test_wolfSSL_CTX_add_session(void)
  8305. {
  8306. EXPECT_DECLS;
  8307. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8308. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8309. !defined(NO_SESSION_CACHE)
  8310. tcp_ready ready;
  8311. func_args client_args;
  8312. func_args server_args;
  8313. THREAD_TYPE serverThread;
  8314. callback_functions client_cb;
  8315. callback_functions server_cb;
  8316. method_provider methods[][2] = {
  8317. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8318. !defined(NO_DES3))
  8319. /* Without AES there are almost no ciphersuites available. This leads
  8320. * to no ciphersuites being available and an error. */
  8321. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8322. #endif
  8323. #ifndef WOLFSSL_NO_TLS12
  8324. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8325. #endif
  8326. /* Needs the default ticket callback since it is tied to the
  8327. * connection context and this makes it easy to carry over the ticket
  8328. * crypto context between connections */
  8329. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8330. defined(HAVE_SESSION_TICKET)
  8331. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8332. #endif
  8333. };
  8334. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8335. size_t i, j;
  8336. for (i = 0; i < methodsLen; i++) {
  8337. /* First run creates a connection while the second+ run will attempt
  8338. * to resume the connection. The trick is that the internal cache
  8339. * is turned off. wolfSSL_CTX_add_session should put the session in
  8340. * the cache anyway. */
  8341. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8342. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8343. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8344. #ifdef NO_SESSION_CACHE_REF
  8345. for (j = 0; j < 4; j++) {
  8346. #else
  8347. /* The session may be overwritten in this case. Do only one resumption
  8348. * to stop this test from failing intermittently. */
  8349. for (j = 0; j < 2; j++) {
  8350. #endif
  8351. #ifdef WOLFSSL_TIRTOS
  8352. fdOpenSession(Task_self());
  8353. #endif
  8354. StartTCP();
  8355. InitTcpReady(&ready);
  8356. XMEMSET(&client_args, 0, sizeof(func_args));
  8357. XMEMSET(&server_args, 0, sizeof(func_args));
  8358. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8359. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8360. client_cb.method = methods[i][0];
  8361. server_cb.method = methods[i][1];
  8362. server_args.signal = &ready;
  8363. server_args.callbacks = &server_cb;
  8364. client_args.signal = &ready;
  8365. client_args.callbacks = &client_cb;
  8366. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8367. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8368. server_cb.isSharedCtx = 1;
  8369. }
  8370. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8371. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8372. if (j != 0)
  8373. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8374. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8375. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8376. server_cb.ticNoInit = 1; /* Use default builtin */
  8377. start_thread(test_server_nofail, &server_args, &serverThread);
  8378. wait_tcp_ready(&server_args);
  8379. test_client_nofail(&client_args, NULL);
  8380. join_thread(serverThread);
  8381. ExpectTrue(client_args.return_code);
  8382. ExpectTrue(server_args.return_code);
  8383. FreeTcpReady(&ready);
  8384. if (EXPECT_FAIL())
  8385. break;
  8386. }
  8387. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8388. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8389. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8390. if (EXPECT_FAIL())
  8391. break;
  8392. }
  8393. #endif
  8394. return EXPECT_RESULT();
  8395. }
  8396. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8397. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8398. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8399. defined(HAVE_SESSION_TICKET) && \
  8400. !defined(TITAN_SESSION_CACHE) && \
  8401. !defined(HUGE_SESSION_CACHE) && \
  8402. !defined(BIG_SESSION_CACHE) && \
  8403. !defined(MEDIUM_SESSION_CACHE)
  8404. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8405. /* Sessions to restore/store */
  8406. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8407. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8408. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8409. static int twcase_new_session_called = 0;
  8410. static int twcase_remove_session_called = 0;
  8411. static int twcase_get_session_called = 0;
  8412. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8413. #define SESSION_CACHE_SIZE 33
  8414. typedef struct {
  8415. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8416. WOLFSSL_SESSION* value;
  8417. } hashTable_entry;
  8418. typedef struct {
  8419. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8420. size_t capacity; /* size of entries */
  8421. size_t length; /* number of items in the hash table */
  8422. wolfSSL_Mutex htLock; /* lock */
  8423. }hashTable;
  8424. static hashTable server_sessionCache;
  8425. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8426. {
  8427. int i;
  8428. unsigned int len;
  8429. (void)ssl;
  8430. /*
  8431. * This example uses a hash table.
  8432. * Steps you should take for a non-demo code:
  8433. * - acquire a lock for the file named according to the session id
  8434. * - open the file
  8435. * - encrypt and write the SSL_SESSION object to the file
  8436. * - release the lock
  8437. *
  8438. * Return:
  8439. * 0: The callback does not wish to hold a reference of the sess
  8440. * 1: The callback wants to hold a reference of the sess. The callback is
  8441. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8442. */
  8443. if (sess == NULL)
  8444. return 0;
  8445. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8446. return 0;
  8447. }
  8448. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8449. if (server_sessionCache.entries[i].value == NULL) {
  8450. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8451. server_sessionCache.entries[i].value = sess;
  8452. server_sessionCache.length++;
  8453. break;
  8454. }
  8455. }
  8456. ++twcase_new_session_called;
  8457. wc_UnLockMutex(&server_sessionCache.htLock);
  8458. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8459. twcase_new_session_called);
  8460. return 1;
  8461. }
  8462. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8463. {
  8464. int i;
  8465. (void)ctx;
  8466. (void)sess;
  8467. if (sess == NULL)
  8468. return;
  8469. /*
  8470. * This example uses a hash table.
  8471. * Steps you should take for a non-demo code:
  8472. * - acquire a lock for the file named according to the session id
  8473. * - remove the file
  8474. * - release the lock
  8475. */
  8476. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8477. return;
  8478. }
  8479. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8480. if (server_sessionCache.entries[i].key != NULL &&
  8481. XMEMCMP(server_sessionCache.entries[i].key,
  8482. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8483. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8484. server_sessionCache.entries[i].value = NULL;
  8485. server_sessionCache.entries[i].key = NULL;
  8486. server_sessionCache.length--;
  8487. break;
  8488. }
  8489. }
  8490. ++twcase_remove_session_called;
  8491. wc_UnLockMutex(&server_sessionCache.htLock);
  8492. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8493. twcase_remove_session_called);
  8494. }
  8495. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8496. const unsigned char *id, int len, int *ref)
  8497. {
  8498. int i;
  8499. (void)ssl;
  8500. (void)id;
  8501. (void)len;
  8502. /*
  8503. * This example uses a hash table.
  8504. * Steps you should take for a non-demo code:
  8505. * - acquire a lock for the file named according to the session id in the
  8506. * 2nd arg
  8507. * - read and decrypt contents of file and create a new SSL_SESSION
  8508. * - object release the lock
  8509. * - return the new session object
  8510. */
  8511. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8512. ++twcase_get_session_called);
  8513. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8514. * be responsible for the pointer then set to 0. */
  8515. *ref = 1;
  8516. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8517. if (server_sessionCache.entries[i].key != NULL &&
  8518. XMEMCMP(server_sessionCache.entries[i].key, id,
  8519. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8520. return server_sessionCache.entries[i].value;
  8521. }
  8522. }
  8523. return NULL;
  8524. }
  8525. static int twcase_get_sessionCb_cleanup(void)
  8526. {
  8527. int i;
  8528. int cnt = 0;
  8529. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8530. * for freeing sessions */
  8531. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8532. if (server_sessionCache.entries[i].value != NULL) {
  8533. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8534. cnt++;
  8535. }
  8536. }
  8537. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8538. cnt);
  8539. return TEST_SUCCESS;
  8540. }
  8541. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8542. {
  8543. EXPECT_DECLS;
  8544. /* off - Disable internal cache */
  8545. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8546. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8547. #ifdef OPENSSL_EXTRA
  8548. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8549. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8550. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8551. #endif
  8552. /* off - Do not setup external cache */
  8553. /* Require both peers to provide certs */
  8554. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8555. return EXPECT_RESULT();
  8556. }
  8557. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8558. {
  8559. /* on - internal cache is on by default */
  8560. /* off - Do not setup external cache */
  8561. /* Require both peers to provide certs */
  8562. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8563. return TEST_SUCCESS;
  8564. }
  8565. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8566. {
  8567. EXPECT_DECLS;
  8568. /* off - Disable internal cache */
  8569. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8570. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8571. #ifdef OPENSSL_EXTRA
  8572. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8573. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8574. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8575. #endif
  8576. /* on - Enable external cache */
  8577. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8578. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8579. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8580. /* Require both peers to provide certs */
  8581. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8582. return EXPECT_RESULT();
  8583. }
  8584. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8585. {
  8586. /* on - internal cache is on by default */
  8587. /* on - Enable external cache */
  8588. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8589. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8590. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8591. /* Require both peers to provide certs */
  8592. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8593. return TEST_SUCCESS;
  8594. }
  8595. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8596. {
  8597. /* on - internal cache is on by default */
  8598. /* on - Enable external cache */
  8599. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8600. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8601. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8602. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8603. /* Require both peers to provide certs */
  8604. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8605. return TEST_SUCCESS;
  8606. }
  8607. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8608. {
  8609. EXPECT_DECLS;
  8610. WOLFSSL_SESSION** sess;
  8611. if (wolfSSL_is_server(ssl))
  8612. sess = &twcase_server_first_session_ptr;
  8613. else
  8614. return TEST_SUCCESS;
  8615. if (*sess == NULL) {
  8616. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8617. /* Now save the session in the internal store to make it available
  8618. * for lookup. For TLS 1.3, we can't save the session without
  8619. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8620. * session from cache. */
  8621. if (wolfSSL_is_server(ssl)
  8622. #ifndef WOLFSSL_TICKET_HAVE_ID
  8623. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8624. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8625. #endif
  8626. ) {
  8627. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8628. *sess), WOLFSSL_SUCCESS);
  8629. }
  8630. }
  8631. /* Save CTX to be able to decrypt tickets */
  8632. if (twcase_server_current_ctx_ptr == NULL) {
  8633. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8634. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8635. WOLFSSL_SUCCESS);
  8636. }
  8637. #ifdef SESSION_CERTS
  8638. #ifndef WOLFSSL_TICKET_HAVE_ID
  8639. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8640. wolfSSL_session_reused(ssl))
  8641. #endif
  8642. {
  8643. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8644. * for all connections. TLS 1.3 only has tickets so if we don't
  8645. * include the session id in the ticket then the certificates
  8646. * will not be available on resumption. */
  8647. WOLFSSL_X509* peer = NULL;
  8648. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8649. wolfSSL_X509_free(peer);
  8650. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8651. }
  8652. #endif
  8653. return EXPECT_RESULT();
  8654. }
  8655. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8656. {
  8657. EXPECT_DECLS;
  8658. WOLFSSL_SESSION** sess;
  8659. sess = &twcase_client_first_session_ptr;
  8660. if (*sess == NULL) {
  8661. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8662. }
  8663. else {
  8664. /* If we have a session retrieved then remaining connections should be
  8665. * resuming on that session */
  8666. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8667. }
  8668. #ifdef SESSION_CERTS
  8669. #ifndef WOLFSSL_TICKET_HAVE_ID
  8670. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8671. wolfSSL_session_reused(ssl))
  8672. #endif
  8673. {
  8674. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8675. ExpectNotNull(peer);
  8676. wolfSSL_X509_free(peer);
  8677. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8678. #ifdef OPENSSL_EXTRA
  8679. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8680. #endif
  8681. }
  8682. #endif
  8683. return EXPECT_RESULT();
  8684. }
  8685. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8686. {
  8687. EXPECT_DECLS;
  8688. /* Set the session to reuse for the client */
  8689. ExpectNotNull(ssl);
  8690. ExpectNotNull(twcase_client_first_session_ptr);
  8691. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8692. WOLFSSL_SUCCESS);
  8693. return EXPECT_RESULT();
  8694. }
  8695. struct test_add_session_ext_params {
  8696. method_provider client_meth;
  8697. method_provider server_meth;
  8698. const char* tls_version;
  8699. };
  8700. static int test_wolfSSL_CTX_add_session_ext(
  8701. struct test_add_session_ext_params* param)
  8702. {
  8703. EXPECT_DECLS;
  8704. /* Test the default 33 sessions */
  8705. int j;
  8706. /* Clear cache before starting */
  8707. wolfSSL_CTX_flush_sessions(NULL, -1);
  8708. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8709. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8710. return BAD_MUTEX_E;
  8711. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8712. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8713. for (j = 0; j < 5; j++) {
  8714. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8715. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8716. test_ssl_cbf client_cb;
  8717. test_ssl_cbf server_cb;
  8718. (void)dtls;
  8719. /* Test five cache configurations */
  8720. twcase_client_first_session_ptr = NULL;
  8721. twcase_server_first_session_ptr = NULL;
  8722. twcase_server_current_ctx_ptr = NULL;
  8723. twcase_new_session_called = 0;
  8724. twcase_remove_session_called = 0;
  8725. twcase_get_session_called = 0;
  8726. /* connection 1 - first connection */
  8727. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8728. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8729. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8730. client_cb.method = param->client_meth;
  8731. server_cb.method = param->server_meth;
  8732. if (dtls)
  8733. client_cb.doUdp = server_cb.doUdp = 1;
  8734. /* Setup internal and external cache */
  8735. switch (j) {
  8736. case 0:
  8737. /* SSL_OP_NO_TICKET stateful ticket case */
  8738. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8739. break;
  8740. case 1:
  8741. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8742. break;
  8743. case 2:
  8744. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8745. break;
  8746. case 3:
  8747. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8748. break;
  8749. case 4:
  8750. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8751. break;
  8752. }
  8753. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8754. /* Add session to internal cache and save SSL session for testing */
  8755. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8756. /* Save client SSL session for testing */
  8757. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8758. server_cb.ticNoInit = 1; /* Use default builtin */
  8759. /* Don't free/release ctx */
  8760. server_cb.ctx = twcase_server_current_ctx_ptr;
  8761. server_cb.isSharedCtx = 1;
  8762. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8763. &server_cb, NULL), TEST_SUCCESS);
  8764. ExpectIntEQ(twcase_get_session_called, 0);
  8765. if (EXPECT_FAIL()) {
  8766. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8767. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8768. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8769. break;
  8770. }
  8771. switch (j) {
  8772. case 0:
  8773. case 1:
  8774. case 2:
  8775. /* cache cannot be searched with out a connection */
  8776. /* Add a new session */
  8777. ExpectIntEQ(twcase_new_session_called, 1);
  8778. /* In twcase_server_sess_ctx_pre_shutdown
  8779. * wolfSSL_CTX_add_session which evicts the existing session
  8780. * in cache and adds it back in */
  8781. ExpectIntLE(twcase_remove_session_called, 1);
  8782. break;
  8783. case 3:
  8784. case 4:
  8785. /* no external cache */
  8786. ExpectIntEQ(twcase_new_session_called, 0);
  8787. ExpectIntEQ(twcase_remove_session_called, 0);
  8788. break;
  8789. }
  8790. /* connection 2 - session resume */
  8791. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  8792. twcase_new_session_called = 0;
  8793. twcase_remove_session_called = 0;
  8794. twcase_get_session_called = 0;
  8795. server_cb.on_result = 0;
  8796. client_cb.on_result = 0;
  8797. server_cb.ticNoInit = 1; /* Use default builtin */
  8798. server_cb.ctx = twcase_server_current_ctx_ptr;
  8799. /* try session resumption */
  8800. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  8801. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8802. &server_cb, NULL), TEST_SUCCESS);
  8803. /* Clear cache before checking */
  8804. wolfSSL_CTX_flush_sessions(NULL, -1);
  8805. switch (j) {
  8806. case 0:
  8807. if (tls13) {
  8808. /* (D)TLSv1.3 stateful case */
  8809. /* cache hit */
  8810. /* DTLS accesses cache once for stateless parsing and
  8811. * once for stateful parsing */
  8812. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8813. /* (D)TLSv1.3 creates a new ticket,
  8814. * updates both internal and external cache */
  8815. ExpectIntEQ(twcase_new_session_called, 1);
  8816. /* A new session ID is created for a new ticket */
  8817. ExpectIntEQ(twcase_remove_session_called, 2);
  8818. }
  8819. else {
  8820. /* non (D)TLSv1.3 case, no update */
  8821. /* DTLS accesses cache once for stateless parsing and
  8822. * once for stateful parsing */
  8823. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8824. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8825. #else
  8826. ExpectIntEQ(twcase_get_session_called, 1);
  8827. #endif
  8828. ExpectIntEQ(twcase_new_session_called, 0);
  8829. /* Called on session added in
  8830. * twcase_server_sess_ctx_pre_shutdown */
  8831. ExpectIntEQ(twcase_remove_session_called, 1);
  8832. }
  8833. break;
  8834. case 1:
  8835. if (tls13) {
  8836. /* (D)TLSv1.3 case */
  8837. /* cache hit */
  8838. ExpectIntEQ(twcase_get_session_called, 1);
  8839. /* (D)TLSv1.3 creates a new ticket,
  8840. * updates both internal and external cache */
  8841. ExpectIntEQ(twcase_new_session_called, 1);
  8842. /* Called on session added in
  8843. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  8844. ExpectIntEQ(twcase_remove_session_called, 1);
  8845. }
  8846. else {
  8847. /* non (D)TLSv1.3 case */
  8848. /* cache hit */
  8849. /* DTLS accesses cache once for stateless parsing and
  8850. * once for stateful parsing */
  8851. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8852. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8853. #else
  8854. ExpectIntEQ(twcase_get_session_called, 1);
  8855. #endif
  8856. ExpectIntEQ(twcase_new_session_called, 0);
  8857. /* Called on session added in
  8858. * twcase_server_sess_ctx_pre_shutdown */
  8859. ExpectIntEQ(twcase_remove_session_called, 1);
  8860. }
  8861. break;
  8862. case 2:
  8863. if (tls13) {
  8864. /* (D)TLSv1.3 case */
  8865. /* cache hit */
  8866. ExpectIntEQ(twcase_get_session_called, 1);
  8867. /* (D)TLSv1.3 creates a new ticket,
  8868. * updates both internal and external cache */
  8869. ExpectIntEQ(twcase_new_session_called, 1);
  8870. /* Called on session added in
  8871. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  8872. ExpectIntEQ(twcase_remove_session_called, 1);
  8873. }
  8874. else {
  8875. /* non (D)TLSv1.3 case */
  8876. /* cache hit */
  8877. /* DTLS accesses cache once for stateless parsing and
  8878. * once for stateful parsing */
  8879. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  8880. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  8881. #else
  8882. ExpectIntEQ(twcase_get_session_called, 1);
  8883. #endif
  8884. ExpectIntEQ(twcase_new_session_called, 0);
  8885. /* Called on session added in
  8886. * twcase_server_sess_ctx_pre_shutdown */
  8887. ExpectIntEQ(twcase_remove_session_called, 1);
  8888. }
  8889. break;
  8890. case 3:
  8891. case 4:
  8892. /* no external cache */
  8893. ExpectIntEQ(twcase_get_session_called, 0);
  8894. ExpectIntEQ(twcase_new_session_called, 0);
  8895. ExpectIntEQ(twcase_remove_session_called, 0);
  8896. break;
  8897. }
  8898. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8899. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8900. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8901. if (EXPECT_FAIL())
  8902. break;
  8903. }
  8904. twcase_get_sessionCb_cleanup();
  8905. XMEMSET(&server_sessionCache.entries, 0,
  8906. sizeof(server_sessionCache.entries));
  8907. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  8908. wc_FreeMutex(&server_sessionCache.htLock);
  8909. return EXPECT_RESULT();
  8910. }
  8911. #endif
  8912. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  8913. {
  8914. EXPECT_DECLS;
  8915. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8916. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8917. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8918. defined(HAVE_SESSION_TICKET) && \
  8919. !defined(TITAN_SESSION_CACHE) && \
  8920. !defined(HUGE_SESSION_CACHE) && \
  8921. !defined(BIG_SESSION_CACHE) && \
  8922. !defined(MEDIUM_SESSION_CACHE)
  8923. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8924. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  8925. struct test_add_session_ext_params param[1] = {
  8926. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  8927. };
  8928. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8929. #endif
  8930. #endif
  8931. return EXPECT_RESULT();
  8932. }
  8933. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  8934. {
  8935. EXPECT_DECLS;
  8936. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8937. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8938. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8939. defined(HAVE_SESSION_TICKET) && \
  8940. !defined(TITAN_SESSION_CACHE) && \
  8941. !defined(HUGE_SESSION_CACHE) && \
  8942. !defined(BIG_SESSION_CACHE) && \
  8943. !defined(MEDIUM_SESSION_CACHE)
  8944. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8945. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  8946. #ifdef WOLFSSL_DTLS13
  8947. struct test_add_session_ext_params param[1] = {
  8948. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  8949. };
  8950. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8951. #endif
  8952. #endif
  8953. #endif
  8954. return EXPECT_RESULT();
  8955. }
  8956. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  8957. {
  8958. EXPECT_DECLS;
  8959. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8960. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8961. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8962. defined(HAVE_SESSION_TICKET) && \
  8963. !defined(TITAN_SESSION_CACHE) && \
  8964. !defined(HUGE_SESSION_CACHE) && \
  8965. !defined(BIG_SESSION_CACHE) && \
  8966. !defined(MEDIUM_SESSION_CACHE)
  8967. #ifndef WOLFSSL_NO_TLS12
  8968. struct test_add_session_ext_params param[1] = {
  8969. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  8970. };
  8971. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8972. #endif
  8973. #endif
  8974. return EXPECT_RESULT();
  8975. }
  8976. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  8977. {
  8978. EXPECT_DECLS;
  8979. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8980. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8981. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8982. defined(HAVE_SESSION_TICKET) && \
  8983. !defined(TITAN_SESSION_CACHE) && \
  8984. !defined(HUGE_SESSION_CACHE) && \
  8985. !defined(BIG_SESSION_CACHE) && \
  8986. !defined(MEDIUM_SESSION_CACHE)
  8987. #ifndef WOLFSSL_NO_TLS12
  8988. #ifdef WOLFSSL_DTLS
  8989. struct test_add_session_ext_params param[1] = {
  8990. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  8991. };
  8992. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  8993. #endif
  8994. #endif
  8995. #endif
  8996. return EXPECT_RESULT();
  8997. }
  8998. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  8999. {
  9000. EXPECT_DECLS;
  9001. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9002. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9003. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9004. defined(HAVE_SESSION_TICKET) && \
  9005. !defined(TITAN_SESSION_CACHE) && \
  9006. !defined(HUGE_SESSION_CACHE) && \
  9007. !defined(BIG_SESSION_CACHE) && \
  9008. !defined(MEDIUM_SESSION_CACHE)
  9009. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9010. !defined(NO_DES3))
  9011. struct test_add_session_ext_params param[1] = {
  9012. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9013. };
  9014. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9015. #endif
  9016. #endif
  9017. return EXPECT_RESULT();
  9018. }
  9019. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9020. {
  9021. EXPECT_DECLS;
  9022. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9023. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9024. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9025. defined(HAVE_SESSION_TICKET) && \
  9026. !defined(TITAN_SESSION_CACHE) && \
  9027. !defined(HUGE_SESSION_CACHE) && \
  9028. !defined(BIG_SESSION_CACHE) && \
  9029. !defined(MEDIUM_SESSION_CACHE)
  9030. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9031. !defined(NO_DES3))
  9032. #ifdef WOLFSSL_DTLS
  9033. struct test_add_session_ext_params param[1] = {
  9034. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9035. };
  9036. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9037. #endif
  9038. #endif
  9039. #endif
  9040. return EXPECT_RESULT();
  9041. }
  9042. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9043. /* canned export of a session using older version 3 */
  9044. static unsigned char version_3[] = {
  9045. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9046. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9047. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9048. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9049. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9050. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9051. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9052. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9053. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9054. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9055. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9056. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9057. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9058. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9059. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9060. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9061. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9062. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9063. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9064. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9065. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9066. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9067. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9068. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9069. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9070. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9071. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9072. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9073. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9074. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9075. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9076. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05,
  9077. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9078. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9079. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9080. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9081. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9082. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9083. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9084. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9085. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9086. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9087. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9088. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9089. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9090. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9091. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9092. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9093. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9094. 0x2E, 0x31, 0xED, 0x4F
  9095. };
  9096. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9097. static int test_wolfSSL_dtls_export(void)
  9098. {
  9099. EXPECT_DECLS;
  9100. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9101. tcp_ready ready;
  9102. func_args client_args;
  9103. func_args server_args;
  9104. THREAD_TYPE serverThread;
  9105. callback_functions server_cbf;
  9106. callback_functions client_cbf;
  9107. #ifdef WOLFSSL_TIRTOS
  9108. fdOpenSession(Task_self());
  9109. #endif
  9110. InitTcpReady(&ready);
  9111. #if defined(USE_WINDOWS_API)
  9112. /* use RNG to get random port if using windows */
  9113. ready.port = GetRandomPort();
  9114. #endif
  9115. /* set using dtls */
  9116. XMEMSET(&client_args, 0, sizeof(func_args));
  9117. XMEMSET(&server_args, 0, sizeof(func_args));
  9118. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9119. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9120. server_cbf.method = wolfDTLSv1_2_server_method;
  9121. client_cbf.method = wolfDTLSv1_2_client_method;
  9122. server_args.callbacks = &server_cbf;
  9123. client_args.callbacks = &client_cbf;
  9124. server_args.signal = &ready;
  9125. client_args.signal = &ready;
  9126. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9127. wait_tcp_ready(&server_args);
  9128. run_wolfssl_client(&client_args);
  9129. join_thread(serverThread);
  9130. ExpectTrue(client_args.return_code);
  9131. ExpectTrue(server_args.return_code);
  9132. FreeTcpReady(&ready);
  9133. #ifdef WOLFSSL_TIRTOS
  9134. fdOpenSession(Task_self());
  9135. #endif
  9136. if (EXPECT_SUCCESS()) {
  9137. SOCKET_T sockfd = 0;
  9138. WOLFSSL_CTX* ctx = NULL;
  9139. WOLFSSL* ssl = NULL;
  9140. char msg[64] = "hello wolfssl!";
  9141. char reply[1024];
  9142. int msgSz = (int)XSTRLEN(msg);
  9143. byte *session, *window;
  9144. unsigned int sessionSz = 0;
  9145. unsigned int windowSz = 0;
  9146. #ifndef TEST_IPV6
  9147. struct sockaddr_in peerAddr;
  9148. #else
  9149. struct sockaddr_in6 peerAddr;
  9150. #endif /* TEST_IPV6 */
  9151. int i;
  9152. /* Set ctx to DTLS 1.2 */
  9153. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9154. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9155. /* test importing version 3 */
  9156. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9157. /* test importing bad length and bad version */
  9158. version_3[2] += 1;
  9159. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9160. version_3[2] -= 1; version_3[1] = 0XA0;
  9161. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9162. wolfSSL_free(ssl);
  9163. wolfSSL_CTX_free(ctx);
  9164. /* check storing client state after connection and storing window only */
  9165. #ifdef WOLFSSL_TIRTOS
  9166. fdOpenSession(Task_self());
  9167. #endif
  9168. InitTcpReady(&ready);
  9169. #if defined(USE_WINDOWS_API)
  9170. /* use RNG to get random port if using windows */
  9171. ready.port = GetRandomPort();
  9172. #endif
  9173. /* set using dtls */
  9174. XMEMSET(&server_args, 0, sizeof(func_args));
  9175. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9176. server_cbf.method = wolfDTLSv1_2_server_method;
  9177. server_cbf.doUdp = 1;
  9178. server_args.callbacks = &server_cbf;
  9179. server_args.argc = 3; /* set loop_count to 3 */
  9180. server_args.signal = &ready;
  9181. start_thread(test_server_nofail, &server_args, &serverThread);
  9182. wait_tcp_ready(&server_args);
  9183. /* create and connect with client */
  9184. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9185. ExpectIntEQ(WOLFSSL_SUCCESS,
  9186. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9187. ExpectIntEQ(WOLFSSL_SUCCESS,
  9188. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9189. ExpectIntEQ(WOLFSSL_SUCCESS,
  9190. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9191. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9192. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9193. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9194. /* store server information connected too */
  9195. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9196. #ifndef TEST_IPV6
  9197. peerAddr.sin_family = AF_INET;
  9198. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9199. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9200. #else
  9201. peerAddr.sin6_family = AF_INET6;
  9202. ExpectIntEQ(
  9203. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9204. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9205. #endif
  9206. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9207. WOLFSSL_SUCCESS);
  9208. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9209. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9210. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9211. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9212. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9213. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9214. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9215. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9216. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9217. wolfSSL_free(ssl);
  9218. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9219. /* restore state */
  9220. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9221. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9222. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9223. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9224. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9225. WOLFSSL_SUCCESS);
  9226. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9227. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9228. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9229. wolfSSL_free(ssl);
  9230. }
  9231. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9232. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9233. wolfSSL_CTX_free(ctx);
  9234. fprintf(stderr, "done and waiting for server\n");
  9235. join_thread(serverThread);
  9236. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9237. FreeTcpReady(&ready);
  9238. #ifdef WOLFSSL_TIRTOS
  9239. fdOpenSession(Task_self());
  9240. #endif
  9241. }
  9242. #endif
  9243. return EXPECT_RESULT();
  9244. }
  9245. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9246. #ifdef WOLFSSL_TLS13
  9247. static const byte canned_client_tls13_session[] = {
  9248. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9249. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9250. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9251. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9252. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9253. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9254. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9255. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9256. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9257. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9258. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9259. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9260. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9261. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9262. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9263. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9264. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9265. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9266. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9267. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9268. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9269. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9270. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9271. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9272. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9273. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9274. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9275. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9277. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9278. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9279. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9280. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9281. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9282. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9283. 0x00, 0x03
  9284. };
  9285. static const byte canned_server_tls13_session[] = {
  9286. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9287. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9288. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9289. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9292. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9293. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9294. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9295. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9296. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9297. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9298. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9299. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9300. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9301. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9302. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9303. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9304. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9305. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9306. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9307. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9308. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9309. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9310. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9311. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9312. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9313. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9314. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9315. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9316. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9317. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9318. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9319. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9320. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9321. 0x00, 0x04
  9322. };
  9323. #endif /* WOLFSSL_TLS13 */
  9324. static const byte canned_client_session[] = {
  9325. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9326. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9327. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9328. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9329. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9330. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9331. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9332. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9333. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9334. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9335. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9336. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9337. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9338. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9339. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9340. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9341. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9342. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9343. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9344. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9345. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9346. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9347. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9348. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9349. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9350. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9351. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9352. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9353. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9354. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9355. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9356. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9358. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9359. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9360. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9361. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9362. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9363. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9364. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9365. 0x00, 0x03
  9366. };
  9367. static const byte canned_server_session[] = {
  9368. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9369. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9370. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9371. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9372. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9373. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9374. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9375. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9376. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9377. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9378. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9379. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9380. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9381. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9382. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9383. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9384. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9385. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9386. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9387. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9388. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9389. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9390. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9391. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9392. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9393. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9394. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9395. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9396. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9397. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9401. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9402. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9403. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9404. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9405. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9406. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9407. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9408. 0x00, 0x04
  9409. };
  9410. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9411. {
  9412. SOCKET_T sockfd = 0;
  9413. SOCKET_T clientfd = 0;
  9414. word16 port;
  9415. callback_functions* cbf;
  9416. WOLFSSL_CTX* ctx = 0;
  9417. WOLFSSL* ssl = 0;
  9418. char msg[] = "I hear you fa shizzle!";
  9419. char input[1024];
  9420. int idx;
  9421. #ifdef WOLFSSL_TIRTOS
  9422. fdOpenSession(Task_self());
  9423. #endif
  9424. ((func_args*)args)->return_code = TEST_FAIL;
  9425. cbf = ((func_args*)args)->callbacks;
  9426. #if defined(USE_WINDOWS_API)
  9427. port = ((func_args*)args)->signal->port;
  9428. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9429. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9430. /* Let tcp_listen assign port */
  9431. port = 0;
  9432. #else
  9433. /* Use default port */
  9434. port = wolfSSLPort;
  9435. #endif
  9436. /* do it here to detect failure */
  9437. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9438. CloseSocket(sockfd);
  9439. {
  9440. WOLFSSL_METHOD* method = NULL;
  9441. if (cbf != NULL && cbf->method != NULL) {
  9442. method = cbf->method();
  9443. }
  9444. else {
  9445. method = wolfTLSv1_2_server_method();
  9446. }
  9447. ctx = wolfSSL_CTX_new(method);
  9448. }
  9449. if (ctx == NULL) {
  9450. goto done;
  9451. }
  9452. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9453. /* call ctx setup callback */
  9454. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9455. cbf->ctx_ready(ctx);
  9456. }
  9457. ssl = wolfSSL_new(ctx);
  9458. if (ssl == NULL) {
  9459. goto done;
  9460. }
  9461. wolfSSL_set_fd(ssl, clientfd);
  9462. /* call ssl setup callback */
  9463. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9464. cbf->ssl_ready(ssl);
  9465. }
  9466. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9467. if (idx > 0) {
  9468. input[idx] = '\0';
  9469. fprintf(stderr, "Client message export/import: %s\n", input);
  9470. }
  9471. else {
  9472. fprintf(stderr, "ret = %d error = %d\n", idx,
  9473. wolfSSL_get_error(ssl, idx));
  9474. goto done;
  9475. }
  9476. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9477. /*err_sys("SSL_write failed");*/
  9478. WOLFSSL_RETURN_FROM_THREAD(0);
  9479. }
  9480. #ifdef WOLFSSL_TIRTOS
  9481. Task_yield();
  9482. #endif
  9483. ((func_args*)args)->return_code = TEST_SUCCESS;
  9484. done:
  9485. wolfSSL_shutdown(ssl);
  9486. wolfSSL_free(ssl);
  9487. wolfSSL_CTX_free(ctx);
  9488. CloseSocket(clientfd);
  9489. #ifdef WOLFSSL_TIRTOS
  9490. fdCloseSession(Task_self());
  9491. #endif
  9492. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9493. && defined(HAVE_THREAD_LS)
  9494. wc_ecc_fp_free(); /* free per thread cache */
  9495. #endif
  9496. #if defined(HAVE_SESSION_TICKET) && \
  9497. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9498. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9499. OpenSSLTicketCleanup();
  9500. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9501. TicketCleanup();
  9502. #endif
  9503. #endif
  9504. WOLFSSL_RETURN_FROM_THREAD(0);
  9505. }
  9506. static void load_tls12_canned_server(WOLFSSL* ssl)
  9507. {
  9508. int clientfd = wolfSSL_get_fd(ssl);
  9509. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9510. sizeof(canned_server_session)), sizeof(canned_server_session));
  9511. wolfSSL_set_fd(ssl, clientfd);
  9512. }
  9513. #ifdef WOLFSSL_TLS13
  9514. static void load_tls13_canned_server(WOLFSSL* ssl)
  9515. {
  9516. int clientfd = wolfSSL_get_fd(ssl);
  9517. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9518. sizeof(canned_server_tls13_session)),
  9519. sizeof(canned_server_tls13_session));
  9520. wolfSSL_set_fd(ssl, clientfd);
  9521. }
  9522. #endif
  9523. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9524. static int test_wolfSSL_tls_export_run(int v)
  9525. {
  9526. EXPECT_DECLS;
  9527. SOCKET_T sockfd = 0;
  9528. WOLFSSL_CTX* ctx = 0;
  9529. WOLFSSL* ssl = 0;
  9530. char msg[64] = "hello wolfssl!";
  9531. char reply[1024];
  9532. word32 replySz;
  9533. int msgSz = (int)XSTRLEN(msg);
  9534. const byte* clientSession = NULL;
  9535. int clientSessionSz = 0;
  9536. tcp_ready ready;
  9537. func_args server_args;
  9538. THREAD_TYPE serverThread;
  9539. callback_functions server_cbf;
  9540. #ifdef WOLFSSL_TIRTOS
  9541. fdOpenSession(Task_self());
  9542. #endif
  9543. InitTcpReady(&ready);
  9544. #if defined(USE_WINDOWS_API)
  9545. /* use RNG to get random port if using windows */
  9546. ready.port = GetRandomPort();
  9547. #endif
  9548. XMEMSET(&server_args, 0, sizeof(func_args));
  9549. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9550. switch (v) {
  9551. case WOLFSSL_TLSV1_2:
  9552. server_cbf.method = wolfTLSv1_2_server_method;
  9553. server_cbf.ssl_ready = load_tls12_canned_server;
  9554. /* setup the client side */
  9555. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9556. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9557. clientSession = canned_client_session;
  9558. clientSessionSz = sizeof(canned_client_session);
  9559. break;
  9560. #ifdef WOLFSSL_TLS13
  9561. case WOLFSSL_TLSV1_3:
  9562. server_cbf.method = wolfTLSv1_3_server_method;
  9563. server_cbf.ssl_ready = load_tls13_canned_server;
  9564. /* setup the client side */
  9565. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9566. clientSession = canned_client_tls13_session;
  9567. clientSessionSz = sizeof(canned_client_tls13_session);
  9568. break;
  9569. #endif
  9570. }
  9571. server_args.callbacks = &server_cbf;
  9572. server_args.signal = &ready;
  9573. start_thread(tls_export_server, &server_args, &serverThread);
  9574. wait_tcp_ready(&server_args);
  9575. #ifdef WOLFSSL_TIRTOS
  9576. fdOpenSession(Task_self());
  9577. #endif
  9578. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9579. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9580. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9581. clientSessionSz);
  9582. replySz = sizeof(reply);
  9583. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9584. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9585. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9586. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9587. #endif
  9588. wolfSSL_set_fd(ssl, sockfd);
  9589. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9590. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9591. wolfSSL_free(ssl);
  9592. wolfSSL_CTX_free(ctx);
  9593. CloseSocket(sockfd);
  9594. #ifdef WOLFSSL_TIRTOS
  9595. fdCloseSession(Task_self());
  9596. #endif
  9597. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9598. && defined(HAVE_THREAD_LS)
  9599. wc_ecc_fp_free(); /* free per thread cache */
  9600. #endif
  9601. join_thread(serverThread);
  9602. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9603. FreeTcpReady(&ready);
  9604. #ifdef WOLFSSL_TIRTOS
  9605. fdOpenSession(Task_self());
  9606. #endif
  9607. return EXPECT_RESULT();
  9608. }
  9609. #endif
  9610. static int test_wolfSSL_tls_export(void)
  9611. {
  9612. int res = TEST_SKIPPED;
  9613. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9614. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9615. #ifdef WOLFSSL_TLS13
  9616. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9617. #endif
  9618. res = TEST_RES_CHECK(1);
  9619. #endif
  9620. return res;
  9621. }
  9622. /*----------------------------------------------------------------------------*
  9623. | TLS extensions tests
  9624. *----------------------------------------------------------------------------*/
  9625. #ifdef ENABLE_TLS_CALLBACK_TEST
  9626. /* Connection test runner - generic */
  9627. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9628. callback_functions* server_callbacks)
  9629. {
  9630. tcp_ready ready;
  9631. func_args client_args;
  9632. func_args server_args;
  9633. THREAD_TYPE serverThread;
  9634. XMEMSET(&client_args, 0, sizeof(func_args));
  9635. XMEMSET(&server_args, 0, sizeof(func_args));
  9636. StartTCP();
  9637. client_args.callbacks = client_callbacks;
  9638. server_args.callbacks = server_callbacks;
  9639. #ifdef WOLFSSL_TIRTOS
  9640. fdOpenSession(Task_self());
  9641. #endif
  9642. /* RUN Server side */
  9643. InitTcpReady(&ready);
  9644. #if defined(USE_WINDOWS_API)
  9645. /* use RNG to get random port if using windows */
  9646. ready.port = GetRandomPort();
  9647. #endif
  9648. server_args.signal = &ready;
  9649. client_args.signal = &ready;
  9650. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9651. wait_tcp_ready(&server_args);
  9652. /* RUN Client side */
  9653. run_wolfssl_client(&client_args);
  9654. join_thread(serverThread);
  9655. FreeTcpReady(&ready);
  9656. #ifdef WOLFSSL_TIRTOS
  9657. fdCloseSession(Task_self());
  9658. #endif
  9659. client_callbacks->return_code = client_args.return_code;
  9660. server_callbacks->return_code = server_args.return_code;
  9661. }
  9662. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9663. #ifdef HAVE_SNI
  9664. static int test_wolfSSL_UseSNI_params(void)
  9665. {
  9666. EXPECT_DECLS;
  9667. #if !defined(NO_WOLFSSL_CLIENT)
  9668. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9669. WOLFSSL *ssl = wolfSSL_new(ctx);
  9670. ExpectNotNull(ctx);
  9671. ExpectNotNull(ssl);
  9672. /* invalid [ctx|ssl] */
  9673. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9674. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9675. /* invalid type */
  9676. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, -1, "ctx", 3));
  9677. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, -1, "ssl", 3));
  9678. /* invalid data */
  9679. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9680. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9681. /* success case */
  9682. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9683. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9684. wolfSSL_free(ssl);
  9685. wolfSSL_CTX_free(ctx);
  9686. #endif /* !NO_WOLFSSL_CLIENT */
  9687. return EXPECT_RESULT();
  9688. }
  9689. /* BEGIN of connection tests callbacks */
  9690. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9691. {
  9692. AssertIntEQ(WOLFSSL_SUCCESS,
  9693. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9694. }
  9695. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9696. {
  9697. AssertIntEQ(WOLFSSL_SUCCESS,
  9698. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9699. }
  9700. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9701. {
  9702. AssertIntEQ(WOLFSSL_SUCCESS,
  9703. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9704. }
  9705. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9706. {
  9707. use_SNI_at_ssl(ssl);
  9708. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9709. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9710. }
  9711. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9712. {
  9713. use_SNI_at_ssl(ssl);
  9714. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9715. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9716. }
  9717. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9718. {
  9719. use_SNI_at_ctx(ctx);
  9720. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9721. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9722. }
  9723. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9724. {
  9725. use_SNI_at_ssl(ssl);
  9726. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9727. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9728. }
  9729. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9730. {
  9731. use_SNI_at_ctx(ctx);
  9732. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9733. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9734. }
  9735. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9736. {
  9737. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9738. wolfSSL_get_error(ssl, 0));
  9739. }
  9740. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9741. {
  9742. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9743. }
  9744. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9745. {
  9746. byte type = WOLFSSL_SNI_HOST_NAME;
  9747. void* request = (void*) &type; /* to be overwritten */
  9748. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9749. AssertNotNull(request);
  9750. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9751. AssertNull(request);
  9752. }
  9753. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9754. {
  9755. byte type = WOLFSSL_SNI_HOST_NAME;
  9756. void* request = NULL;
  9757. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9758. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9759. AssertNotNull(request);
  9760. AssertStrEQ("www.wolfssl.com", (char*)request);
  9761. }
  9762. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9763. {
  9764. byte type = WOLFSSL_SNI_HOST_NAME;
  9765. void* request = NULL;
  9766. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9767. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9768. AssertNotNull(request);
  9769. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9770. }
  9771. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9772. {
  9773. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9774. }
  9775. /* END of connection tests callbacks */
  9776. static int test_wolfSSL_UseSNI_connection(void)
  9777. {
  9778. int res = TEST_SKIPPED;
  9779. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  9780. callback_functions client_cb;
  9781. callback_functions server_cb;
  9782. size_t i;
  9783. #ifdef WOLFSSL_STATIC_MEMORY
  9784. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  9785. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  9786. #endif
  9787. struct {
  9788. method_provider client_meth;
  9789. method_provider server_meth;
  9790. #ifdef WOLFSSL_STATIC_MEMORY
  9791. wolfSSL_method_func client_meth_ex;
  9792. wolfSSL_method_func server_meth_ex;
  9793. #endif
  9794. } methods[] = {
  9795. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  9796. {wolfSSLv23_client_method, wolfSSLv23_server_method
  9797. #ifdef WOLFSSL_STATIC_MEMORY
  9798. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  9799. #endif
  9800. },
  9801. #endif
  9802. #ifndef WOLFSSL_NO_TLS12
  9803. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  9804. #ifdef WOLFSSL_STATIC_MEMORY
  9805. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  9806. #endif
  9807. },
  9808. #endif
  9809. #ifdef WOLFSSL_TLS13
  9810. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  9811. #ifdef WOLFSSL_STATIC_MEMORY
  9812. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  9813. #endif
  9814. },
  9815. #endif
  9816. };
  9817. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  9818. for (i = 0; i < methodsSz; i++) {
  9819. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  9820. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  9821. client_cb.method = methods[i].client_meth;
  9822. server_cb.method = methods[i].server_meth;
  9823. client_cb.devId = testDevId;
  9824. server_cb.devId = testDevId;
  9825. #ifdef WOLFSSL_STATIC_MEMORY
  9826. client_cb.method_ex = methods[i].client_meth_ex;
  9827. server_cb.method_ex = methods[i].server_meth_ex;
  9828. client_cb.mem = cliMem;
  9829. client_cb.memSz = (word32)sizeof(cliMem);
  9830. server_cb.mem = svrMem;
  9831. server_cb.memSz = (word32)sizeof(svrMem);;
  9832. #endif
  9833. /* success case at ctx */
  9834. fprintf(stderr, "\n\tsuccess case at ctx\n");
  9835. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9836. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  9837. test_wolfSSL_client_server(&client_cb, &server_cb);
  9838. /* success case at ssl */
  9839. fprintf(stderr, "\tsuccess case at ssl\n");
  9840. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  9841. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  9842. test_wolfSSL_client_server(&client_cb, &server_cb);
  9843. /* default mismatch behavior */
  9844. fprintf(stderr, "\tdefault mismatch behavior\n");
  9845. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9846. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  9847. test_wolfSSL_client_server(&client_cb, &server_cb);
  9848. /* continue on mismatch */
  9849. fprintf(stderr, "\tcontinue on mismatch\n");
  9850. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9851. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  9852. test_wolfSSL_client_server(&client_cb, &server_cb);
  9853. /* fake answer on mismatch */
  9854. fprintf(stderr, "\tfake answer on mismatch\n");
  9855. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9856. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  9857. test_wolfSSL_client_server(&client_cb, &server_cb);
  9858. /* sni abort - success */
  9859. fprintf(stderr, "\tsni abort - success\n");
  9860. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9861. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  9862. test_wolfSSL_client_server(&client_cb, &server_cb);
  9863. /* sni abort - abort when absent (ctx) */
  9864. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  9865. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9866. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  9867. test_wolfSSL_client_server(&client_cb, &server_cb);
  9868. /* sni abort - abort when absent (ssl) */
  9869. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  9870. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  9871. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  9872. test_wolfSSL_client_server(&client_cb, &server_cb);
  9873. /* sni abort - success when overwritten */
  9874. fprintf(stderr, "\tsni abort - success when overwritten\n");
  9875. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  9876. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  9877. test_wolfSSL_client_server(&client_cb, &server_cb);
  9878. /* sni abort - success when allowing mismatches */
  9879. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  9880. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  9881. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  9882. test_wolfSSL_client_server(&client_cb, &server_cb);
  9883. }
  9884. res = TEST_RES_CHECK(1);
  9885. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  9886. return res;
  9887. }
  9888. static int test_wolfSSL_SNI_GetFromBuffer(void)
  9889. {
  9890. EXPECT_DECLS;
  9891. byte buff[] = { /* www.paypal.com */
  9892. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  9893. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  9894. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  9895. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  9896. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  9897. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  9898. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  9899. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  9900. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  9901. };
  9902. byte buff2[] = { /* api.textmate.org */
  9903. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  9904. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  9905. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  9906. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  9907. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  9908. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  9909. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  9910. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  9911. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  9912. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  9913. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  9914. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  9915. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  9916. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  9917. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  9918. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  9919. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  9920. };
  9921. byte buff3[] = { /* no sni extension */
  9922. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  9923. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  9924. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  9925. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  9926. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  9927. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  9928. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  9929. };
  9930. byte buff4[] = { /* last extension has zero size */
  9931. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  9932. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  9933. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  9934. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  9935. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  9936. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  9937. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  9938. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  9939. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  9940. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  9941. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  9942. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  9943. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  9944. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  9945. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  9946. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  9947. 0x12, 0x00, 0x00
  9948. };
  9949. byte buff5[] = { /* SSL v2.0 client hello */
  9950. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  9951. /* dummy bytes below, just to pass size check */
  9952. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  9953. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  9954. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  9955. };
  9956. byte result[32] = {0};
  9957. word32 length = 32;
  9958. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  9959. 0, result, &length));
  9960. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  9961. 0, result, &length));
  9962. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  9963. 1, result, &length));
  9964. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9965. 0, result, &length));
  9966. buff[0] = 0x16;
  9967. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9968. 0, result, &length));
  9969. buff[1] = 0x03;
  9970. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  9971. sizeof(buff), 0, result, &length));
  9972. buff[2] = 0x03;
  9973. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  9974. sizeof(buff), 0, result, &length));
  9975. buff[4] = 0x64;
  9976. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  9977. 0, result, &length));
  9978. if (EXPECT_SUCCESS())
  9979. result[length] = 0;
  9980. ExpectStrEQ("www.paypal.com", (const char*) result);
  9981. length = 32;
  9982. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  9983. 0, result, &length));
  9984. if (EXPECT_SUCCESS())
  9985. result[length] = 0;
  9986. ExpectStrEQ("api.textmate.org", (const char*) result);
  9987. /* SSL v2.0 tests */
  9988. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  9989. sizeof(buff5), 0, result, &length));
  9990. buff5[2] = 0x02;
  9991. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9992. sizeof(buff5), 0, result, &length));
  9993. buff5[2] = 0x01; buff5[6] = 0x08;
  9994. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9995. sizeof(buff5), 0, result, &length));
  9996. buff5[6] = 0x09; buff5[8] = 0x01;
  9997. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  9998. sizeof(buff5), 0, result, &length));
  9999. return EXPECT_RESULT();
  10000. }
  10001. #endif /* HAVE_SNI */
  10002. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10003. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10004. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10005. /* Dummy peer functions to satisfy the exporter/importer */
  10006. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10007. int* ipSz, unsigned short* port, int* fam)
  10008. {
  10009. (void)ssl;
  10010. ip[0] = -1;
  10011. *ipSz = 1;
  10012. *port = 1;
  10013. *fam = 2;
  10014. return 1;
  10015. }
  10016. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10017. int ipSz, unsigned short port, int fam)
  10018. {
  10019. (void)ssl;
  10020. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10021. return 0;
  10022. return 1;
  10023. }
  10024. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10025. WOLFSSL **ssl)
  10026. {
  10027. EXPECT_DECLS;
  10028. unsigned char* sessionBuf = NULL;
  10029. unsigned int sessionSz = 0;
  10030. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10031. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10032. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10033. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10034. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10035. ExpectNotNull(sessionBuf =
  10036. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10037. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10038. wolfSSL_free(*ssl);
  10039. *ssl = NULL;
  10040. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10041. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10042. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10043. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10044. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10045. return EXPECT_RESULT();
  10046. }
  10047. #endif
  10048. static int test_wolfSSL_dtls_export_peers(void)
  10049. {
  10050. EXPECT_DECLS;
  10051. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10052. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10053. test_ssl_cbf client_cbf;
  10054. test_ssl_cbf server_cbf;
  10055. size_t i, j;
  10056. struct test_params {
  10057. method_provider client_meth;
  10058. method_provider server_meth;
  10059. const char* dtls_version;
  10060. } params[] = {
  10061. #ifndef NO_OLD_TLS
  10062. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10063. #endif
  10064. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10065. /* TODO DTLS 1.3 exporting not supported
  10066. #ifdef WOLFSSL_DTLS13
  10067. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10068. #endif
  10069. */
  10070. };
  10071. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10072. for (j = 0; j <= 0b11; j++) {
  10073. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10074. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10075. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10076. client_cbf.method = params[i].client_meth;
  10077. server_cbf.method = params[i].server_meth;
  10078. if (j & 0b01) {
  10079. client_cbf.on_handshake =
  10080. test_wolfSSL_dtls_export_peers_on_handshake;
  10081. printf(" With client export;");
  10082. }
  10083. if (j & 0b10) {
  10084. server_cbf.on_handshake =
  10085. test_wolfSSL_dtls_export_peers_on_handshake;
  10086. printf(" With server export;");
  10087. }
  10088. printf("\n");
  10089. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10090. &server_cbf, NULL), TEST_SUCCESS);
  10091. if (!EXPECT_SUCCESS())
  10092. break;
  10093. }
  10094. }
  10095. #endif
  10096. return EXPECT_RESULT();
  10097. }
  10098. static int test_wolfSSL_UseTrustedCA(void)
  10099. {
  10100. EXPECT_DECLS;
  10101. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10102. && !defined(NO_RSA)
  10103. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10104. WOLFSSL_CTX *ctx = NULL;
  10105. WOLFSSL *ssl = NULL;
  10106. byte id[20];
  10107. #ifndef NO_WOLFSSL_SERVER
  10108. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10109. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10110. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10111. #else
  10112. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10113. #endif
  10114. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10115. XMEMSET(id, 0, sizeof(id));
  10116. /* error cases */
  10117. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10118. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10119. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10120. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10121. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10122. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10123. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10124. #ifdef NO_SHA
  10125. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10126. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10127. #endif
  10128. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10129. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10130. /* success cases */
  10131. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10132. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10133. #ifndef NO_SHA
  10134. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10135. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10136. #endif
  10137. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10138. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10139. wolfSSL_free(ssl);
  10140. wolfSSL_CTX_free(ctx);
  10141. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10142. #endif /* HAVE_TRUSTED_CA */
  10143. return EXPECT_RESULT();
  10144. }
  10145. static int test_wolfSSL_UseMaxFragment(void)
  10146. {
  10147. EXPECT_DECLS;
  10148. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10149. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10150. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10151. #ifndef NO_WOLFSSL_SERVER
  10152. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10153. #else
  10154. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10155. #endif
  10156. WOLFSSL *ssl = NULL;
  10157. #ifdef OPENSSL_EXTRA
  10158. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10159. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10160. #else
  10161. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10162. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10163. #endif
  10164. #ifndef NO_WOLFSSL_SERVER
  10165. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10166. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10167. #endif
  10168. ExpectNotNull(ctx);
  10169. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10170. #ifdef OPENSSL_EXTRA
  10171. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10172. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10173. #else
  10174. UseMaxFragment = wolfSSL_UseMaxFragment;
  10175. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10176. #endif
  10177. /* error cases */
  10178. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10179. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10180. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10181. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10182. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10183. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10184. /* success case */
  10185. #ifdef OPENSSL_EXTRA
  10186. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10187. #else
  10188. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10189. #endif
  10190. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10191. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10192. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10193. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10194. #ifdef OPENSSL_EXTRA
  10195. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10196. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10197. #else
  10198. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10199. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10200. #endif
  10201. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10202. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10203. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10204. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10205. #ifdef OPENSSL_EXTRA
  10206. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10207. #else
  10208. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10209. #endif
  10210. wolfSSL_free(ssl);
  10211. wolfSSL_CTX_free(ctx);
  10212. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10213. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10214. /* check negotiated max fragment size */
  10215. {
  10216. WOLFSSL *ssl_c = NULL;
  10217. WOLFSSL *ssl_s = NULL;
  10218. struct test_memio_ctx test_ctx;
  10219. WOLFSSL_CTX *ctx_c = NULL;
  10220. WOLFSSL_CTX *ctx_s = NULL;
  10221. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10222. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10223. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10224. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10225. WOLFSSL_SUCCESS);
  10226. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10227. #ifndef NO_SESSION_CACHE
  10228. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10229. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10230. #endif
  10231. wolfSSL_free(ssl_c);
  10232. wolfSSL_free(ssl_s);
  10233. wolfSSL_CTX_free(ctx_c);
  10234. wolfSSL_CTX_free(ctx_s);
  10235. }
  10236. #endif
  10237. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10238. #endif
  10239. return EXPECT_RESULT();
  10240. }
  10241. static int test_wolfSSL_UseTruncatedHMAC(void)
  10242. {
  10243. EXPECT_DECLS;
  10244. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10245. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10246. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10247. #ifndef NO_WOLFSSL_SERVER
  10248. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10249. #else
  10250. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10251. #endif
  10252. WOLFSSL *ssl = NULL;
  10253. ExpectNotNull(ctx);
  10254. #ifndef NO_WOLFSSL_SERVER
  10255. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10256. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10257. #endif
  10258. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10259. /* error cases */
  10260. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10261. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10262. /* success case */
  10263. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10264. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10265. wolfSSL_free(ssl);
  10266. wolfSSL_CTX_free(ctx);
  10267. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10268. #endif
  10269. return EXPECT_RESULT();
  10270. }
  10271. static int test_wolfSSL_UseSupportedCurve(void)
  10272. {
  10273. EXPECT_DECLS;
  10274. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10275. !defined(NO_TLS)
  10276. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10277. WOLFSSL *ssl = wolfSSL_new(ctx);
  10278. ExpectNotNull(ctx);
  10279. ExpectNotNull(ssl);
  10280. /* error cases */
  10281. ExpectIntNE(WOLFSSL_SUCCESS,
  10282. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10283. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10284. ExpectIntNE(WOLFSSL_SUCCESS,
  10285. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10286. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10287. /* success case */
  10288. ExpectIntEQ(WOLFSSL_SUCCESS,
  10289. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10290. ExpectIntEQ(WOLFSSL_SUCCESS,
  10291. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10292. wolfSSL_free(ssl);
  10293. wolfSSL_CTX_free(ctx);
  10294. #endif
  10295. return EXPECT_RESULT();
  10296. }
  10297. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10298. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10299. {
  10300. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10301. }
  10302. static void use_ALPN_all(WOLFSSL* ssl)
  10303. {
  10304. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10305. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10306. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10307. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10308. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10309. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10310. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10311. }
  10312. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10313. {
  10314. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10315. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10316. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10317. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10318. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10319. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10320. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10321. }
  10322. static void use_ALPN_one(WOLFSSL* ssl)
  10323. {
  10324. /* spdy/2 */
  10325. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10326. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10327. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10328. }
  10329. static void use_ALPN_unknown(WOLFSSL* ssl)
  10330. {
  10331. /* http/2.0 */
  10332. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10333. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10334. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10335. }
  10336. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10337. {
  10338. /* http/2.0 */
  10339. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10340. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10341. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10342. }
  10343. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10344. {
  10345. /* spdy/3 */
  10346. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10347. char *proto = NULL;
  10348. word16 protoSz = 0;
  10349. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10350. /* check value */
  10351. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10352. if (proto) {
  10353. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10354. }
  10355. }
  10356. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10357. {
  10358. char *proto = NULL;
  10359. word16 protoSz = 0;
  10360. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10361. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10362. /* check value */
  10363. AssertIntEQ(1, (0 == protoSz));
  10364. AssertIntEQ(1, (NULL == proto));
  10365. }
  10366. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10367. {
  10368. /* http/1.1 */
  10369. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10370. char *proto;
  10371. word16 protoSz = 0;
  10372. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10373. /* check value */
  10374. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10375. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10376. }
  10377. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10378. {
  10379. /* spdy/2 */
  10380. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10381. char *proto;
  10382. word16 protoSz = 0;
  10383. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10384. /* check value */
  10385. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10386. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10387. }
  10388. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10389. {
  10390. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10391. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10392. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10393. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10394. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10395. char *clist = NULL;
  10396. word16 clistSz = 0;
  10397. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10398. &clistSz));
  10399. /* check value */
  10400. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10401. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10402. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10403. }
  10404. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10405. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10406. /* ALPN select callback, success with spdy/2 */
  10407. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10408. unsigned char *outlen, const unsigned char *in,
  10409. unsigned int inlen, void *arg)
  10410. {
  10411. /* spdy/2 */
  10412. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10413. (void)ssl;
  10414. (void)arg;
  10415. /* adding +1 since LEN byte comes first */
  10416. if (inlen < sizeof(proto) + 1) {
  10417. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10418. }
  10419. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10420. *out = in + 1;
  10421. *outlen = (unsigned char)sizeof(proto);
  10422. return SSL_TLSEXT_ERR_OK;
  10423. }
  10424. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10425. }
  10426. /* ALPN select callback, force failure */
  10427. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10428. unsigned char *outlen, const unsigned char *in,
  10429. unsigned int inlen, void *arg)
  10430. {
  10431. (void)ssl;
  10432. (void)out;
  10433. (void)outlen;
  10434. (void)in;
  10435. (void)inlen;
  10436. (void)arg;
  10437. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10438. }
  10439. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10440. {
  10441. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10442. }
  10443. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10444. {
  10445. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10446. }
  10447. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10448. static int test_wolfSSL_UseALPN_connection(void)
  10449. {
  10450. int res = TEST_SKIPPED;
  10451. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10452. callback_functions client_cb;
  10453. callback_functions server_cb;
  10454. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10455. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10456. client_cb.method = wolfSSLv23_client_method;
  10457. server_cb.method = wolfSSLv23_server_method;
  10458. client_cb.devId = testDevId;
  10459. server_cb.devId = testDevId;
  10460. /* success case same list */
  10461. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10462. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10463. test_wolfSSL_client_server(&client_cb, &server_cb);
  10464. /* success case only one for server */
  10465. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10466. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10467. test_wolfSSL_client_server(&client_cb, &server_cb);
  10468. /* success case only one for client */
  10469. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10470. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10471. test_wolfSSL_client_server(&client_cb, &server_cb);
  10472. /* success case none for client */
  10473. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10474. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10475. test_wolfSSL_client_server(&client_cb, &server_cb);
  10476. /* success case mismatch behavior but option 'continue' set */
  10477. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10478. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10479. test_wolfSSL_client_server(&client_cb, &server_cb);
  10480. /* success case read protocol send by client */
  10481. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10482. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10483. test_wolfSSL_client_server(&client_cb, &server_cb);
  10484. /* mismatch behavior with same list
  10485. * the first and only this one must be taken */
  10486. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10487. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10488. test_wolfSSL_client_server(&client_cb, &server_cb);
  10489. /* default mismatch behavior */
  10490. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10491. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10492. test_wolfSSL_client_server(&client_cb, &server_cb);
  10493. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10494. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10495. /* WOLFSSL-level ALPN select callback tests */
  10496. /* Callback: success (one protocol, spdy/2) */
  10497. client_cb.ctx_ready = NULL;
  10498. client_cb.ssl_ready = use_ALPN_one;
  10499. client_cb.on_result = verify_ALPN_matching_spdy2;
  10500. server_cb.ctx_ready = NULL;
  10501. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10502. server_cb.on_result = verify_ALPN_matching_spdy2;
  10503. test_wolfSSL_client_server(&client_cb, &server_cb);
  10504. /* Callback: failure (one client protocol, spdy/2) */
  10505. client_cb.ctx_ready = NULL;
  10506. client_cb.ssl_ready = use_ALPN_one;
  10507. client_cb.on_result = NULL;
  10508. server_cb.ctx_ready = NULL;
  10509. server_cb.ssl_ready = use_ALPN_failure_callback;
  10510. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10511. test_wolfSSL_client_server(&client_cb, &server_cb);
  10512. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10513. res = TEST_RES_CHECK(1);
  10514. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10515. return res;
  10516. }
  10517. static int test_wolfSSL_UseALPN_params(void)
  10518. {
  10519. EXPECT_DECLS;
  10520. #ifndef NO_WOLFSSL_CLIENT
  10521. /* "http/1.1" */
  10522. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10523. /* "spdy/1" */
  10524. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10525. /* "spdy/2" */
  10526. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10527. /* "spdy/3" */
  10528. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10529. char buff[256];
  10530. word32 idx;
  10531. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10532. WOLFSSL *ssl = wolfSSL_new(ctx);
  10533. ExpectNotNull(ctx);
  10534. ExpectNotNull(ssl);
  10535. /* error cases */
  10536. ExpectIntNE(WOLFSSL_SUCCESS,
  10537. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10538. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10539. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10540. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10541. /* success case */
  10542. /* http1 only */
  10543. ExpectIntEQ(WOLFSSL_SUCCESS,
  10544. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10545. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10546. /* http1, spdy1 */
  10547. XMEMCPY(buff, http1, sizeof(http1));
  10548. idx = sizeof(http1);
  10549. buff[idx++] = ',';
  10550. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10551. idx += sizeof(spdy1);
  10552. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10553. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10554. /* http1, spdy2, spdy1 */
  10555. XMEMCPY(buff, http1, sizeof(http1));
  10556. idx = sizeof(http1);
  10557. buff[idx++] = ',';
  10558. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10559. idx += sizeof(spdy2);
  10560. buff[idx++] = ',';
  10561. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10562. idx += sizeof(spdy1);
  10563. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10564. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10565. /* spdy3, http1, spdy2, spdy1 */
  10566. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10567. idx = sizeof(spdy3);
  10568. buff[idx++] = ',';
  10569. XMEMCPY(buff+idx, http1, sizeof(http1));
  10570. idx += sizeof(http1);
  10571. buff[idx++] = ',';
  10572. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10573. idx += sizeof(spdy2);
  10574. buff[idx++] = ',';
  10575. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10576. idx += sizeof(spdy1);
  10577. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10578. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10579. wolfSSL_free(ssl);
  10580. wolfSSL_CTX_free(ctx);
  10581. #endif
  10582. return EXPECT_RESULT();
  10583. }
  10584. #endif /* HAVE_ALPN */
  10585. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10586. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10587. {
  10588. unsigned char p[] = {
  10589. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10590. 6, 's', 'p', 'd', 'y', '/', '2',
  10591. 6, 's', 'p', 'd', 'y', '/', '1',
  10592. };
  10593. unsigned char p_len = sizeof(p);
  10594. int ret;
  10595. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10596. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10597. AssertIntEQ(ret, 0);
  10598. #else
  10599. AssertIntEQ(ret, SSL_SUCCESS);
  10600. #endif
  10601. }
  10602. static void set_alpn_protos(SSL* ssl)
  10603. {
  10604. unsigned char p[] = {
  10605. 6, 's', 'p', 'd', 'y', '/', '3',
  10606. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10607. 6, 's', 'p', 'd', 'y', '/', '2',
  10608. 6, 's', 'p', 'd', 'y', '/', '1',
  10609. };
  10610. unsigned char p_len = sizeof(p);
  10611. int ret;
  10612. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10613. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10614. AssertIntEQ(ret, 0);
  10615. #else
  10616. AssertIntEQ(ret, SSL_SUCCESS);
  10617. #endif
  10618. }
  10619. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10620. {
  10621. /* "spdy/3" */
  10622. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10623. const unsigned char *proto;
  10624. unsigned int protoSz = 0;
  10625. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10626. /* check value */
  10627. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10628. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10629. }
  10630. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10631. {
  10632. /* "http/1.1" */
  10633. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10634. const unsigned char *proto;
  10635. unsigned int protoSz = 0;
  10636. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10637. /* check value */
  10638. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10639. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10640. }
  10641. static int test_wolfSSL_set_alpn_protos(void)
  10642. {
  10643. int res = TEST_SKIPPED;
  10644. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10645. callback_functions client_cb;
  10646. callback_functions server_cb;
  10647. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10648. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10649. client_cb.method = wolfSSLv23_client_method;
  10650. server_cb.method = wolfSSLv23_server_method;
  10651. client_cb.devId = testDevId;
  10652. server_cb.devId = testDevId;
  10653. /* use CTX_alpn_protos */
  10654. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10655. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10656. test_wolfSSL_client_server(&client_cb, &server_cb);
  10657. /* use set_alpn_protos */
  10658. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10659. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10660. test_wolfSSL_client_server(&client_cb, &server_cb);
  10661. res = TEST_SUCCESS;
  10662. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10663. return res;
  10664. }
  10665. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10666. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10667. {
  10668. EXPECT_DECLS;
  10669. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10670. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10671. WOLFSSL *ssl = wolfSSL_new(ctx);
  10672. ExpectNotNull(ctx);
  10673. ExpectNotNull(ssl);
  10674. /* error cases */
  10675. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10676. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10677. /* success cases */
  10678. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10679. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10680. wolfSSL_free(ssl);
  10681. wolfSSL_CTX_free(ctx);
  10682. #endif
  10683. return EXPECT_RESULT();
  10684. }
  10685. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10686. {
  10687. EXPECT_DECLS;
  10688. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10689. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10690. WOLFSSL *ssl = wolfSSL_new(ctx);
  10691. ExpectNotNull(ctx);
  10692. ExpectNotNull(ssl);
  10693. /* error cases */
  10694. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10695. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10696. /* success cases */
  10697. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10698. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10699. wolfSSL_free(ssl);
  10700. wolfSSL_CTX_free(ctx);
  10701. #endif
  10702. return EXPECT_RESULT();
  10703. }
  10704. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10705. static int test_wolfSSL_SCR_Reconnect(void)
  10706. {
  10707. EXPECT_DECLS;
  10708. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10709. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10710. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10711. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10712. struct test_memio_ctx test_ctx;
  10713. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10714. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10715. byte data;
  10716. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10717. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10718. test_ctx.s_ciphers =
  10719. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10720. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10721. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10722. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10723. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10724. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10725. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10726. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10727. /* WOLFSSL_FATAL_ERROR since it will block */
  10728. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10729. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10730. WOLFSSL_ERROR_WANT_READ);
  10731. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10732. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10733. WOLFSSL_ERROR_WANT_READ);
  10734. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10735. wolfSSL_free(ssl_c);
  10736. ssl_c = NULL;
  10737. wolfSSL_free(ssl_s);
  10738. ssl_s = NULL;
  10739. wolfSSL_CTX_free(ctx_c);
  10740. ctx_c = NULL;
  10741. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10742. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10743. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10744. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10745. wolfSSL_free(ssl_s);
  10746. wolfSSL_free(ssl_c);
  10747. wolfSSL_CTX_free(ctx_s);
  10748. wolfSSL_CTX_free(ctx_c);
  10749. #endif
  10750. return EXPECT_RESULT();
  10751. }
  10752. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10753. (!defined(NO_RSA) || defined(HAVE_ECC))
  10754. /* Called when writing. */
  10755. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10756. {
  10757. (void)ssl;
  10758. (void)buf;
  10759. (void)sz;
  10760. (void)ctx;
  10761. /* Force error return from wolfSSL_accept_TLSv13(). */
  10762. return WANT_WRITE;
  10763. }
  10764. /* Called when reading. */
  10765. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10766. {
  10767. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10768. int len = (int)msg->length;
  10769. (void)ssl;
  10770. (void)sz;
  10771. /* Pass back as much of message as will fit in buffer. */
  10772. if (len > sz)
  10773. len = sz;
  10774. XMEMCPY(buf, msg->buffer, len);
  10775. /* Move over returned data. */
  10776. msg->buffer += len;
  10777. msg->length -= len;
  10778. /* Amount actually copied. */
  10779. return len;
  10780. }
  10781. #endif
  10782. /* Test the detection of duplicate known TLS extensions.
  10783. * Specifically in a ClientHello.
  10784. */
  10785. static int test_tls_ext_duplicate(void)
  10786. {
  10787. EXPECT_DECLS;
  10788. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  10789. !defined(NO_FILESYSTEM)
  10790. const unsigned char clientHelloDupTlsExt[] = {
  10791. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  10792. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  10793. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  10794. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  10795. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  10796. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  10797. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  10798. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  10799. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  10800. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  10801. 0x00, 0x9e, 0x01, 0x00,
  10802. /* Extensions - duplicate signature algorithms. */
  10803. 0x00, 0x19, 0x00, 0x0d,
  10804. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  10805. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  10806. /* Supported Versions extension for TLS 1.3. */
  10807. 0x00, 0x2b,
  10808. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  10809. };
  10810. WOLFSSL_BUFFER_INFO msg;
  10811. const char* testCertFile;
  10812. const char* testKeyFile;
  10813. WOLFSSL_CTX *ctx = NULL;
  10814. WOLFSSL *ssl = NULL;
  10815. #ifndef NO_RSA
  10816. testCertFile = svrCertFile;
  10817. testKeyFile = svrKeyFile;
  10818. #elif defined(HAVE_ECC)
  10819. testCertFile = eccCertFile;
  10820. testKeyFile = eccKeyFile;
  10821. #endif
  10822. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  10823. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  10824. WOLFSSL_FILETYPE_PEM));
  10825. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  10826. WOLFSSL_FILETYPE_PEM));
  10827. /* Read from 'msg'. */
  10828. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  10829. /* No where to send to - dummy sender. */
  10830. wolfSSL_SetIOSend(ctx, DummySend);
  10831. ssl = wolfSSL_new(ctx);
  10832. ExpectNotNull(ssl);
  10833. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  10834. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  10835. wolfSSL_SetIOReadCtx(ssl, &msg);
  10836. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  10837. /* can return duplicate ext error or socket error if the peer closed down
  10838. * while sending alert */
  10839. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  10840. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  10841. }
  10842. wolfSSL_free(ssl);
  10843. wolfSSL_CTX_free(ctx);
  10844. #endif
  10845. return EXPECT_RESULT();
  10846. }
  10847. /*----------------------------------------------------------------------------*
  10848. | X509 Tests
  10849. *----------------------------------------------------------------------------*/
  10850. static int test_wolfSSL_X509_NAME_get_entry(void)
  10851. {
  10852. EXPECT_DECLS;
  10853. #if !defined(NO_CERTS) && !defined(NO_RSA)
  10854. #if defined(OPENSSL_ALL) || \
  10855. (defined(OPENSSL_EXTRA) && \
  10856. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  10857. /* use openssl like name to test mapping */
  10858. X509_NAME_ENTRY* ne = NULL;
  10859. X509_NAME* name = NULL;
  10860. X509* x509 = NULL;
  10861. #ifndef NO_FILESYSTEM
  10862. ASN1_STRING* asn = NULL;
  10863. char* subCN = NULL;
  10864. #endif
  10865. int idx = 0;
  10866. ASN1_OBJECT *object = NULL;
  10867. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  10868. defined(WOLFSSL_NGINX)
  10869. #ifndef NO_BIO
  10870. BIO* bio = NULL;
  10871. #endif
  10872. #endif
  10873. #ifndef NO_FILESYSTEM
  10874. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  10875. WOLFSSL_FILETYPE_PEM));
  10876. ExpectNotNull(name = X509_get_subject_name(x509));
  10877. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  10878. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  10879. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  10880. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  10881. wolfSSL_FreeX509(x509);
  10882. x509 = NULL;
  10883. #endif
  10884. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  10885. WOLFSSL_FILETYPE_PEM));
  10886. ExpectNotNull(name = X509_get_subject_name(x509));
  10887. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  10888. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  10889. defined(WOLFSSL_NGINX)
  10890. #ifndef NO_BIO
  10891. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  10892. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  10893. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  10894. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  10895. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  10896. BIO_free(bio);
  10897. #endif
  10898. #endif
  10899. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  10900. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  10901. wolfSSL_FreeX509(x509);
  10902. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  10903. #endif /* !NO_CERTS && !NO_RSA */
  10904. return EXPECT_RESULT();
  10905. }
  10906. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  10907. static int test_wolfSSL_PKCS12(void)
  10908. {
  10909. EXPECT_DECLS;
  10910. /* .p12 file is encrypted with DES3 */
  10911. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  10912. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  10913. * Password Key
  10914. */
  10915. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  10916. !defined(NO_STDIO_FILESYSTEM) && \
  10917. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  10918. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  10919. byte buf[6000];
  10920. char file[] = "./certs/test-servercert.p12";
  10921. char order[] = "./certs/ecc-rsa-server.p12";
  10922. #ifdef WC_RC2
  10923. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  10924. #endif
  10925. char pass[] = "a password";
  10926. const char goodPsw[] = "wolfSSL test";
  10927. const char badPsw[] = "bad";
  10928. #ifdef HAVE_ECC
  10929. WOLFSSL_X509_NAME *subject = NULL;
  10930. WOLFSSL_X509 *x509 = NULL;
  10931. #endif
  10932. XFILE f = XBADFILE;
  10933. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  10934. WOLFSSL_BIO *bio = NULL;
  10935. WOLFSSL_EVP_PKEY *pkey = NULL;
  10936. WC_PKCS12 *pkcs12 = NULL;
  10937. WC_PKCS12 *pkcs12_2 = NULL;
  10938. WOLFSSL_X509 *cert = NULL;
  10939. WOLFSSL_X509 *tmp = NULL;
  10940. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  10941. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  10942. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  10943. WOLFSSL_CTX *ctx = NULL;
  10944. WOLFSSL *ssl = NULL;
  10945. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  10946. #endif
  10947. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  10948. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  10949. if (f != XBADFILE) {
  10950. XFCLOSE(f);
  10951. f = XBADFILE;
  10952. }
  10953. goodPswLen = (int)XSTRLEN(goodPsw);
  10954. badPswLen = (int)XSTRLEN(badPsw);
  10955. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  10956. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  10957. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  10958. ExpectNotNull(pkcs12);
  10959. BIO_free(bio);
  10960. bio = NULL;
  10961. /* check verify MAC directly */
  10962. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  10963. /* check verify MAC fail case directly */
  10964. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  10965. /* check verify MAC fail case */
  10966. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  10967. ExpectNull(pkey);
  10968. ExpectNull(cert);
  10969. /* check parse with no extra certs kept */
  10970. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  10971. 1);
  10972. ExpectNotNull(pkey);
  10973. ExpectNotNull(cert);
  10974. wolfSSL_EVP_PKEY_free(pkey);
  10975. pkey = NULL;
  10976. wolfSSL_X509_free(cert);
  10977. cert = NULL;
  10978. /* check parse with extra certs kept */
  10979. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  10980. 1);
  10981. ExpectNotNull(pkey);
  10982. ExpectNotNull(cert);
  10983. ExpectNotNull(ca);
  10984. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  10985. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  10986. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  10987. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10988. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  10989. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  10990. #else
  10991. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  10992. #endif
  10993. /* Copy stack structure */
  10994. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  10995. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  10996. /* CTX now owns the tmp_ca stack structure */
  10997. tmp_ca = NULL;
  10998. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  10999. ExpectNotNull(tmp_ca);
  11000. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11001. /* Check that the main cert is also set */
  11002. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11003. ExpectNotNull(ssl = SSL_new(ctx));
  11004. ExpectNotNull(SSL_get_certificate(ssl));
  11005. SSL_free(ssl);
  11006. SSL_CTX_free(ctx);
  11007. ctx = NULL;
  11008. #endif
  11009. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11010. /* should be 2 other certs on stack */
  11011. ExpectNotNull(tmp = sk_X509_pop(ca));
  11012. X509_free(tmp);
  11013. ExpectNotNull(tmp = sk_X509_pop(ca));
  11014. X509_free(tmp);
  11015. ExpectNull(sk_X509_pop(ca));
  11016. EVP_PKEY_free(pkey);
  11017. pkey = NULL;
  11018. X509_free(cert);
  11019. cert = NULL;
  11020. sk_X509_pop_free(ca, X509_free);
  11021. ca = NULL;
  11022. /* check PKCS12_create */
  11023. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11024. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11025. SSL_SUCCESS);
  11026. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11027. -1, -1, 100, -1, 0)));
  11028. EVP_PKEY_free(pkey);
  11029. pkey = NULL;
  11030. X509_free(cert);
  11031. cert = NULL;
  11032. sk_X509_pop_free(ca, NULL);
  11033. ca = NULL;
  11034. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11035. SSL_SUCCESS);
  11036. PKCS12_free(pkcs12_2);
  11037. pkcs12_2 = NULL;
  11038. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11039. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11040. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11041. 2000, 1, 0)));
  11042. EVP_PKEY_free(pkey);
  11043. pkey = NULL;
  11044. X509_free(cert);
  11045. cert = NULL;
  11046. sk_X509_pop_free(ca, NULL);
  11047. ca = NULL;
  11048. /* convert to DER then back and parse */
  11049. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11050. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11051. PKCS12_free(pkcs12_2);
  11052. pkcs12_2 = NULL;
  11053. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11054. BIO_free(bio);
  11055. bio = NULL;
  11056. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11057. SSL_SUCCESS);
  11058. /* should be 2 other certs on stack */
  11059. ExpectNotNull(tmp = sk_X509_pop(ca));
  11060. X509_free(tmp);
  11061. ExpectNotNull(tmp = sk_X509_pop(ca));
  11062. X509_free(tmp);
  11063. ExpectNull(sk_X509_pop(ca));
  11064. #ifndef NO_RC4
  11065. PKCS12_free(pkcs12_2);
  11066. pkcs12_2 = NULL;
  11067. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11068. NID_pbe_WithSHA1And128BitRC4,
  11069. NID_pbe_WithSHA1And128BitRC4,
  11070. 2000, 1, 0)));
  11071. EVP_PKEY_free(pkey);
  11072. pkey = NULL;
  11073. X509_free(cert);
  11074. cert = NULL;
  11075. sk_X509_pop_free(ca, NULL);
  11076. ca = NULL;
  11077. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11078. SSL_SUCCESS);
  11079. #endif /* NO_RC4 */
  11080. EVP_PKEY_free(pkey);
  11081. pkey = NULL;
  11082. X509_free(cert);
  11083. cert = NULL;
  11084. PKCS12_free(pkcs12);
  11085. pkcs12 = NULL;
  11086. PKCS12_free(pkcs12_2);
  11087. pkcs12_2 = NULL;
  11088. sk_X509_pop_free(ca, NULL);
  11089. ca = NULL;
  11090. #ifdef HAVE_ECC
  11091. /* test order of parsing */
  11092. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11093. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11094. if (f != XBADFILE) {
  11095. XFCLOSE(f);
  11096. f = XBADFILE;
  11097. }
  11098. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11099. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11100. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11101. WOLFSSL_SUCCESS);
  11102. /* check use of pkey after parse */
  11103. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11104. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11105. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11106. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11107. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11108. #else
  11109. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11110. #endif
  11111. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11112. SSL_CTX_free(ctx);
  11113. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11114. #endif
  11115. ExpectNotNull(pkey);
  11116. ExpectNotNull(cert);
  11117. ExpectNotNull(ca);
  11118. /* compare subject lines of certificates */
  11119. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11120. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11121. SSL_FILETYPE_PEM));
  11122. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11123. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11124. X509_free(x509);
  11125. x509 = NULL;
  11126. /* test expected fail case */
  11127. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11128. SSL_FILETYPE_PEM));
  11129. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11130. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11131. X509_free(x509);
  11132. x509 = NULL;
  11133. X509_free(cert);
  11134. cert = NULL;
  11135. /* get subject line from ca stack */
  11136. ExpectNotNull(cert = sk_X509_pop(ca));
  11137. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11138. /* compare subject from certificate in ca to expected */
  11139. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11140. SSL_FILETYPE_PEM));
  11141. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11142. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11143. /* modify case and compare subject from certificate in ca to expected.
  11144. * The first bit of the name is:
  11145. * /C=US/ST=Washington
  11146. * So we'll change subject->name[1] to 'c' (lower case) */
  11147. if (subject != NULL) {
  11148. subject->name[1] = 'c';
  11149. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11150. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11151. }
  11152. EVP_PKEY_free(pkey);
  11153. pkey = NULL;
  11154. X509_free(x509);
  11155. x509 = NULL;
  11156. X509_free(cert);
  11157. cert = NULL;
  11158. BIO_free(bio);
  11159. bio = NULL;
  11160. PKCS12_free(pkcs12);
  11161. pkcs12 = NULL;
  11162. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11163. ca = NULL;
  11164. /* test order of parsing */
  11165. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11166. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11167. if (f != XBADFILE) {
  11168. XFCLOSE(f);
  11169. f = XBADFILE;
  11170. }
  11171. /* check verify MAC fail case */
  11172. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11173. ExpectNull(pkey);
  11174. ExpectNull(cert);
  11175. /* check parse with no extra certs kept */
  11176. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11177. 1);
  11178. ExpectNotNull(pkey);
  11179. ExpectNotNull(cert);
  11180. wolfSSL_EVP_PKEY_free(pkey);
  11181. pkey = NULL;
  11182. wolfSSL_X509_free(cert);
  11183. cert = NULL;
  11184. /* check parse with extra certs kept */
  11185. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11186. 1);
  11187. ExpectNotNull(pkey);
  11188. ExpectNotNull(cert);
  11189. ExpectNotNull(ca);
  11190. wolfSSL_EVP_PKEY_free(pkey);
  11191. pkey = NULL;
  11192. wolfSSL_X509_free(cert);
  11193. cert = NULL;
  11194. sk_X509_pop_free(ca, NULL);
  11195. ca = NULL;
  11196. PKCS12_free(pkcs12);
  11197. pkcs12 = NULL;
  11198. #endif /* HAVE_ECC */
  11199. #ifdef WC_RC2
  11200. /* test PKCS#12 with RC2 encryption */
  11201. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11202. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11203. if (f != XBADFILE) {
  11204. XFCLOSE(f);
  11205. f = XBADFILE;
  11206. }
  11207. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11208. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11209. /* check verify MAC fail case */
  11210. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11211. ExpectNull(pkey);
  11212. ExpectNull(cert);
  11213. /* check parse with not extra certs kept */
  11214. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11215. WOLFSSL_SUCCESS);
  11216. ExpectNotNull(pkey);
  11217. ExpectNotNull(cert);
  11218. wolfSSL_EVP_PKEY_free(pkey);
  11219. pkey = NULL;
  11220. wolfSSL_X509_free(cert);
  11221. cert = NULL;
  11222. /* check parse with extra certs kept */
  11223. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11224. WOLFSSL_SUCCESS);
  11225. ExpectNotNull(pkey);
  11226. ExpectNotNull(cert);
  11227. ExpectNotNull(ca);
  11228. wolfSSL_EVP_PKEY_free(pkey);
  11229. wolfSSL_X509_free(cert);
  11230. sk_X509_pop_free(ca, NULL);
  11231. BIO_free(bio);
  11232. bio = NULL;
  11233. PKCS12_free(pkcs12);
  11234. pkcs12 = NULL;
  11235. #endif /* WC_RC2 */
  11236. /* Test i2d_PKCS12_bio */
  11237. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11238. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11239. if (f != XBADFILE)
  11240. XFCLOSE(f);
  11241. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11242. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11243. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11244. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11245. PKCS12_free(pkcs12);
  11246. BIO_free(bio);
  11247. (void)order;
  11248. #endif /* OPENSSL_EXTRA */
  11249. #endif /* HAVE_FIPS */
  11250. return EXPECT_RESULT();
  11251. }
  11252. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11253. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11254. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11255. #define TEST_PKCS8_ENC
  11256. #endif
  11257. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11258. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11259. /* used to keep track if FailTestCallback was called */
  11260. static int failTestCallbackCalled = 0;
  11261. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11262. {
  11263. (void)passwd;
  11264. (void)sz;
  11265. (void)rw;
  11266. (void)userdata;
  11267. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11268. failTestCallbackCalled = 1;
  11269. return -1;
  11270. }
  11271. #endif
  11272. static int test_wolfSSL_no_password_cb(void)
  11273. {
  11274. EXPECT_DECLS;
  11275. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11276. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11277. WOLFSSL_CTX* ctx = NULL;
  11278. byte buff[FOURK_BUF];
  11279. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11280. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11281. XFILE f = XBADFILE;
  11282. int bytes = 0;
  11283. #ifndef NO_WOLFSSL_CLIENT
  11284. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11285. #else
  11286. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11287. #endif
  11288. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11289. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11290. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11291. if (f != XBADFILE) {
  11292. XFCLOSE(f);
  11293. f = XBADFILE;
  11294. }
  11295. ExpectIntLE(bytes, sizeof(buff));
  11296. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11297. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11298. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11299. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11300. if (f != XBADFILE)
  11301. XFCLOSE(f);
  11302. ExpectIntLE(bytes, sizeof(buff));
  11303. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11304. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11305. wolfSSL_CTX_free(ctx);
  11306. /* Password callback should not be called by default */
  11307. ExpectIntEQ(failTestCallbackCalled, 0);
  11308. #endif
  11309. return EXPECT_RESULT();
  11310. }
  11311. #ifdef TEST_PKCS8_ENC
  11312. /* for PKCS8 test case */
  11313. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11314. {
  11315. int flag = 0;
  11316. (void)rw;
  11317. if (userdata != NULL) {
  11318. flag = *((int*)userdata); /* user set data */
  11319. }
  11320. switch (flag) {
  11321. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11322. * can be anything the user wishes to be passed to the callback
  11323. * associated with the WOLFSSL_CTX */
  11324. XSTRNCPY(passwd, "yassl123", sz);
  11325. return 8;
  11326. default:
  11327. return BAD_FUNC_ARG;
  11328. }
  11329. }
  11330. #endif /* TEST_PKCS8_ENC */
  11331. /* Testing functions dealing with PKCS8 */
  11332. static int test_wolfSSL_PKCS8(void)
  11333. {
  11334. EXPECT_DECLS;
  11335. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11336. !defined(WOLFCRYPT_ONLY)
  11337. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11338. byte buff[FOURK_BUF];
  11339. byte der[FOURK_BUF];
  11340. #ifndef NO_RSA
  11341. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11342. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11343. #endif
  11344. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11345. #ifdef HAVE_ECC
  11346. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11347. #endif
  11348. XFILE f = XBADFILE;
  11349. int bytes = 0;
  11350. WOLFSSL_CTX* ctx = NULL;
  11351. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11352. int ret;
  11353. ecc_key key;
  11354. word32 x = 0;
  11355. #endif
  11356. #ifdef TEST_PKCS8_ENC
  11357. #if !defined(NO_RSA) && !defined(NO_SHA)
  11358. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11359. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11360. #endif
  11361. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11362. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11363. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11364. #endif
  11365. int flag;
  11366. #endif
  11367. (void)der;
  11368. #ifndef NO_WOLFSSL_CLIENT
  11369. #ifndef WOLFSSL_NO_TLS12
  11370. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11371. #else
  11372. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11373. #endif
  11374. #else
  11375. #ifndef WOLFSSL_NO_TLS12
  11376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11377. #else
  11378. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11379. #endif
  11380. #endif
  11381. #ifdef TEST_PKCS8_ENC
  11382. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11383. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11384. flag = 1; /* used by password callback as return code */
  11385. #if !defined(NO_RSA) && !defined(NO_SHA)
  11386. /* test loading PEM PKCS8 encrypted file */
  11387. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11388. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11389. if (f != XBADFILE) {
  11390. XFCLOSE(f);
  11391. f = XBADFILE;
  11392. }
  11393. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11394. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11395. /* this next case should fail because of password callback return code */
  11396. flag = 0; /* used by password callback as return code */
  11397. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11398. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11399. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11400. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11401. "yassl123"), 0);
  11402. /* test that error value is returned with a bad password */
  11403. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11404. "bad"), 0);
  11405. /* test loading PEM PKCS8 encrypted file */
  11406. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11407. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11408. if (f != XBADFILE) {
  11409. XFCLOSE(f);
  11410. f = XBADFILE;
  11411. }
  11412. flag = 1; /* used by password callback as return code */
  11413. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11414. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11415. /* this next case should fail because of password callback return code */
  11416. flag = 0; /* used by password callback as return code */
  11417. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11418. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11419. #endif /* !NO_RSA && !NO_SHA */
  11420. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11421. /* test loading PEM PKCS8 encrypted ECC Key file */
  11422. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11423. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11424. if (f != XBADFILE) {
  11425. XFCLOSE(f);
  11426. f = XBADFILE;
  11427. }
  11428. flag = 1; /* used by password callback as return code */
  11429. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11430. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11431. /* this next case should fail because of password callback return code */
  11432. flag = 0; /* used by password callback as return code */
  11433. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11434. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11435. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11436. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11437. "yassl123"), 0);
  11438. /* test that error value is returned with a bad password */
  11439. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11440. "bad"), 0);
  11441. /* test loading DER PKCS8 encrypted ECC Key file */
  11442. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11443. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11444. if (f != XBADFILE) {
  11445. XFCLOSE(f);
  11446. f = XBADFILE;
  11447. }
  11448. flag = 1; /* used by password callback as return code */
  11449. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11450. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11451. /* this next case should fail because of password callback return code */
  11452. flag = 0; /* used by password callback as return code */
  11453. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11454. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11455. /* leave flag as "okay" */
  11456. flag = 1;
  11457. #endif /* HAVE_ECC && !NO_SHA */
  11458. #endif /* TEST_PKCS8_ENC */
  11459. #ifndef NO_RSA
  11460. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11461. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11462. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11463. if (f != XBADFILE) {
  11464. XFCLOSE(f);
  11465. f = XBADFILE;
  11466. }
  11467. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11468. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11469. /* test loading PEM PKCS8 private key file (not encrypted) */
  11470. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11471. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11472. if (f != XBADFILE) {
  11473. XFCLOSE(f);
  11474. f = XBADFILE;
  11475. }
  11476. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11477. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11478. #endif /* !NO_RSA */
  11479. /* Test PKCS8 PEM ECC key no crypt */
  11480. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11481. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11482. if (f != XBADFILE) {
  11483. XFCLOSE(f);
  11484. f = XBADFILE;
  11485. }
  11486. #ifdef HAVE_ECC
  11487. /* Test PKCS8 PEM ECC key no crypt */
  11488. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11489. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11490. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11491. /* decrypt PKCS8 PEM to key in DER format */
  11492. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11493. (word32)sizeof(der), NULL)), 0);
  11494. ret = wc_ecc_init(&key);
  11495. if (ret == 0) {
  11496. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11497. wc_ecc_free(&key);
  11498. }
  11499. ExpectIntEQ(ret, 0);
  11500. #endif
  11501. /* Test PKCS8 DER ECC key no crypt */
  11502. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11503. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11504. if (f != XBADFILE)
  11505. XFCLOSE(f);
  11506. /* Test using a PKCS8 ECC PEM */
  11507. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11508. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11509. #else
  11510. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11511. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11512. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11513. #endif /* HAVE_ECC */
  11514. wolfSSL_CTX_free(ctx);
  11515. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11516. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11517. return EXPECT_RESULT();
  11518. }
  11519. static int test_wolfSSL_PKCS8_ED25519(void)
  11520. {
  11521. EXPECT_DECLS;
  11522. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11523. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11524. defined(HAVE_ED25519_KEY_IMPORT)
  11525. const byte encPrivKey[] = \
  11526. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11527. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11528. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11529. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11530. "2L9W4v7swXkV+X+a1ww=\n"
  11531. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11532. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11533. byte der[FOURK_BUF];
  11534. WOLFSSL_CTX* ctx = NULL;
  11535. int bytes;
  11536. XMEMSET(der, 0, sizeof(der));
  11537. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11538. (word32)sizeof(der), password)), 0);
  11539. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11540. #ifndef NO_WOLFSSL_SERVER
  11541. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11542. #else
  11543. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11544. #endif
  11545. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11546. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11547. wolfSSL_CTX_free(ctx);
  11548. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11549. #endif
  11550. return EXPECT_RESULT();
  11551. }
  11552. static int test_wolfSSL_PKCS8_ED448(void)
  11553. {
  11554. EXPECT_DECLS;
  11555. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11556. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11557. defined(HAVE_ED448_KEY_IMPORT)
  11558. const byte encPrivKey[] = \
  11559. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11560. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11561. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11562. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11563. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11564. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11565. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11566. byte der[FOURK_BUF];
  11567. WOLFSSL_CTX* ctx = NULL;
  11568. int bytes;
  11569. XMEMSET(der, 0, sizeof(der));
  11570. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11571. (word32)sizeof(der), password)), 0);
  11572. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11573. #ifndef NO_WOLFSSL_SERVER
  11574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11575. #else
  11576. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11577. #endif
  11578. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11579. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11580. wolfSSL_CTX_free(ctx);
  11581. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11582. #endif
  11583. return EXPECT_RESULT();
  11584. }
  11585. /* Testing functions dealing with PKCS5 */
  11586. static int test_wolfSSL_PKCS5(void)
  11587. {
  11588. EXPECT_DECLS;
  11589. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11590. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11591. const char* passwd = "myfipsPa$$W0rd";
  11592. #else
  11593. const char *passwd = "pass1234";
  11594. #endif
  11595. const unsigned char *salt = (unsigned char *)"salt1234";
  11596. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11597. DYNAMIC_TYPE_TMP_BUFFER);
  11598. int ret = 0;
  11599. ExpectNotNull(out);
  11600. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11601. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11602. WOLFSSL_SUCCESS);
  11603. #ifdef WOLFSSL_SHA512
  11604. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11605. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11606. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11607. #endif
  11608. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11609. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11610. return EXPECT_RESULT();
  11611. }
  11612. /* test parsing URI from certificate */
  11613. static int test_wolfSSL_URI(void)
  11614. {
  11615. EXPECT_DECLS;
  11616. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11617. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11618. defined(OPENSSL_EXTRA))
  11619. WOLFSSL_X509* x509 = NULL;
  11620. const char uri[] = "./certs/client-uri-cert.pem";
  11621. const char urn[] = "./certs/client-absolute-urn.pem";
  11622. const char badUri[] = "./certs/client-relative-uri.pem";
  11623. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11624. WOLFSSL_FILETYPE_PEM));
  11625. wolfSSL_FreeX509(x509);
  11626. x509 = NULL;
  11627. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11628. WOLFSSL_FILETYPE_PEM));
  11629. wolfSSL_FreeX509(x509);
  11630. x509 = NULL;
  11631. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11632. && !defined(WOLFSSL_FPKI)
  11633. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11634. WOLFSSL_FILETYPE_PEM));
  11635. #else
  11636. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11637. WOLFSSL_FILETYPE_PEM));
  11638. #endif
  11639. wolfSSL_FreeX509(x509);
  11640. #endif
  11641. return EXPECT_RESULT();
  11642. }
  11643. static int test_wolfSSL_TBS(void)
  11644. {
  11645. EXPECT_DECLS;
  11646. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11647. && defined(OPENSSL_EXTRA)
  11648. WOLFSSL_X509* x509 = NULL;
  11649. const unsigned char* tbs;
  11650. int tbsSz;
  11651. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11652. WOLFSSL_FILETYPE_PEM));
  11653. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11654. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11655. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11656. ExpectIntEQ(tbsSz, 1003);
  11657. wolfSSL_FreeX509(x509);
  11658. #endif
  11659. return EXPECT_RESULT();
  11660. }
  11661. static int test_wolfSSL_X509_verify(void)
  11662. {
  11663. EXPECT_DECLS;
  11664. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11665. defined(OPENSSL_EXTRA)
  11666. WOLFSSL_X509* ca = NULL;
  11667. WOLFSSL_X509* serv = NULL;
  11668. WOLFSSL_EVP_PKEY* pkey = NULL;
  11669. unsigned char buf[2048];
  11670. const unsigned char* pt = NULL;
  11671. int bufSz;
  11672. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11673. WOLFSSL_FILETYPE_PEM));
  11674. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11675. WOLFSSL_SUCCESS);
  11676. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11677. WOLFSSL_SUCCESS);
  11678. ExpectIntEQ(bufSz, 294);
  11679. bufSz = 2048;
  11680. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11681. WOLFSSL_SUCCESS);
  11682. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11683. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11684. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11685. WOLFSSL_FILETYPE_PEM));
  11686. /* success case */
  11687. pt = buf;
  11688. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11689. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11690. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11691. wolfSSL_EVP_PKEY_free(pkey);
  11692. pkey = NULL;
  11693. /* fail case */
  11694. bufSz = 2048;
  11695. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11696. WOLFSSL_SUCCESS);
  11697. pt = buf;
  11698. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11699. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11700. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11701. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11702. wolfSSL_EVP_PKEY_free(pkey);
  11703. wolfSSL_FreeX509(ca);
  11704. wolfSSL_FreeX509(serv);
  11705. #endif
  11706. return EXPECT_RESULT();
  11707. }
  11708. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11709. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11710. /* Given acert file and its pubkey file, read them and then
  11711. * attempt to verify signed acert.
  11712. *
  11713. * If expect_pass is true, then verification should pass.
  11714. * If expect_pass is false, then verification should fail.
  11715. * */
  11716. static int do_acert_verify_test(const char * acert_file,
  11717. const char * pkey_file,
  11718. size_t expect_pass)
  11719. {
  11720. X509_ACERT * x509 = NULL;
  11721. EVP_PKEY * pkey = NULL;
  11722. BIO * bp = NULL;
  11723. int verify_rc = 0;
  11724. /* First read the attribute certificate. */
  11725. bp = BIO_new_file(acert_file, "r");
  11726. if (bp == NULL) {
  11727. return -1;
  11728. }
  11729. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11730. BIO_free(bp);
  11731. bp = NULL;
  11732. if (x509 == NULL) {
  11733. return -1;
  11734. }
  11735. /* Next read the associated pub key. */
  11736. bp = BIO_new_file(pkey_file, "r");
  11737. if (bp == NULL) {
  11738. X509_ACERT_free(x509);
  11739. x509 = NULL;
  11740. return -1;
  11741. }
  11742. pkey = PEM_read_bio_PUBKEY(bp, &pkey, NULL, NULL);
  11743. BIO_free(bp);
  11744. bp = NULL;
  11745. if (pkey == NULL) {
  11746. X509_ACERT_free(x509);
  11747. x509 = NULL;
  11748. return -1;
  11749. }
  11750. /* Finally, do verification. */
  11751. verify_rc = X509_ACERT_verify(x509, pkey);
  11752. X509_ACERT_free(x509);
  11753. x509 = NULL;
  11754. EVP_PKEY_free(pkey);
  11755. pkey = NULL;
  11756. if (expect_pass && verify_rc != 1) {
  11757. return -1;
  11758. }
  11759. if (!expect_pass && verify_rc == 1) {
  11760. return -1;
  11761. }
  11762. return 0;
  11763. }
  11764. #endif
  11765. static int test_wolfSSL_X509_ACERT_verify(void)
  11766. {
  11767. EXPECT_DECLS;
  11768. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11769. defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11770. /* Walk over list of signed ACERTs and their pubkeys.
  11771. * All should load and pass verification. */
  11772. const char * acerts[4] = {"certs/acert/acert.pem",
  11773. "certs/acert/acert_ietf.pem",
  11774. "certs/acert/rsa_pss/acert.pem",
  11775. "certs/acert/rsa_pss/acert_ietf.pem"};
  11776. const char * pkeys[4] = {"certs/acert/acert_pubkey.pem",
  11777. "certs/acert/acert_ietf_pubkey.pem",
  11778. "certs/acert/rsa_pss/acert_pubkey.pem",
  11779. "certs/acert/rsa_pss/acert_ietf_pubkey.pem"};
  11780. int rc = 0;
  11781. size_t i = 0;
  11782. size_t j = 0;
  11783. for (i = 0; i < 4; ++i) {
  11784. for (j = i; j < 4; ++j) {
  11785. rc = do_acert_verify_test(acerts[i], pkeys[j], i == j);
  11786. if (rc) {
  11787. fprintf(stderr, "error: %s: i = %zu, j = %zu, rc = %d\n",
  11788. "do_acert_verify_test", i, j, rc);
  11789. break;
  11790. }
  11791. }
  11792. if (rc) { break; }
  11793. }
  11794. ExpectIntEQ(rc, 0);
  11795. #endif
  11796. return EXPECT_RESULT();
  11797. }
  11798. static int test_wolfSSL_X509_ACERT_misc_api(void)
  11799. {
  11800. EXPECT_DECLS;
  11801. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11802. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11803. const char * acerts[4] = {"certs/acert/acert.pem",
  11804. "certs/acert/acert_ietf.pem",
  11805. "certs/acert/rsa_pss/acert.pem",
  11806. "certs/acert/rsa_pss/acert_ietf.pem"};
  11807. int rc = 0;
  11808. X509_ACERT * x509 = NULL;
  11809. BIO * bp = NULL;
  11810. long ver_long = 0;
  11811. int ver = 0;
  11812. int nid = 0;
  11813. const byte * raw_attr = NULL;
  11814. word32 attr_len = 0;
  11815. size_t i = 0;
  11816. int buf_len = 0;
  11817. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  11818. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  11819. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  11820. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  11821. for (i = 0; i < 4; ++i) {
  11822. const char * acert_file = acerts[i];
  11823. int is_rsa_pss = 0;
  11824. int is_ietf_acert = 0;
  11825. byte serial[64];
  11826. int serial_len = sizeof(serial);
  11827. XMEMSET(serial, 0, sizeof(serial));
  11828. is_rsa_pss = XSTRSTR(acert_file, "rsa_pss") != NULL ? 1 : 0;
  11829. is_ietf_acert = XSTRSTR(acert_file, "ietf.pem") != NULL ? 1 : 0;
  11830. /* First read the attribute certificate. */
  11831. bp = BIO_new_file(acert_file, "r");
  11832. ExpectNotNull(bp);
  11833. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11834. ExpectNotNull(x509);
  11835. /* We're done with the bio for now. */
  11836. if (bp != NULL) {
  11837. BIO_free(bp);
  11838. bp = NULL;
  11839. }
  11840. /* Check version and signature NID. */
  11841. ver_long = X509_ACERT_get_version(x509);
  11842. ExpectIntEQ(ver_long, 1);
  11843. ver = wolfSSL_X509_ACERT_version(x509);
  11844. ExpectIntEQ(ver, 2);
  11845. nid = X509_ACERT_get_signature_nid(x509);
  11846. if (is_rsa_pss) {
  11847. ExpectIntEQ(nid, NID_rsassaPss);
  11848. }
  11849. else {
  11850. ExpectIntEQ(nid, NID_sha256WithRSAEncryption);
  11851. }
  11852. /* Get the serial number buffer.
  11853. * The ietf acert example has a 20 byte serial number. */
  11854. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  11855. ExpectIntEQ(rc, SSL_SUCCESS);
  11856. if (is_ietf_acert) {
  11857. ExpectIntEQ(serial_len, 20);
  11858. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  11859. }
  11860. else {
  11861. ExpectIntEQ(serial_len, 1);
  11862. ExpectTrue(serial[0] == 0x01);
  11863. }
  11864. /* Repeat the same but with null serial buffer. This is ok. */
  11865. rc = wolfSSL_X509_ACERT_get_serial_number(x509, NULL, &serial_len);
  11866. ExpectIntEQ(rc, SSL_SUCCESS);
  11867. if (is_ietf_acert) {
  11868. ExpectIntEQ(serial_len, 20);
  11869. }
  11870. else {
  11871. ExpectIntEQ(serial_len, 1);
  11872. ExpectTrue(serial[0] == 0x01);
  11873. }
  11874. /* Get the attributes buffer. */
  11875. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  11876. ExpectIntEQ(rc, SSL_SUCCESS);
  11877. if (is_ietf_acert) {
  11878. /* This cert has a 65 byte attributes field. */
  11879. ExpectNotNull(raw_attr);
  11880. ExpectIntEQ(attr_len, 65);
  11881. }
  11882. else {
  11883. /* This cert has a 237 byte attributes field. */
  11884. ExpectNotNull(raw_attr);
  11885. ExpectIntEQ(attr_len, 237);
  11886. }
  11887. /* Test printing acert to memory bio. */
  11888. ExpectNotNull(bp = BIO_new(BIO_s_mem()));
  11889. rc = X509_ACERT_print(bp, x509);
  11890. ExpectIntEQ(rc, SSL_SUCCESS);
  11891. /* Now do a bunch of invalid stuff with partially valid inputs. */
  11892. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, NULL);
  11893. ExpectIntEQ(rc, BAD_FUNC_ARG);
  11894. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, NULL, &attr_len);
  11895. ExpectIntEQ(rc, BAD_FUNC_ARG);
  11896. rc = wolfSSL_X509_ACERT_get_attr_buf(NULL, &raw_attr, &attr_len);
  11897. ExpectIntEQ(rc, BAD_FUNC_ARG);
  11898. ver_long = X509_ACERT_get_version(NULL);
  11899. ExpectIntEQ(ver_long, 0);
  11900. ver = wolfSSL_X509_ACERT_version(NULL);
  11901. ExpectIntEQ(ver, 0);
  11902. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, NULL);
  11903. ExpectIntEQ(rc, WOLFSSL_FATAL_ERROR);
  11904. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, &buf_len);
  11905. ExpectIntEQ(rc, SSL_SUCCESS);
  11906. ExpectIntEQ(buf_len, 256);
  11907. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, NULL);
  11908. ExpectIntEQ(rc, BAD_FUNC_ARG);
  11909. rc = X509_ACERT_print(bp, NULL);
  11910. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  11911. rc = X509_ACERT_print(NULL, x509);
  11912. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  11913. /* Finally free the acert and bio, we're done with them. */
  11914. if (x509 != NULL) {
  11915. X509_ACERT_free(x509);
  11916. x509 = NULL;
  11917. }
  11918. if (bp != NULL) {
  11919. BIO_free(bp);
  11920. bp = NULL;
  11921. }
  11922. }
  11923. #endif
  11924. return EXPECT_RESULT();
  11925. }
  11926. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  11927. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  11928. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  11929. /* create certificate with version 2 */
  11930. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  11931. {
  11932. EXPECT_DECLS;
  11933. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  11934. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  11935. unsigned char *der = NULL, *key = NULL, *pt;
  11936. char *header = NULL, *name = NULL;
  11937. int derSz;
  11938. long keySz;
  11939. XFILE fp = XBADFILE;
  11940. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  11941. time_t t;
  11942. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11943. WOLFSSL_FILETYPE_PEM));
  11944. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  11945. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  11946. WOLFSSL_SUCCESS);
  11947. if (fp != XBADFILE)
  11948. XFCLOSE(fp);
  11949. pt = key;
  11950. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  11951. (const unsigned char**)&pt, keySz));
  11952. /* create the version 2 certificate */
  11953. ExpectNotNull(x509v2 = X509_new());
  11954. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  11955. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  11956. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  11957. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  11958. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  11959. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  11960. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  11961. t = time(NULL);
  11962. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  11963. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  11964. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  11965. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  11966. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  11967. derSz = wolfSSL_i2d_X509(x509v2, &der);
  11968. ExpectIntGT(derSz, 0);
  11969. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  11970. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11971. /* TODO: Replace with API call */
  11972. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  11973. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11974. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11975. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11976. wolfSSL_X509_free(x509);
  11977. wolfSSL_X509_free(x509v2);
  11978. wolfSSL_EVP_PKEY_free(priv);
  11979. wolfSSL_EVP_PKEY_free(pub);
  11980. wolfSSL_ASN1_TIME_free(notBefore);
  11981. wolfSSL_ASN1_TIME_free(notAfter);
  11982. return EXPECT_RESULT();
  11983. }
  11984. /* override certificate version error */
  11985. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  11986. {
  11987. EXPECT_DECLS;
  11988. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  11989. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  11990. #else
  11991. ExpectIntEQ(store->error, 0);
  11992. #endif
  11993. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  11994. (void)preverify;
  11995. return EXPECT_RESULT() == TEST_SUCCESS;
  11996. }
  11997. /* set verify callback that will override bad certificate version */
  11998. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  11999. {
  12000. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  12001. return TEST_SUCCESS;
  12002. }
  12003. #endif
  12004. static int test_wolfSSL_X509_TLS_version_test_1(void)
  12005. {
  12006. EXPECT_DECLS;
  12007. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12008. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12009. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12010. test_ssl_cbf func_cb_client;
  12011. test_ssl_cbf func_cb_server;
  12012. /* test server rejects a client certificate that is not version 3 */
  12013. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12014. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12015. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12016. #ifndef WOLFSSL_NO_TLS12
  12017. func_cb_client.method = wolfTLSv1_2_client_method;
  12018. #else
  12019. func_cb_client.method = wolfTLSv1_3_client_method;
  12020. #endif
  12021. #ifndef WOLFSSL_NO_TLS12
  12022. func_cb_server.method = wolfTLSv1_2_server_method;
  12023. #else
  12024. func_cb_server.method = wolfTLSv1_3_server_method;
  12025. #endif
  12026. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12027. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12028. &func_cb_server, NULL), TEST_FAIL);
  12029. #else
  12030. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12031. &func_cb_server, NULL), TEST_SUCCESS);
  12032. #endif
  12033. #endif
  12034. return EXPECT_RESULT();
  12035. }
  12036. static int test_wolfSSL_X509_TLS_version_test_2(void)
  12037. {
  12038. EXPECT_DECLS;
  12039. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12040. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12041. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12042. test_ssl_cbf func_cb_client;
  12043. test_ssl_cbf func_cb_server;
  12044. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12045. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12046. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12047. func_cb_server.ctx_ready = &test_set_override_x509;
  12048. #ifndef WOLFSSL_NO_TLS12
  12049. func_cb_client.method = wolfTLSv1_2_client_method;
  12050. #else
  12051. func_cb_client.method = wolfTLSv1_3_client_method;
  12052. #endif
  12053. #ifndef WOLFSSL_NO_TLS12
  12054. func_cb_server.method = wolfTLSv1_2_server_method;
  12055. #else
  12056. func_cb_server.method = wolfTLSv1_3_server_method;
  12057. #endif
  12058. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12059. &func_cb_server, NULL), TEST_SUCCESS);
  12060. #endif
  12061. return EXPECT_RESULT();
  12062. }
  12063. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  12064. * version allowed.
  12065. * POST: 1 on success.
  12066. */
  12067. static int test_wolfSSL_CTX_SetMinVersion(void)
  12068. {
  12069. int res = TEST_SKIPPED;
  12070. #ifndef NO_WOLFSSL_CLIENT
  12071. int failFlag = WOLFSSL_SUCCESS;
  12072. WOLFSSL_CTX* ctx;
  12073. int itr;
  12074. #ifndef NO_OLD_TLS
  12075. const int versions[] = {
  12076. #ifdef WOLFSSL_ALLOW_TLSV10
  12077. WOLFSSL_TLSV1,
  12078. #endif
  12079. WOLFSSL_TLSV1_1,
  12080. WOLFSSL_TLSV1_2 };
  12081. #elif !defined(WOLFSSL_NO_TLS12)
  12082. const int versions[] = { WOLFSSL_TLSV1_2 };
  12083. #elif defined(WOLFSSL_TLS13)
  12084. const int versions[] = { WOLFSSL_TLSV1_3 };
  12085. #else
  12086. const int versions[0];
  12087. #endif
  12088. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  12089. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  12090. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  12091. != WOLFSSL_SUCCESS) {
  12092. failFlag = WOLFSSL_FAILURE;
  12093. }
  12094. }
  12095. wolfSSL_CTX_free(ctx);
  12096. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  12097. #endif
  12098. return res;
  12099. } /* END test_wolfSSL_CTX_SetMinVersion */
  12100. /*----------------------------------------------------------------------------*
  12101. | OCSP Stapling
  12102. *----------------------------------------------------------------------------*/
  12103. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  12104. * need to contact the CA, lowering the cost of cert revocation checking.
  12105. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  12106. * POST: 1 returned for success.
  12107. */
  12108. static int test_wolfSSL_UseOCSPStapling(void)
  12109. {
  12110. EXPECT_DECLS;
  12111. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  12112. !defined(NO_WOLFSSL_CLIENT)
  12113. WOLFSSL_CTX* ctx = NULL;
  12114. WOLFSSL* ssl = NULL;
  12115. #ifndef NO_WOLFSSL_CLIENT
  12116. #ifndef WOLFSSL_NO_TLS12
  12117. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12118. #else
  12119. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12120. #endif
  12121. #else
  12122. #ifndef WOLFSSL_NO_TLS12
  12123. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12124. #else
  12125. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12126. #endif
  12127. #endif
  12128. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12129. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  12130. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12131. #ifndef NO_WOLFSSL_CLIENT
  12132. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12133. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12134. #else
  12135. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12136. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12137. #endif
  12138. wolfSSL_free(ssl);
  12139. wolfSSL_CTX_free(ctx);
  12140. #endif
  12141. return EXPECT_RESULT();
  12142. } /* END test_wolfSSL_UseOCSPStapling */
  12143. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  12144. * stapling eliminates the need to contact the CA and lowers cert revocation
  12145. * check.
  12146. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  12147. */
  12148. static int test_wolfSSL_UseOCSPStaplingV2(void)
  12149. {
  12150. EXPECT_DECLS;
  12151. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  12152. !defined(NO_WOLFSSL_CLIENT)
  12153. WOLFSSL_CTX* ctx = NULL;
  12154. WOLFSSL* ssl = NULL;
  12155. #ifndef NO_WOLFSSL_CLIENT
  12156. #ifndef WOLFSSL_NO_TLS12
  12157. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12158. #else
  12159. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12160. #endif
  12161. #else
  12162. #ifndef WOLFSSL_NO_TLS12
  12163. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12164. #else
  12165. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12166. #endif
  12167. #endif
  12168. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12169. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  12170. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12171. #ifndef NO_WOLFSSL_CLIENT
  12172. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12173. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12174. #else
  12175. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12176. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12177. #endif
  12178. wolfSSL_free(ssl);
  12179. wolfSSL_CTX_free(ctx);
  12180. #endif
  12181. return EXPECT_RESULT();
  12182. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  12183. /*----------------------------------------------------------------------------*
  12184. | Multicast Tests
  12185. *----------------------------------------------------------------------------*/
  12186. static int test_wolfSSL_mcast(void)
  12187. {
  12188. EXPECT_DECLS;
  12189. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  12190. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  12191. WOLFSSL_CTX* ctx = NULL;
  12192. WOLFSSL* ssl = NULL;
  12193. byte preMasterSecret[512];
  12194. byte clientRandom[32];
  12195. byte serverRandom[32];
  12196. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  12197. byte buf[256];
  12198. word16 newId;
  12199. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  12200. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  12201. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12202. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  12203. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  12204. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  12205. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  12206. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  12207. WOLFSSL_SUCCESS);
  12208. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  12209. ExpectIntLE(newId, 100);
  12210. wolfSSL_free(ssl);
  12211. wolfSSL_CTX_free(ctx);
  12212. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  12213. * WOLFSSL_SNIFFER) */
  12214. return EXPECT_RESULT();
  12215. }
  12216. /*----------------------------------------------------------------------------*
  12217. | Wolfcrypt
  12218. *----------------------------------------------------------------------------*/
  12219. /*
  12220. * Unit test for the wc_InitBlake2b()
  12221. */
  12222. static int test_wc_InitBlake2b(void)
  12223. {
  12224. EXPECT_DECLS;
  12225. #ifdef HAVE_BLAKE2
  12226. Blake2b blake;
  12227. /* Test good arg. */
  12228. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12229. /* Test bad arg. */
  12230. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12231. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12232. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12233. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12234. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12235. #endif
  12236. return EXPECT_RESULT();
  12237. } /* END test_wc_InitBlake2b*/
  12238. /*
  12239. * Unit test for the wc_InitBlake2b_WithKey()
  12240. */
  12241. static int test_wc_InitBlake2b_WithKey(void)
  12242. {
  12243. EXPECT_DECLS;
  12244. #ifdef HAVE_BLAKE2
  12245. Blake2b blake;
  12246. word32 digestSz = BLAKE2B_KEYBYTES;
  12247. byte key[BLAKE2B_KEYBYTES];
  12248. word32 keylen = BLAKE2B_KEYBYTES;
  12249. XMEMSET(key, 0, sizeof(key));
  12250. /* Test good arg. */
  12251. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12252. /* Test bad args. */
  12253. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12255. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12256. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12257. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12258. #endif
  12259. return EXPECT_RESULT();
  12260. } /* END wc_InitBlake2b_WithKey*/
  12261. /*
  12262. * Unit test for the wc_InitBlake2s_WithKey()
  12263. */
  12264. static int test_wc_InitBlake2s_WithKey(void)
  12265. {
  12266. EXPECT_DECLS;
  12267. #ifdef HAVE_BLAKE2S
  12268. Blake2s blake;
  12269. word32 digestSz = BLAKE2S_KEYBYTES;
  12270. byte *key = (byte*)"01234567890123456789012345678901";
  12271. word32 keylen = BLAKE2S_KEYBYTES;
  12272. /* Test good arg. */
  12273. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12274. /* Test bad args. */
  12275. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12276. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12277. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12278. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12279. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12280. #endif
  12281. return EXPECT_RESULT();
  12282. } /* END wc_InitBlake2s_WithKey*/
  12283. /*
  12284. * Unit test for the wc_InitMd5()
  12285. */
  12286. static int test_wc_InitMd5(void)
  12287. {
  12288. EXPECT_DECLS;
  12289. #ifndef NO_MD5
  12290. wc_Md5 md5;
  12291. /* Test good arg. */
  12292. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12293. /* Test bad arg. */
  12294. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12295. wc_Md5Free(&md5);
  12296. #endif
  12297. return EXPECT_RESULT();
  12298. } /* END test_wc_InitMd5 */
  12299. /*
  12300. * Testing wc_UpdateMd5()
  12301. */
  12302. static int test_wc_Md5Update(void)
  12303. {
  12304. EXPECT_DECLS;
  12305. #ifndef NO_MD5
  12306. wc_Md5 md5;
  12307. byte hash[WC_MD5_DIGEST_SIZE];
  12308. testVector a, b, c;
  12309. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12310. /* Input */
  12311. a.input = "a";
  12312. a.inLen = XSTRLEN(a.input);
  12313. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12314. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12315. /* Update input. */
  12316. a.input = "abc";
  12317. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12318. "\x72";
  12319. a.inLen = XSTRLEN(a.input);
  12320. a.outLen = XSTRLEN(a.output);
  12321. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12322. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12323. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12324. /* Pass in bad values. */
  12325. b.input = NULL;
  12326. b.inLen = 0;
  12327. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12328. c.input = NULL;
  12329. c.inLen = WC_MD5_DIGEST_SIZE;
  12330. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12331. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12332. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12333. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12334. wc_Md5Free(&md5);
  12335. #endif
  12336. return EXPECT_RESULT();
  12337. } /* END test_wc_Md5Update() */
  12338. /*
  12339. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12340. */
  12341. static int test_wc_Md5Final(void)
  12342. {
  12343. EXPECT_DECLS;
  12344. #ifndef NO_MD5
  12345. /* Instantiate */
  12346. wc_Md5 md5;
  12347. byte* hash_test[3];
  12348. byte hash1[WC_MD5_DIGEST_SIZE];
  12349. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12350. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12351. int times, i;
  12352. /* Initialize */
  12353. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12354. hash_test[0] = hash1;
  12355. hash_test[1] = hash2;
  12356. hash_test[2] = hash3;
  12357. times = sizeof(hash_test)/sizeof(byte*);
  12358. for (i = 0; i < times; i++) {
  12359. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12360. }
  12361. /* Test bad args. */
  12362. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12363. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12364. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12365. wc_Md5Free(&md5);
  12366. #endif
  12367. return EXPECT_RESULT();
  12368. }
  12369. /*
  12370. * Unit test for the wc_InitSha()
  12371. */
  12372. static int test_wc_InitSha(void)
  12373. {
  12374. EXPECT_DECLS;
  12375. #ifndef NO_SHA
  12376. wc_Sha sha;
  12377. /* Test good arg. */
  12378. ExpectIntEQ(wc_InitSha(&sha), 0);
  12379. /* Test bad arg. */
  12380. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12381. wc_ShaFree(&sha);
  12382. #endif
  12383. return EXPECT_RESULT();
  12384. } /* END test_wc_InitSha */
  12385. /*
  12386. * Tesing wc_ShaUpdate()
  12387. */
  12388. static int test_wc_ShaUpdate(void)
  12389. {
  12390. EXPECT_DECLS;
  12391. #ifndef NO_SHA
  12392. wc_Sha sha;
  12393. byte hash[WC_SHA_DIGEST_SIZE];
  12394. testVector a, b, c;
  12395. ExpectIntEQ(wc_InitSha(&sha), 0);
  12396. /* Input. */
  12397. a.input = "a";
  12398. a.inLen = XSTRLEN(a.input);
  12399. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12400. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12401. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12402. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12403. /* Update input. */
  12404. a.input = "abc";
  12405. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12406. "\x6C\x9C\xD0\xD8\x9D";
  12407. a.inLen = XSTRLEN(a.input);
  12408. a.outLen = XSTRLEN(a.output);
  12409. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12410. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12411. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12412. /* Try passing in bad values. */
  12413. b.input = NULL;
  12414. b.inLen = 0;
  12415. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12416. c.input = NULL;
  12417. c.inLen = WC_SHA_DIGEST_SIZE;
  12418. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12419. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12420. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12421. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12422. wc_ShaFree(&sha);
  12423. #endif
  12424. return EXPECT_RESULT();
  12425. } /* END test_wc_ShaUpdate() */
  12426. /*
  12427. * Unit test on wc_ShaFinal
  12428. */
  12429. static int test_wc_ShaFinal(void)
  12430. {
  12431. EXPECT_DECLS;
  12432. #ifndef NO_SHA
  12433. wc_Sha sha;
  12434. byte* hash_test[3];
  12435. byte hash1[WC_SHA_DIGEST_SIZE];
  12436. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12437. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12438. int times, i;
  12439. /* Initialize*/
  12440. ExpectIntEQ(wc_InitSha(&sha), 0);
  12441. hash_test[0] = hash1;
  12442. hash_test[1] = hash2;
  12443. hash_test[2] = hash3;
  12444. times = sizeof(hash_test)/sizeof(byte*);
  12445. for (i = 0; i < times; i++) {
  12446. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12447. }
  12448. /* Test bad args. */
  12449. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12450. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12451. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12452. wc_ShaFree(&sha);
  12453. #endif
  12454. return EXPECT_RESULT();
  12455. } /* END test_wc_ShaFinal */
  12456. /*
  12457. * Unit test for wc_InitSha256()
  12458. */
  12459. static int test_wc_InitSha256(void)
  12460. {
  12461. EXPECT_DECLS;
  12462. #ifndef NO_SHA256
  12463. wc_Sha256 sha256;
  12464. /* Test good arg. */
  12465. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12466. /* Test bad arg. */
  12467. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12468. wc_Sha256Free(&sha256);
  12469. #endif
  12470. return EXPECT_RESULT();
  12471. } /* END test_wc_InitSha256 */
  12472. /*
  12473. * Unit test for wc_Sha256Update()
  12474. */
  12475. static int test_wc_Sha256Update(void)
  12476. {
  12477. EXPECT_DECLS;
  12478. #ifndef NO_SHA256
  12479. wc_Sha256 sha256;
  12480. byte hash[WC_SHA256_DIGEST_SIZE];
  12481. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12482. testVector a, b, c;
  12483. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12484. /* Input. */
  12485. a.input = "a";
  12486. a.inLen = XSTRLEN(a.input);
  12487. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12488. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12489. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12490. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12491. /* Update input. */
  12492. a.input = "abc";
  12493. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12494. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12495. "\x15\xAD";
  12496. a.inLen = XSTRLEN(a.input);
  12497. a.outLen = XSTRLEN(a.output);
  12498. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12499. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12500. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12501. /* Unaligned check. */
  12502. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12503. 0);
  12504. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12505. /* Try passing in bad values */
  12506. b.input = NULL;
  12507. b.inLen = 0;
  12508. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12509. c.input = NULL;
  12510. c.inLen = WC_SHA256_DIGEST_SIZE;
  12511. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12513. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12514. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12515. wc_Sha256Free(&sha256);
  12516. #endif
  12517. return EXPECT_RESULT();
  12518. } /* END test_wc_Sha256Update */
  12519. /*
  12520. * Unit test function for wc_Sha256Final()
  12521. */
  12522. static int test_wc_Sha256Final(void)
  12523. {
  12524. EXPECT_DECLS;
  12525. #ifndef NO_SHA256
  12526. wc_Sha256 sha256;
  12527. byte* hash_test[3];
  12528. byte hash1[WC_SHA256_DIGEST_SIZE];
  12529. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12530. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12531. int times, i;
  12532. /* Initialize */
  12533. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12534. hash_test[0] = hash1;
  12535. hash_test[1] = hash2;
  12536. hash_test[2] = hash3;
  12537. times = sizeof(hash_test) / sizeof(byte*);
  12538. for (i = 0; i < times; i++) {
  12539. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12540. }
  12541. /* Test bad args. */
  12542. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12543. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12544. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12545. wc_Sha256Free(&sha256);
  12546. #endif
  12547. return EXPECT_RESULT();
  12548. } /* END test_wc_Sha256Final */
  12549. /*
  12550. * Unit test function for wc_Sha256FinalRaw()
  12551. */
  12552. static int test_wc_Sha256FinalRaw(void)
  12553. {
  12554. EXPECT_DECLS;
  12555. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12556. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12557. !defined(WOLFSSL_NO_HASH_RAW)
  12558. wc_Sha256 sha256;
  12559. byte* hash_test[3];
  12560. byte hash1[WC_SHA256_DIGEST_SIZE];
  12561. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12562. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12563. int times, i;
  12564. /* Initialize */
  12565. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12566. hash_test[0] = hash1;
  12567. hash_test[1] = hash2;
  12568. hash_test[2] = hash3;
  12569. times = sizeof(hash_test) / sizeof(byte*);
  12570. for (i = 0; i < times; i++) {
  12571. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12572. }
  12573. /* Test bad args. */
  12574. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12575. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12576. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12577. wc_Sha256Free(&sha256);
  12578. #endif
  12579. return EXPECT_RESULT();
  12580. } /* END test_wc_Sha256FinalRaw */
  12581. /*
  12582. * Unit test function for wc_Sha256GetFlags()
  12583. */
  12584. static int test_wc_Sha256GetFlags(void)
  12585. {
  12586. EXPECT_DECLS;
  12587. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12588. wc_Sha256 sha256;
  12589. word32 flags = 0;
  12590. /* Initialize */
  12591. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12592. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12593. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12594. wc_Sha256Free(&sha256);
  12595. #endif
  12596. return EXPECT_RESULT();
  12597. } /* END test_wc_Sha256GetFlags */
  12598. /*
  12599. * Unit test function for wc_Sha256Free()
  12600. */
  12601. static int test_wc_Sha256Free(void)
  12602. {
  12603. EXPECT_DECLS;
  12604. #ifndef NO_SHA256
  12605. wc_Sha256Free(NULL);
  12606. /* Set result to SUCCESS. */
  12607. ExpectTrue(1);
  12608. #endif
  12609. return EXPECT_RESULT();
  12610. } /* END test_wc_Sha256Free */
  12611. /*
  12612. * Unit test function for wc_Sha256GetHash()
  12613. */
  12614. static int test_wc_Sha256GetHash(void)
  12615. {
  12616. EXPECT_DECLS;
  12617. #ifndef NO_SHA256
  12618. wc_Sha256 sha256;
  12619. byte hash1[WC_SHA256_DIGEST_SIZE];
  12620. /* Initialize */
  12621. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12622. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12623. /* test bad arguments*/
  12624. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12625. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12626. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12627. wc_Sha256Free(&sha256);
  12628. #endif
  12629. return EXPECT_RESULT();
  12630. } /* END test_wc_Sha256GetHash */
  12631. /*
  12632. * Unit test function for wc_Sha256Copy()
  12633. */
  12634. static int test_wc_Sha256Copy(void)
  12635. {
  12636. EXPECT_DECLS;
  12637. #ifndef NO_SHA256
  12638. wc_Sha256 sha256;
  12639. wc_Sha256 temp;
  12640. XMEMSET(&sha256, 0, sizeof(sha256));
  12641. XMEMSET(&temp, 0, sizeof(temp));
  12642. /* Initialize */
  12643. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12644. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12645. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12646. /* test bad arguments*/
  12647. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12648. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12649. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12650. wc_Sha256Free(&sha256);
  12651. wc_Sha256Free(&temp);
  12652. #endif
  12653. return EXPECT_RESULT();
  12654. } /* END test_wc_Sha256Copy */
  12655. /*
  12656. * Testing wc_InitSha512()
  12657. */
  12658. static int test_wc_InitSha512(void)
  12659. {
  12660. EXPECT_DECLS;
  12661. #ifdef WOLFSSL_SHA512
  12662. wc_Sha512 sha512;
  12663. /* Test good arg. */
  12664. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12665. /* Test bad arg. */
  12666. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12667. wc_Sha512Free(&sha512);
  12668. #endif
  12669. return EXPECT_RESULT();
  12670. } /* END test_wc_InitSha512 */
  12671. /*
  12672. * wc_Sha512Update() test.
  12673. */
  12674. static int test_wc_Sha512Update(void)
  12675. {
  12676. EXPECT_DECLS;
  12677. #ifdef WOLFSSL_SHA512
  12678. wc_Sha512 sha512;
  12679. byte hash[WC_SHA512_DIGEST_SIZE];
  12680. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  12681. testVector a, b, c;
  12682. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12683. /* Input. */
  12684. a.input = "a";
  12685. a.inLen = XSTRLEN(a.input);
  12686. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  12687. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  12688. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  12689. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12690. /* Update input. */
  12691. a.input = "abc";
  12692. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  12693. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  12694. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  12695. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  12696. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  12697. a.inLen = XSTRLEN(a.input);
  12698. a.outLen = XSTRLEN(a.output);
  12699. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  12700. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12701. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  12702. /* Unaligned check. */
  12703. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  12704. 0);
  12705. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  12706. /* Try passing in bad values */
  12707. b.input = NULL;
  12708. b.inLen = 0;
  12709. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  12710. c.input = NULL;
  12711. c.inLen = WC_SHA512_DIGEST_SIZE;
  12712. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12713. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12714. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  12715. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12716. wc_Sha512Free(&sha512);
  12717. #endif
  12718. return EXPECT_RESULT();
  12719. } /* END test_wc_Sha512Update */
  12720. #ifdef WOLFSSL_SHA512
  12721. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12722. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12723. /* Performs test for
  12724. * - wc_Sha512Final/wc_Sha512FinalRaw
  12725. * - wc_Sha512_224Final/wc_Sha512_224Final
  12726. * - wc_Sha512_256Final/wc_Sha512_256Final
  12727. * parameter:
  12728. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  12729. * WC_HASH_TYPE_SHA512_256
  12730. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  12731. *return 0 on success
  12732. */
  12733. static int test_Sha512_Family_Final(int type, int isRaw)
  12734. {
  12735. EXPECT_DECLS;
  12736. wc_Sha512 sha512;
  12737. byte* hash_test[3];
  12738. byte hash1[WC_SHA512_DIGEST_SIZE];
  12739. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12740. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12741. int times, i;
  12742. int(*initFp)(wc_Sha512*);
  12743. int(*finalFp)(wc_Sha512*, byte*);
  12744. void(*freeFp)(wc_Sha512*);
  12745. if (type == WC_HASH_TYPE_SHA512) {
  12746. initFp = wc_InitSha512;
  12747. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12748. !defined(WOLFSSL_NO_HASH_RAW)
  12749. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  12750. #else
  12751. finalFp = (isRaw)? NULL : wc_Sha512Final;
  12752. #endif
  12753. freeFp = wc_Sha512Free;
  12754. }
  12755. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12756. #if !defined(WOLFSSL_NOSHA512_224)
  12757. else if (type == WC_HASH_TYPE_SHA512_224) {
  12758. initFp = wc_InitSha512_224;
  12759. #if !defined(WOLFSSL_NO_HASH_RAW)
  12760. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  12761. #else
  12762. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  12763. #endif
  12764. freeFp = wc_Sha512_224Free;
  12765. }
  12766. #endif
  12767. #if !defined(WOLFSSL_NOSHA512_256)
  12768. else if (type == WC_HASH_TYPE_SHA512_256) {
  12769. initFp = wc_InitSha512_256;
  12770. #if !defined(WOLFSSL_NO_HASH_RAW)
  12771. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  12772. #else
  12773. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  12774. #endif
  12775. freeFp = wc_Sha512_256Free;
  12776. }
  12777. #endif
  12778. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12779. else
  12780. return TEST_FAIL;
  12781. /* Initialize */
  12782. ExpectIntEQ(initFp(&sha512), 0);
  12783. hash_test[0] = hash1;
  12784. hash_test[1] = hash2;
  12785. hash_test[2] = hash3;
  12786. times = sizeof(hash_test) / sizeof(byte *);
  12787. /* Good test args. */
  12788. for (i = 0; i < times; i++) {
  12789. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  12790. }
  12791. /* Test bad args. */
  12792. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12793. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12794. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12795. freeFp(&sha512);
  12796. return EXPECT_RESULT();
  12797. }
  12798. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  12799. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  12800. #endif /* WOLFSSL_SHA512 */
  12801. /*
  12802. * Unit test function for wc_Sha512Final()
  12803. */
  12804. static int test_wc_Sha512Final(void)
  12805. {
  12806. EXPECT_DECLS;
  12807. #ifdef WOLFSSL_SHA512
  12808. wc_Sha512 sha512;
  12809. byte* hash_test[3];
  12810. byte hash1[WC_SHA512_DIGEST_SIZE];
  12811. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12812. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12813. int times, i;
  12814. /* Initialize */
  12815. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12816. hash_test[0] = hash1;
  12817. hash_test[1] = hash2;
  12818. hash_test[2] = hash3;
  12819. times = sizeof(hash_test) / sizeof(byte *);
  12820. for (i = 0; i < times; i++) {
  12821. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  12822. }
  12823. /* Test bad args. */
  12824. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12825. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12826. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12827. wc_Sha512Free(&sha512);
  12828. #endif
  12829. return EXPECT_RESULT();
  12830. } /* END test_wc_Sha512Final */
  12831. /*
  12832. * Unit test function for wc_Sha512GetFlags()
  12833. */
  12834. static int test_wc_Sha512GetFlags(void)
  12835. {
  12836. EXPECT_DECLS;
  12837. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  12838. wc_Sha512 sha512;
  12839. word32 flags = 0;
  12840. /* Initialize */
  12841. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12842. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  12843. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  12844. wc_Sha512Free(&sha512);
  12845. #endif
  12846. return EXPECT_RESULT();
  12847. } /* END test_wc_Sha512GetFlags */
  12848. /*
  12849. * Unit test function for wc_Sha512FinalRaw()
  12850. */
  12851. static int test_wc_Sha512FinalRaw(void)
  12852. {
  12853. EXPECT_DECLS;
  12854. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  12855. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  12856. !defined(WOLFSSL_NO_HASH_RAW)
  12857. wc_Sha512 sha512;
  12858. byte* hash_test[3];
  12859. byte hash1[WC_SHA512_DIGEST_SIZE];
  12860. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12861. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12862. int times, i;
  12863. /* Initialize */
  12864. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12865. hash_test[0] = hash1;
  12866. hash_test[1] = hash2;
  12867. hash_test[2] = hash3;
  12868. times = sizeof(hash_test) / sizeof(byte*);
  12869. /* Good test args. */
  12870. for (i = 0; i < times; i++) {
  12871. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  12872. }
  12873. /* Test bad args. */
  12874. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12875. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12876. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12877. wc_Sha512Free(&sha512);
  12878. #endif
  12879. return EXPECT_RESULT();
  12880. } /* END test_wc_Sha512FinalRaw */
  12881. /*
  12882. * Unit test function for wc_Sha512Free()
  12883. */
  12884. static int test_wc_Sha512Free(void)
  12885. {
  12886. EXPECT_DECLS;
  12887. #ifdef WOLFSSL_SHA512
  12888. wc_Sha512Free(NULL);
  12889. /* Set result to SUCCESS. */
  12890. ExpectTrue(1);
  12891. #endif
  12892. return EXPECT_RESULT();
  12893. } /* END test_wc_Sha512Free */
  12894. #ifdef WOLFSSL_SHA512
  12895. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12896. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12897. static int test_Sha512_Family_GetHash(int type )
  12898. {
  12899. EXPECT_DECLS;
  12900. int(*initFp)(wc_Sha512*);
  12901. int(*ghashFp)(wc_Sha512*, byte*);
  12902. wc_Sha512 sha512;
  12903. byte hash1[WC_SHA512_DIGEST_SIZE];
  12904. if (type == WC_HASH_TYPE_SHA512) {
  12905. initFp = wc_InitSha512;
  12906. ghashFp = wc_Sha512GetHash;
  12907. }
  12908. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12909. #if !defined(WOLFSSL_NOSHA512_224)
  12910. else if (type == WC_HASH_TYPE_SHA512_224) {
  12911. initFp = wc_InitSha512_224;
  12912. ghashFp = wc_Sha512_224GetHash;
  12913. }
  12914. #endif
  12915. #if !defined(WOLFSSL_NOSHA512_256)
  12916. else if (type == WC_HASH_TYPE_SHA512_256) {
  12917. initFp = wc_InitSha512_256;
  12918. ghashFp = wc_Sha512_256GetHash;
  12919. }
  12920. #endif
  12921. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12922. else {
  12923. initFp = NULL;
  12924. ghashFp = NULL;
  12925. }
  12926. if (initFp == NULL || ghashFp == NULL)
  12927. return TEST_FAIL;
  12928. ExpectIntEQ(initFp(&sha512), 0);
  12929. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  12930. /* test bad arguments*/
  12931. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12932. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12933. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12934. wc_Sha512Free(&sha512);
  12935. return EXPECT_RESULT();
  12936. }
  12937. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  12938. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  12939. #endif /* WOLFSSL_SHA512 */
  12940. /*
  12941. * Unit test function for wc_Sha512GetHash()
  12942. */
  12943. static int test_wc_Sha512GetHash(void)
  12944. {
  12945. EXPECT_DECLS;
  12946. #ifdef WOLFSSL_SHA512
  12947. wc_Sha512 sha512;
  12948. byte hash1[WC_SHA512_DIGEST_SIZE];
  12949. /* Initialize */
  12950. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12951. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  12952. /* test bad arguments*/
  12953. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12954. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12955. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12956. wc_Sha512Free(&sha512);
  12957. #endif
  12958. return EXPECT_RESULT();
  12959. } /* END test_wc_Sha512GetHash */
  12960. /*
  12961. * Unit test function for wc_Sha512Copy()
  12962. */
  12963. static int test_wc_Sha512Copy(void)
  12964. {
  12965. EXPECT_DECLS;
  12966. #ifdef WOLFSSL_SHA512
  12967. wc_Sha512 sha512;
  12968. wc_Sha512 temp;
  12969. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  12970. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  12971. /* Initialize */
  12972. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12973. ExpectIntEQ(wc_InitSha512(&temp), 0);
  12974. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  12975. /* test bad arguments*/
  12976. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12977. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12978. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12979. wc_Sha512Free(&sha512);
  12980. wc_Sha512Free(&temp);
  12981. #endif
  12982. return EXPECT_RESULT();
  12983. } /* END test_wc_Sha512Copy */
  12984. static int test_wc_InitSha512_224(void)
  12985. {
  12986. EXPECT_DECLS;
  12987. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12988. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  12989. wc_Sha512 sha512;
  12990. /* Test good arg. */
  12991. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  12992. /* Test bad arg. */
  12993. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12994. wc_Sha512_224Free(&sha512);
  12995. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  12996. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12997. return EXPECT_RESULT();
  12998. }
  12999. static int test_wc_Sha512_224Update(void)
  13000. {
  13001. EXPECT_DECLS;
  13002. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13003. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13004. wc_Sha512 sha512;
  13005. byte hash[WC_SHA512_DIGEST_SIZE];
  13006. testVector a, c;
  13007. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13008. /* Input. */
  13009. a.input = "a";
  13010. a.inLen = XSTRLEN(a.input);
  13011. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  13012. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  13013. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13014. 0);
  13015. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13016. /* Update input. */
  13017. a.input = "abc";
  13018. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  13019. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  13020. a.inLen = XSTRLEN(a.input);
  13021. a.outLen = XSTRLEN(a.output);
  13022. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13023. 0);
  13024. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13025. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  13026. c.input = NULL;
  13027. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  13028. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13029. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13030. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13031. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13032. wc_Sha512_224Free(&sha512);
  13033. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13034. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13035. return EXPECT_RESULT();
  13036. }
  13037. static int test_wc_Sha512_224Final(void)
  13038. {
  13039. EXPECT_DECLS;
  13040. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13041. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13042. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  13043. TEST_SUCCESS);
  13044. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13045. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13046. return EXPECT_RESULT();
  13047. }
  13048. static int test_wc_Sha512_224GetFlags(void)
  13049. {
  13050. EXPECT_DECLS;
  13051. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13052. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  13053. wc_Sha512 sha512;
  13054. wc_Sha512 copy;
  13055. word32 flags = 0;
  13056. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13057. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13058. /* Initialize */
  13059. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13060. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  13061. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  13062. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13063. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  13064. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  13065. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13066. wc_Sha512_224Free(&copy);
  13067. wc_Sha512_224Free(&sha512);
  13068. #endif
  13069. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13070. return EXPECT_RESULT();
  13071. }
  13072. static int test_wc_Sha512_224FinalRaw(void)
  13073. {
  13074. EXPECT_DECLS;
  13075. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13076. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  13077. !defined(WOLFSSL_NO_HASH_RAW)
  13078. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  13079. TEST_SUCCESS);
  13080. #endif
  13081. return EXPECT_RESULT();
  13082. }
  13083. static int test_wc_Sha512_224Free(void)
  13084. {
  13085. EXPECT_DECLS;
  13086. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13087. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13088. wc_Sha512_224Free(NULL);
  13089. /* Set result to SUCCESS. */
  13090. ExpectTrue(1);
  13091. #endif
  13092. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13093. return EXPECT_RESULT();
  13094. }
  13095. static int test_wc_Sha512_224GetHash(void)
  13096. {
  13097. EXPECT_DECLS;
  13098. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13099. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13100. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  13101. TEST_SUCCESS);
  13102. #endif
  13103. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13104. return EXPECT_RESULT();
  13105. }
  13106. static int test_wc_Sha512_224Copy(void)
  13107. {
  13108. EXPECT_DECLS;
  13109. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13110. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13111. wc_Sha512 sha512;
  13112. wc_Sha512 temp;
  13113. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13114. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13115. /* Initialize */
  13116. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13117. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  13118. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  13119. /* test bad arguments*/
  13120. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13121. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13122. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13123. wc_Sha512_224Free(&sha512);
  13124. wc_Sha512_224Free(&temp);
  13125. #endif
  13126. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13127. return EXPECT_RESULT();
  13128. }
  13129. static int test_wc_InitSha512_256(void)
  13130. {
  13131. EXPECT_DECLS;
  13132. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13133. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13134. wc_Sha512 sha512;
  13135. /* Test good arg. */
  13136. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13137. /* Test bad arg. */
  13138. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13139. wc_Sha512_256Free(&sha512);
  13140. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13141. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13142. return EXPECT_RESULT();
  13143. }
  13144. static int test_wc_Sha512_256Update(void)
  13145. {
  13146. EXPECT_DECLS;
  13147. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13148. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13149. wc_Sha512 sha512;
  13150. byte hash[WC_SHA512_DIGEST_SIZE];
  13151. testVector a, c;
  13152. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13153. /* Input. */
  13154. a.input = "a";
  13155. a.inLen = XSTRLEN(a.input);
  13156. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  13157. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  13158. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13159. 0);
  13160. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13161. /* Update input. */
  13162. a.input = "abc";
  13163. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  13164. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  13165. "\x07\xe7\xaf\x23";
  13166. a.inLen = XSTRLEN(a.input);
  13167. a.outLen = XSTRLEN(a.output);
  13168. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13169. 0);
  13170. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13171. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  13172. c.input = NULL;
  13173. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  13174. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13175. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13176. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  13177. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13178. wc_Sha512_256Free(&sha512);
  13179. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13180. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13181. return EXPECT_RESULT();
  13182. }
  13183. static int test_wc_Sha512_256Final(void)
  13184. {
  13185. EXPECT_DECLS;
  13186. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13187. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13188. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  13189. TEST_SUCCESS);
  13190. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13191. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13192. return EXPECT_RESULT();
  13193. }
  13194. static int test_wc_Sha512_256GetFlags(void)
  13195. {
  13196. EXPECT_DECLS;
  13197. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13198. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  13199. wc_Sha512 sha512, copy;
  13200. word32 flags = 0;
  13201. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13202. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13203. /* Initialize */
  13204. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13205. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  13206. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  13207. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13208. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  13209. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  13210. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13211. wc_Sha512_256Free(&sha512);
  13212. #endif
  13213. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13214. return EXPECT_RESULT();
  13215. }
  13216. static int test_wc_Sha512_256FinalRaw(void)
  13217. {
  13218. EXPECT_DECLS;
  13219. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13220. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13221. !defined(WOLFSSL_NO_HASH_RAW)
  13222. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13223. TEST_SUCCESS);
  13224. #endif
  13225. return EXPECT_RESULT();
  13226. }
  13227. static int test_wc_Sha512_256Free(void)
  13228. {
  13229. EXPECT_DECLS;
  13230. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13231. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13232. wc_Sha512_256Free(NULL);
  13233. /* Set result to SUCCESS. */
  13234. ExpectTrue(1);
  13235. #endif
  13236. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13237. return EXPECT_RESULT();
  13238. }
  13239. static int test_wc_Sha512_256GetHash(void)
  13240. {
  13241. EXPECT_DECLS;
  13242. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13243. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13244. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13245. TEST_SUCCESS);
  13246. #endif
  13247. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13248. return EXPECT_RESULT();
  13249. }
  13250. static int test_wc_Sha512_256Copy(void)
  13251. {
  13252. EXPECT_DECLS;
  13253. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13254. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13255. wc_Sha512 sha512;
  13256. wc_Sha512 temp;
  13257. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13258. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13259. /* Initialize */
  13260. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13261. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13262. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13263. /* test bad arguments*/
  13264. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13265. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13266. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13267. wc_Sha512_256Free(&sha512);
  13268. wc_Sha512_256Free(&temp);
  13269. #endif
  13270. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13271. return EXPECT_RESULT();
  13272. }
  13273. /*
  13274. * Testing wc_InitSha384()
  13275. */
  13276. static int test_wc_InitSha384(void)
  13277. {
  13278. EXPECT_DECLS;
  13279. #ifdef WOLFSSL_SHA384
  13280. wc_Sha384 sha384;
  13281. /* Test good arg. */
  13282. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13283. /* Test bad arg. */
  13284. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13285. wc_Sha384Free(&sha384);
  13286. #endif
  13287. return EXPECT_RESULT();
  13288. } /* END test_wc_InitSha384 */
  13289. /*
  13290. * test wc_Sha384Update()
  13291. */
  13292. static int test_wc_Sha384Update(void)
  13293. {
  13294. EXPECT_DECLS;
  13295. #ifdef WOLFSSL_SHA384
  13296. wc_Sha384 sha384;
  13297. byte hash[WC_SHA384_DIGEST_SIZE];
  13298. testVector a, b, c;
  13299. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13300. /* Input */
  13301. a.input = "a";
  13302. a.inLen = XSTRLEN(a.input);
  13303. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13304. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13305. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13306. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13307. /* Update input. */
  13308. a.input = "abc";
  13309. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13310. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13311. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13312. "\xc8\x25\xa7";
  13313. a.inLen = XSTRLEN(a.input);
  13314. a.outLen = XSTRLEN(a.output);
  13315. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13316. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13317. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13318. /* Pass in bad values. */
  13319. b.input = NULL;
  13320. b.inLen = 0;
  13321. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13322. c.input = NULL;
  13323. c.inLen = WC_SHA384_DIGEST_SIZE;
  13324. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13325. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13326. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13327. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13328. wc_Sha384Free(&sha384);
  13329. #endif
  13330. return EXPECT_RESULT();
  13331. } /* END test_wc_Sha384Update */
  13332. /*
  13333. * Unit test function for wc_Sha384Final();
  13334. */
  13335. static int test_wc_Sha384Final(void)
  13336. {
  13337. EXPECT_DECLS;
  13338. #ifdef WOLFSSL_SHA384
  13339. wc_Sha384 sha384;
  13340. byte* hash_test[3];
  13341. byte hash1[WC_SHA384_DIGEST_SIZE];
  13342. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13343. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13344. int times, i;
  13345. /* Initialize */
  13346. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13347. hash_test[0] = hash1;
  13348. hash_test[1] = hash2;
  13349. hash_test[2] = hash3;
  13350. times = sizeof(hash_test) / sizeof(byte*);
  13351. /* Good test args. */
  13352. for (i = 0; i < times; i++) {
  13353. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13354. }
  13355. /* Test bad args. */
  13356. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13357. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13358. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13359. wc_Sha384Free(&sha384);
  13360. #endif
  13361. return EXPECT_RESULT();
  13362. } /* END test_wc_Sha384Final */
  13363. /*
  13364. * Unit test function for wc_Sha384GetFlags()
  13365. */
  13366. static int test_wc_Sha384GetFlags(void)
  13367. {
  13368. EXPECT_DECLS;
  13369. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13370. wc_Sha384 sha384;
  13371. word32 flags = 0;
  13372. /* Initialize */
  13373. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13374. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13375. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13376. wc_Sha384Free(&sha384);
  13377. #endif
  13378. return EXPECT_RESULT();
  13379. } /* END test_wc_Sha384GetFlags */
  13380. /*
  13381. * Unit test function for wc_Sha384FinalRaw()
  13382. */
  13383. static int test_wc_Sha384FinalRaw(void)
  13384. {
  13385. EXPECT_DECLS;
  13386. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13387. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13388. !defined(WOLFSSL_NO_HASH_RAW)
  13389. wc_Sha384 sha384;
  13390. byte* hash_test[3];
  13391. byte hash1[WC_SHA384_DIGEST_SIZE];
  13392. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13393. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13394. int times, i;
  13395. /* Initialize */
  13396. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13397. hash_test[0] = hash1;
  13398. hash_test[1] = hash2;
  13399. hash_test[2] = hash3;
  13400. times = sizeof(hash_test) / sizeof(byte*);
  13401. /* Good test args. */
  13402. for (i = 0; i < times; i++) {
  13403. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13404. }
  13405. /* Test bad args. */
  13406. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13407. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13408. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13409. wc_Sha384Free(&sha384);
  13410. #endif
  13411. return EXPECT_RESULT();
  13412. } /* END test_wc_Sha384FinalRaw */
  13413. /*
  13414. * Unit test function for wc_Sha384Free()
  13415. */
  13416. static int test_wc_Sha384Free(void)
  13417. {
  13418. EXPECT_DECLS;
  13419. #ifdef WOLFSSL_SHA384
  13420. wc_Sha384Free(NULL);
  13421. /* Set result to SUCCESS. */
  13422. ExpectTrue(1);
  13423. #endif
  13424. return EXPECT_RESULT();
  13425. } /* END test_wc_Sha384Free */
  13426. /*
  13427. * Unit test function for wc_Sha384GetHash()
  13428. */
  13429. static int test_wc_Sha384GetHash(void)
  13430. {
  13431. EXPECT_DECLS;
  13432. #ifdef WOLFSSL_SHA384
  13433. wc_Sha384 sha384;
  13434. byte hash1[WC_SHA384_DIGEST_SIZE];
  13435. /* Initialize */
  13436. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13437. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13438. /* test bad arguments*/
  13439. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13440. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13441. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13442. wc_Sha384Free(&sha384);
  13443. #endif
  13444. return EXPECT_RESULT();
  13445. } /* END test_wc_Sha384GetHash */
  13446. /*
  13447. * Unit test function for wc_Sha384Copy()
  13448. */
  13449. static int test_wc_Sha384Copy(void)
  13450. {
  13451. EXPECT_DECLS;
  13452. #ifdef WOLFSSL_SHA384
  13453. wc_Sha384 sha384;
  13454. wc_Sha384 temp;
  13455. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13456. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13457. /* Initialize */
  13458. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13459. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13460. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13461. /* test bad arguments*/
  13462. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13463. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13464. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13465. wc_Sha384Free(&sha384);
  13466. wc_Sha384Free(&temp);
  13467. #endif
  13468. return EXPECT_RESULT();
  13469. } /* END test_wc_Sha384Copy */
  13470. /*
  13471. * Testing wc_InitSha224();
  13472. */
  13473. static int test_wc_InitSha224(void)
  13474. {
  13475. EXPECT_DECLS;
  13476. #ifdef WOLFSSL_SHA224
  13477. wc_Sha224 sha224;
  13478. /* Test good arg. */
  13479. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13480. /* Test bad arg. */
  13481. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13482. wc_Sha224Free(&sha224);
  13483. #endif
  13484. return EXPECT_RESULT();
  13485. } /* END test_wc_InitSha224 */
  13486. /*
  13487. * Unit test on wc_Sha224Update
  13488. */
  13489. static int test_wc_Sha224Update(void)
  13490. {
  13491. EXPECT_DECLS;
  13492. #ifdef WOLFSSL_SHA224
  13493. wc_Sha224 sha224;
  13494. byte hash[WC_SHA224_DIGEST_SIZE];
  13495. testVector a, b, c;
  13496. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13497. /* Input. */
  13498. a.input = "a";
  13499. a.inLen = XSTRLEN(a.input);
  13500. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13501. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13502. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13503. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13504. /* Update input. */
  13505. a.input = "abc";
  13506. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13507. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13508. a.inLen = XSTRLEN(a.input);
  13509. a.outLen = XSTRLEN(a.output);
  13510. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13511. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13512. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13513. /* Pass in bad values. */
  13514. b.input = NULL;
  13515. b.inLen = 0;
  13516. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13517. c.input = NULL;
  13518. c.inLen = WC_SHA224_DIGEST_SIZE;
  13519. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13520. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13521. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13522. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13523. wc_Sha224Free(&sha224);
  13524. #endif
  13525. return EXPECT_RESULT();
  13526. } /* END test_wc_Sha224Update */
  13527. /*
  13528. * Unit test for wc_Sha224Final();
  13529. */
  13530. static int test_wc_Sha224Final(void)
  13531. {
  13532. EXPECT_DECLS;
  13533. #ifdef WOLFSSL_SHA224
  13534. wc_Sha224 sha224;
  13535. byte* hash_test[3];
  13536. byte hash1[WC_SHA224_DIGEST_SIZE];
  13537. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13538. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13539. int times, i;
  13540. /* Initialize */
  13541. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13542. hash_test[0] = hash1;
  13543. hash_test[1] = hash2;
  13544. hash_test[2] = hash3;
  13545. times = sizeof(hash_test) / sizeof(byte*);
  13546. /* Good test args. */
  13547. /* Testing oversized buffers. */
  13548. for (i = 0; i < times; i++) {
  13549. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13550. }
  13551. /* Test bad args. */
  13552. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13553. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13554. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13555. wc_Sha224Free(&sha224);
  13556. #endif
  13557. return EXPECT_RESULT();
  13558. } /* END test_wc_Sha224Final */
  13559. /*
  13560. * Unit test function for wc_Sha224SetFlags()
  13561. */
  13562. static int test_wc_Sha224SetFlags(void)
  13563. {
  13564. EXPECT_DECLS;
  13565. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13566. wc_Sha224 sha224;
  13567. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13568. /* Initialize */
  13569. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13570. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13571. flags = 0;
  13572. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13573. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13574. wc_Sha224Free(&sha224);
  13575. #endif
  13576. return EXPECT_RESULT();
  13577. } /* END test_wc_Sha224SetFlags */
  13578. /*
  13579. * Unit test function for wc_Sha224GetFlags()
  13580. */
  13581. static int test_wc_Sha224GetFlags(void)
  13582. {
  13583. EXPECT_DECLS;
  13584. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13585. wc_Sha224 sha224;
  13586. word32 flags = 0;
  13587. /* Initialize */
  13588. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13589. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13590. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13591. wc_Sha224Free(&sha224);
  13592. #endif
  13593. return EXPECT_RESULT();
  13594. } /* END test_wc_Sha224GetFlags */
  13595. /*
  13596. * Unit test function for wc_Sha224Free()
  13597. */
  13598. static int test_wc_Sha224Free(void)
  13599. {
  13600. EXPECT_DECLS;
  13601. #ifdef WOLFSSL_SHA224
  13602. wc_Sha224Free(NULL);
  13603. /* Set result to SUCCESS. */
  13604. ExpectTrue(1);
  13605. #endif
  13606. return EXPECT_RESULT();
  13607. } /* END test_wc_Sha224Free */
  13608. /*
  13609. * Unit test function for wc_Sha224GetHash()
  13610. */
  13611. static int test_wc_Sha224GetHash(void)
  13612. {
  13613. EXPECT_DECLS;
  13614. #ifdef WOLFSSL_SHA224
  13615. wc_Sha224 sha224;
  13616. byte hash1[WC_SHA224_DIGEST_SIZE];
  13617. /* Initialize */
  13618. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13619. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13620. /* test bad arguments*/
  13621. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13622. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13623. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13624. wc_Sha224Free(&sha224);
  13625. #endif
  13626. return EXPECT_RESULT();
  13627. } /* END test_wc_Sha224GetHash */
  13628. /*
  13629. * Unit test function for wc_Sha224Copy()
  13630. */
  13631. static int test_wc_Sha224Copy(void)
  13632. {
  13633. EXPECT_DECLS;
  13634. #ifdef WOLFSSL_SHA224
  13635. wc_Sha224 sha224;
  13636. wc_Sha224 temp;
  13637. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13638. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13639. /* Initialize */
  13640. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13641. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13642. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  13643. /* test bad arguments*/
  13644. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13645. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13646. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13647. wc_Sha224Free(&sha224);
  13648. wc_Sha224Free(&temp);
  13649. #endif
  13650. return EXPECT_RESULT();
  13651. } /* END test_wc_Sha224Copy */
  13652. /*
  13653. * Testing wc_InitRipeMd()
  13654. */
  13655. static int test_wc_InitRipeMd(void)
  13656. {
  13657. EXPECT_DECLS;
  13658. #ifdef WOLFSSL_RIPEMD
  13659. RipeMd ripemd;
  13660. /* Test good arg. */
  13661. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13662. /* Test bad arg. */
  13663. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13664. #endif
  13665. return EXPECT_RESULT();
  13666. } /* END test_wc_InitRipeMd */
  13667. /*
  13668. * Testing wc_RipeMdUpdate()
  13669. */
  13670. static int test_wc_RipeMdUpdate(void)
  13671. {
  13672. EXPECT_DECLS;
  13673. #ifdef WOLFSSL_RIPEMD
  13674. RipeMd ripemd;
  13675. byte hash[RIPEMD_DIGEST_SIZE];
  13676. testVector a, b, c;
  13677. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13678. /* Input */
  13679. a.input = "a";
  13680. a.inLen = XSTRLEN(a.input);
  13681. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13682. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13683. /* Update input. */
  13684. a.input = "abc";
  13685. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  13686. "\xb0\x87\xf1\x5a\x0b\xfc";
  13687. a.inLen = XSTRLEN(a.input);
  13688. a.outLen = XSTRLEN(a.output);
  13689. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13690. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13691. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  13692. /* Pass in bad values. */
  13693. b.input = NULL;
  13694. b.inLen = 0;
  13695. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  13696. c.input = NULL;
  13697. c.inLen = RIPEMD_DIGEST_SIZE;
  13698. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  13699. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13700. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  13701. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13702. #endif
  13703. return EXPECT_RESULT();
  13704. } /* END test_wc_RipeMdUdpate */
  13705. /*
  13706. * Unit test function for wc_RipeMdFinal()
  13707. */
  13708. static int test_wc_RipeMdFinal(void)
  13709. {
  13710. EXPECT_DECLS;
  13711. #ifdef WOLFSSL_RIPEMD
  13712. RipeMd ripemd;
  13713. byte* hash_test[3];
  13714. byte hash1[RIPEMD_DIGEST_SIZE];
  13715. byte hash2[2*RIPEMD_DIGEST_SIZE];
  13716. byte hash3[5*RIPEMD_DIGEST_SIZE];
  13717. int times, i;
  13718. /* Initialize */
  13719. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13720. hash_test[0] = hash1;
  13721. hash_test[1] = hash2;
  13722. hash_test[2] = hash3;
  13723. times = sizeof(hash_test) / sizeof(byte*);
  13724. /* Testing oversized buffers. */
  13725. for (i = 0; i < times; i++) {
  13726. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  13727. }
  13728. /* Test bad args. */
  13729. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13730. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13731. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13732. #endif
  13733. return EXPECT_RESULT();
  13734. } /* END test_wc_RipeMdFinal */
  13735. /*
  13736. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  13737. * wc_InitSha3_512
  13738. */
  13739. static int test_wc_InitSha3(void)
  13740. {
  13741. EXPECT_DECLS;
  13742. #if defined(WOLFSSL_SHA3)
  13743. wc_Sha3 sha3;
  13744. (void)sha3;
  13745. #if !defined(WOLFSSL_NOSHA3_224)
  13746. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13747. /* Test bad args. */
  13748. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13749. wc_Sha3_224_Free(&sha3);
  13750. #endif /* NOSHA3_224 */
  13751. #if !defined(WOLFSSL_NOSHA3_256)
  13752. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13753. /* Test bad args. */
  13754. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13755. wc_Sha3_256_Free(&sha3);
  13756. #endif /* NOSHA3_256 */
  13757. #if !defined(WOLFSSL_NOSHA3_384)
  13758. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13759. /* Test bad args. */
  13760. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13761. wc_Sha3_384_Free(&sha3);
  13762. #endif /* NOSHA3_384 */
  13763. #if !defined(WOLFSSL_NOSHA3_512)
  13764. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13765. /* Test bad args. */
  13766. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13767. wc_Sha3_512_Free(&sha3);
  13768. #endif /* NOSHA3_512 */
  13769. #endif
  13770. return EXPECT_RESULT();
  13771. } /* END test_wc_InitSha3 */
  13772. /*
  13773. * Testing wc_Sha3_Update()
  13774. */
  13775. static int testing_wc_Sha3_Update(void)
  13776. {
  13777. EXPECT_DECLS;
  13778. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  13779. !defined(WOLFSSL_AFALG_XILINX)
  13780. wc_Sha3 sha3;
  13781. byte msg[] = "Everybody's working for the weekend.";
  13782. byte msg2[] = "Everybody gets Friday off.";
  13783. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  13784. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  13785. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  13786. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  13787. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  13788. word32 msglen = sizeof(msg) - 1;
  13789. word32 msg2len = sizeof(msg2);
  13790. word32 msgCmplen = sizeof(msgCmp);
  13791. #if !defined(WOLFSSL_NOSHA3_224)
  13792. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13793. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  13794. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13795. ExpectTrue(sha3.i == msglen);
  13796. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  13797. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13798. /* Pass bad args. */
  13799. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13800. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13801. wc_Sha3_224_Free(&sha3);
  13802. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13803. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  13804. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  13805. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13806. wc_Sha3_224_Free(&sha3);
  13807. #endif /* SHA3_224 */
  13808. #if !defined(WOLFSSL_NOSHA3_256)
  13809. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13810. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  13811. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13812. ExpectTrue(sha3.i == msglen);
  13813. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  13814. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13815. /* Pass bad args. */
  13816. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13817. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13818. wc_Sha3_256_Free(&sha3);
  13819. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13820. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  13821. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  13822. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13823. wc_Sha3_256_Free(&sha3);
  13824. #endif /* SHA3_256 */
  13825. #if !defined(WOLFSSL_NOSHA3_384)
  13826. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13827. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  13828. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13829. ExpectTrue(sha3.i == msglen);
  13830. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  13831. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13832. /* Pass bad args. */
  13833. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13834. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13835. wc_Sha3_384_Free(&sha3);
  13836. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13837. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  13838. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  13839. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13840. wc_Sha3_384_Free(&sha3);
  13841. #endif /* SHA3_384 */
  13842. #if !defined(WOLFSSL_NOSHA3_512)
  13843. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13844. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  13845. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  13846. ExpectTrue(sha3.i == msglen);
  13847. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  13848. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  13849. /* Pass bad args. */
  13850. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13851. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13852. wc_Sha3_512_Free(&sha3);
  13853. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13854. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  13855. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  13856. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  13857. wc_Sha3_512_Free(&sha3);
  13858. #endif /* SHA3_512 */
  13859. #endif /* WOLFSSL_SHA3 */
  13860. return EXPECT_RESULT();
  13861. } /* END testing_wc_Sha3_Update */
  13862. /*
  13863. * Testing wc_Sha3_224_Final()
  13864. */
  13865. static int test_wc_Sha3_224_Final(void)
  13866. {
  13867. EXPECT_DECLS;
  13868. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  13869. wc_Sha3 sha3;
  13870. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13871. "nopnopq";
  13872. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  13873. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  13874. "\x64\xea\xd0\xfc\xce\x33";
  13875. byte hash[WC_SHA3_224_DIGEST_SIZE];
  13876. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  13877. /* Init stack variables. */
  13878. XMEMSET(hash, 0, sizeof(hash));
  13879. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13880. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13881. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  13882. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  13883. /* Test bad args. */
  13884. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13885. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13886. wc_Sha3_224_Free(&sha3);
  13887. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13888. /* Init stack variables. */
  13889. XMEMSET(hash, 0, sizeof(hash));
  13890. XMEMSET(hashRet, 0, sizeof(hashRet));
  13891. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13892. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  13893. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  13894. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  13895. /* Test bad args. */
  13896. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13897. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13898. wc_Sha3_224_Free(&sha3);
  13899. #endif
  13900. return EXPECT_RESULT();
  13901. } /* END test_wc_Sha3_224_Final */
  13902. /*
  13903. * Testing wc_Sha3_256_Final()
  13904. */
  13905. static int test_wc_Sha3_256_Final(void)
  13906. {
  13907. EXPECT_DECLS;
  13908. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  13909. wc_Sha3 sha3;
  13910. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13911. "nopnopq";
  13912. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  13913. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  13914. "\xdd\x97\x49\x6d\x33\x76";
  13915. byte hash[WC_SHA3_256_DIGEST_SIZE];
  13916. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  13917. /* Init stack variables. */
  13918. XMEMSET(hash, 0, sizeof(hash));
  13919. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13920. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13921. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  13922. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  13923. /* Test bad args. */
  13924. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13925. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13926. wc_Sha3_256_Free(&sha3);
  13927. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13928. /* Init stack variables. */
  13929. XMEMSET(hash, 0, sizeof(hash));
  13930. XMEMSET(hashRet, 0, sizeof(hashRet));
  13931. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13932. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  13933. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  13934. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  13935. /* Test bad args. */
  13936. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13937. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13938. wc_Sha3_256_Free(&sha3);
  13939. #endif
  13940. return EXPECT_RESULT();
  13941. } /* END test_wc_Sha3_256_Final */
  13942. /*
  13943. * Testing wc_Sha3_384_Final()
  13944. */
  13945. static int test_wc_Sha3_384_Final(void)
  13946. {
  13947. EXPECT_DECLS;
  13948. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  13949. wc_Sha3 sha3;
  13950. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13951. "nopnopq";
  13952. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  13953. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  13954. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  13955. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  13956. byte hash[WC_SHA3_384_DIGEST_SIZE];
  13957. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  13958. /* Init stack variables. */
  13959. XMEMSET(hash, 0, sizeof(hash));
  13960. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13961. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13962. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  13963. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  13964. /* Test bad args. */
  13965. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13966. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13967. wc_Sha3_384_Free(&sha3);
  13968. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13969. /* Init stack variables. */
  13970. XMEMSET(hash, 0, sizeof(hash));
  13971. XMEMSET(hashRet, 0, sizeof(hashRet));
  13972. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  13973. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  13974. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  13975. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  13976. /* Test bad args. */
  13977. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13978. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13979. wc_Sha3_384_Free(&sha3);
  13980. #endif
  13981. return EXPECT_RESULT();
  13982. } /* END test_wc_Sha3_384_Final */
  13983. /*
  13984. * Testing wc_Sha3_512_Final()
  13985. */
  13986. static int test_wc_Sha3_512_Final(void)
  13987. {
  13988. EXPECT_DECLS;
  13989. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  13990. !defined(WOLFSSL_NOSHA3_384)
  13991. wc_Sha3 sha3;
  13992. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  13993. "nopnopq";
  13994. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  13995. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  13996. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  13997. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  13998. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  13999. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14000. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  14001. /* Init stack variables. */
  14002. XMEMSET(hash, 0, sizeof(hash));
  14003. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14004. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14005. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14006. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  14007. /* Test bad args. */
  14008. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14009. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14010. wc_Sha3_512_Free(&sha3);
  14011. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14012. /* Init stack variables. */
  14013. XMEMSET(hash, 0, sizeof(hash));
  14014. XMEMSET(hashRet, 0, sizeof(hashRet));
  14015. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14016. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  14017. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14018. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  14019. /* Test bad args. */
  14020. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14021. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14022. wc_Sha3_512_Free(&sha3);
  14023. #endif
  14024. return EXPECT_RESULT();
  14025. } /* END test_wc_Sha3_512_Final */
  14026. /*
  14027. * Testing wc_Sha3_224_Copy()
  14028. */
  14029. static int test_wc_Sha3_224_Copy(void)
  14030. {
  14031. EXPECT_DECLS;
  14032. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14033. wc_Sha3 sha3, sha3Cpy;
  14034. const char* msg = TEST_STRING;
  14035. word32 msglen = (word32)TEST_STRING_SZ;
  14036. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14037. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  14038. XMEMSET(hash, 0, sizeof(hash));
  14039. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14040. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14041. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14042. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14043. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14044. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  14045. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  14046. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14047. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  14048. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14049. /* Test bad args. */
  14050. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14051. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14052. wc_Sha3_224_Free(&sha3);
  14053. wc_Sha3_224_Free(&sha3Cpy);
  14054. #endif
  14055. return EXPECT_RESULT();
  14056. } /* END test_wc_Sha3_224_Copy */
  14057. /*
  14058. * Testing wc_Sha3_256_Copy()
  14059. */
  14060. static int test_wc_Sha3_256_Copy(void)
  14061. {
  14062. EXPECT_DECLS;
  14063. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14064. wc_Sha3 sha3, sha3Cpy;
  14065. const char* msg = TEST_STRING;
  14066. word32 msglen = (word32)TEST_STRING_SZ;
  14067. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14068. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  14069. XMEMSET(hash, 0, sizeof(hash));
  14070. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14071. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14072. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14073. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14074. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14075. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  14076. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  14077. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14078. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  14079. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14080. /* Test bad args. */
  14081. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14082. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14083. wc_Sha3_256_Free(&sha3);
  14084. wc_Sha3_256_Free(&sha3Cpy);
  14085. #endif
  14086. return EXPECT_RESULT();
  14087. } /* END test_wc_Sha3_256_Copy */
  14088. /*
  14089. * Testing wc_Sha3_384_Copy()
  14090. */
  14091. static int test_wc_Sha3_384_Copy(void)
  14092. {
  14093. EXPECT_DECLS;
  14094. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14095. wc_Sha3 sha3, sha3Cpy;
  14096. const char* msg = TEST_STRING;
  14097. word32 msglen = (word32)TEST_STRING_SZ;
  14098. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14099. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  14100. XMEMSET(hash, 0, sizeof(hash));
  14101. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14102. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14103. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14104. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14105. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14106. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  14107. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  14108. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14109. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  14110. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14111. /* Test bad args. */
  14112. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14113. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14114. wc_Sha3_384_Free(&sha3);
  14115. wc_Sha3_384_Free(&sha3Cpy);
  14116. #endif
  14117. return EXPECT_RESULT();
  14118. } /* END test_wc_Sha3_384_Copy */
  14119. /*
  14120. * Testing wc_Sha3_512_Copy()
  14121. */
  14122. static int test_wc_Sha3_512_Copy(void)
  14123. {
  14124. EXPECT_DECLS;
  14125. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  14126. wc_Sha3 sha3, sha3Cpy;
  14127. const char* msg = TEST_STRING;
  14128. word32 msglen = (word32)TEST_STRING_SZ;
  14129. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14130. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  14131. XMEMSET(hash, 0, sizeof(hash));
  14132. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14133. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14134. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14135. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14136. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14137. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  14138. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  14139. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14140. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  14141. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14142. /* Test bad args. */
  14143. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14144. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14145. wc_Sha3_512_Free(&sha3);
  14146. wc_Sha3_512_Free(&sha3Cpy);
  14147. #endif
  14148. return EXPECT_RESULT();
  14149. } /* END test_wc_Sha3_512_Copy */
  14150. /*
  14151. * Unit test function for wc_Sha3_GetFlags()
  14152. */
  14153. static int test_wc_Sha3_GetFlags(void)
  14154. {
  14155. EXPECT_DECLS;
  14156. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  14157. wc_Sha3 sha3;
  14158. word32 flags = 0;
  14159. /* Initialize */
  14160. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14161. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  14162. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  14163. wc_Sha3_224_Free(&sha3);
  14164. #endif
  14165. return EXPECT_RESULT();
  14166. } /* END test_wc_Sha3_GetFlags */
  14167. static int test_wc_InitShake256(void)
  14168. {
  14169. EXPECT_DECLS;
  14170. #ifdef WOLFSSL_SHAKE256
  14171. wc_Shake shake;
  14172. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14173. /* Test bad args. */
  14174. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14175. wc_Shake256_Free(&shake);
  14176. #endif
  14177. return EXPECT_RESULT();
  14178. }
  14179. static int testing_wc_Shake256_Update(void)
  14180. {
  14181. EXPECT_DECLS;
  14182. #ifdef WOLFSSL_SHAKE256
  14183. wc_Shake shake;
  14184. byte msg[] = "Everybody's working for the weekend.";
  14185. byte msg2[] = "Everybody gets Friday off.";
  14186. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14187. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14188. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14189. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14190. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14191. word32 msglen = sizeof(msg) - 1;
  14192. word32 msg2len = sizeof(msg2);
  14193. word32 msgCmplen = sizeof(msgCmp);
  14194. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14195. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  14196. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  14197. ExpectTrue(shake.i == msglen);
  14198. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14199. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  14200. /* Pass bad args. */
  14201. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14202. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14203. wc_Shake256_Free(&shake);
  14204. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14205. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  14206. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14207. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  14208. wc_Shake256_Free(&shake);
  14209. #endif /* WOLFSSL_SHAKE256 */
  14210. return EXPECT_RESULT();
  14211. }
  14212. static int test_wc_Shake256_Final(void)
  14213. {
  14214. EXPECT_DECLS;
  14215. #ifdef WOLFSSL_SHAKE256
  14216. wc_Shake shake;
  14217. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14218. "nopnopq";
  14219. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14220. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14221. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14222. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14223. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14224. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14225. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14226. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14227. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14228. byte hash[114];
  14229. /* Init stack variables. */
  14230. XMEMSET(hash, 0, sizeof(hash));
  14231. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14232. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14233. 0);
  14234. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14235. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14236. /* Test bad args. */
  14237. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14239. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14241. wc_Shake256_Free(&shake);
  14242. #endif
  14243. return EXPECT_RESULT();
  14244. }
  14245. /*
  14246. * Testing wc_Shake256_Copy()
  14247. */
  14248. static int test_wc_Shake256_Copy(void)
  14249. {
  14250. EXPECT_DECLS;
  14251. #ifdef WOLFSSL_SHAKE256
  14252. wc_Shake shake, shakeCpy;
  14253. const char* msg = TEST_STRING;
  14254. word32 msglen = (word32)TEST_STRING_SZ;
  14255. byte hash[144];
  14256. byte hashCpy[144];
  14257. word32 hashLen = sizeof(hash);
  14258. word32 hashLenCpy = sizeof(hashCpy);
  14259. XMEMSET(hash, 0, sizeof(hash));
  14260. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14261. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14262. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14263. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14264. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14265. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14266. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14267. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14268. /* Test bad args. */
  14269. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14270. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14271. wc_Shake256_Free(&shake);
  14272. wc_Shake256_Free(&shakeCpy);
  14273. #endif
  14274. return EXPECT_RESULT();
  14275. } /* END test_wc_Shake256_Copy */
  14276. /*
  14277. * Unit test function for wc_Shake256Hash()
  14278. */
  14279. static int test_wc_Shake256Hash(void)
  14280. {
  14281. EXPECT_DECLS;
  14282. #ifdef WOLFSSL_SHAKE256
  14283. const byte data[] = { /* Hello World */
  14284. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14285. 0x72,0x6c,0x64
  14286. };
  14287. word32 len = sizeof(data);
  14288. byte hash[144];
  14289. word32 hashLen = sizeof(hash);
  14290. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14291. #endif
  14292. return EXPECT_RESULT();
  14293. } /* END test_wc_Shake256Hash */
  14294. /*
  14295. * Testing wc_InitSm3(), wc_Sm3Free()
  14296. */
  14297. static int test_wc_InitSm3Free(void)
  14298. {
  14299. EXPECT_DECLS;
  14300. #ifdef WOLFSSL_SM3
  14301. wc_Sm3 sm3;
  14302. /* Invalid Parameters */
  14303. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14304. /* Valid Parameters */
  14305. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14306. wc_Sm3Free(NULL);
  14307. wc_Sm3Free(&sm3);
  14308. #endif
  14309. return EXPECT_RESULT();
  14310. } /* END test_wc_InitSm3 */
  14311. /*
  14312. * Testing wc_Sm3Update(), wc_Sm3Final()
  14313. */
  14314. static int test_wc_Sm3UpdateFinal(void)
  14315. {
  14316. EXPECT_DECLS;
  14317. #ifdef WOLFSSL_SM3
  14318. wc_Sm3 sm3;
  14319. byte data[WC_SM3_BLOCK_SIZE * 4];
  14320. byte hash[WC_SM3_DIGEST_SIZE];
  14321. byte calcHash[WC_SM3_DIGEST_SIZE];
  14322. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14323. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14324. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14325. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14326. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14327. };
  14328. word32 chunk;
  14329. word32 i;
  14330. XMEMSET(data, 0, sizeof(data));
  14331. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14332. /* Invalid Parameters */
  14333. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14334. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14335. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14336. /* Valid Parameters */
  14337. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14338. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14339. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14340. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14341. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14342. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14343. /* Ensure too many bytes for lengths. */
  14344. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14345. /* Invalid Parameters */
  14346. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14347. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14348. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14349. /* Valid Parameters */
  14350. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14351. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14352. /* Chunk tests. */
  14353. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14354. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14355. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14356. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14357. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14358. }
  14359. if (i < (word32)sizeof(data)) {
  14360. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14361. 0);
  14362. }
  14363. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14364. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14365. }
  14366. /* Not testing when the low 32-bit length overflows. */
  14367. wc_Sm3Free(&sm3);
  14368. #endif
  14369. return EXPECT_RESULT();
  14370. } /* END test_wc_Sm3Update */
  14371. /*
  14372. * Testing wc_Sm3GetHash()
  14373. */
  14374. static int test_wc_Sm3GetHash(void)
  14375. {
  14376. EXPECT_DECLS;
  14377. #ifdef WOLFSSL_SM3
  14378. wc_Sm3 sm3;
  14379. byte hash[WC_SM3_DIGEST_SIZE];
  14380. byte calcHash[WC_SM3_DIGEST_SIZE];
  14381. byte data[WC_SM3_BLOCK_SIZE];
  14382. XMEMSET(data, 0, sizeof(data));
  14383. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14384. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14385. /* Invalid Parameters */
  14386. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14387. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14388. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14389. /* Valid Parameters */
  14390. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14391. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14392. /* With update. */
  14393. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14394. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14395. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14396. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14397. wc_Sm3Free(&sm3);
  14398. #endif
  14399. return EXPECT_RESULT();
  14400. } /* END test_wc_Sm3Update */
  14401. /*
  14402. * Testing wc_Sm3Copy()
  14403. */
  14404. static int test_wc_Sm3Copy(void)
  14405. {
  14406. EXPECT_DECLS;
  14407. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14408. wc_Sm3 sm3;
  14409. wc_Sm3 sm3Copy;
  14410. byte hash[WC_SM3_DIGEST_SIZE];
  14411. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14412. byte data[WC_SM3_BLOCK_SIZE + 1];
  14413. int i;
  14414. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14415. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14416. /* Invalid Parameters */
  14417. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14418. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14419. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14420. /* Valid Parameters */
  14421. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14422. /* Ensure all parts of data updated during hashing are copied. */
  14423. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14424. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14425. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14426. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14427. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14428. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14429. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14430. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14431. }
  14432. wc_Sm3Free(&sm3Copy);
  14433. wc_Sm3Free(&sm3);
  14434. #endif
  14435. return EXPECT_RESULT();
  14436. } /* END test_wc_Sm3Copy */
  14437. /*
  14438. * Testing wc_Sm3FinalRaw()
  14439. */
  14440. static int test_wc_Sm3FinalRaw(void)
  14441. {
  14442. EXPECT_DECLS;
  14443. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14444. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14445. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14446. !defined(WOLFSSL_NO_HASH_RAW)
  14447. wc_Sm3 sm3;
  14448. byte hash1[WC_SM3_DIGEST_SIZE];
  14449. byte hash2[WC_SM3_DIGEST_SIZE];
  14450. byte hash3[WC_SM3_DIGEST_SIZE];
  14451. byte* hash_test[3] = { hash1, hash2, hash3 };
  14452. int times;
  14453. int i;
  14454. XMEMSET(&sm3, 0, sizeof(sm3));
  14455. /* Initialize */
  14456. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14457. /* Invalid Parameters */
  14458. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14459. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14460. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14461. times = sizeof(hash_test) / sizeof(byte*);
  14462. for (i = 0; i < times; i++) {
  14463. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14464. }
  14465. wc_Sm3Free(&sm3);
  14466. #endif
  14467. return EXPECT_RESULT();
  14468. } /* END test_wc_Sm3FinalRaw */
  14469. /*
  14470. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14471. */
  14472. static int test_wc_Sm3GetSetFlags(void)
  14473. {
  14474. EXPECT_DECLS;
  14475. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14476. wc_Sm3 sm3;
  14477. wc_Sm3 sm3Copy;
  14478. word32 flags = 0;
  14479. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14480. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14481. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14482. ExpectIntEQ(flags, 0);
  14483. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14484. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14485. ExpectIntEQ(flags, 0);
  14486. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14487. ExpectIntEQ(flags, 0);
  14488. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14489. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14490. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14491. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14492. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14493. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14494. wc_Sm3Free(&sm3Copy);
  14495. wc_Sm3Free(&sm3);
  14496. #endif
  14497. return EXPECT_RESULT();
  14498. } /* END test_wc_Sm3Update */
  14499. /*
  14500. * Testing wc_Sm3Hash()
  14501. */
  14502. static int test_wc_Sm3Hash(void)
  14503. {
  14504. EXPECT_DECLS;
  14505. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14506. byte data[WC_SM3_BLOCK_SIZE];
  14507. byte hash[WC_SM3_DIGEST_SIZE];
  14508. /* Invalid parameters. */
  14509. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14510. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14511. /* Valid parameters. */
  14512. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14513. #endif
  14514. return EXPECT_RESULT();
  14515. } /* END test_wc_Sm3Hash */
  14516. /*
  14517. * Test function for wc_HmacSetKey
  14518. */
  14519. static int test_wc_Md5HmacSetKey(void)
  14520. {
  14521. EXPECT_DECLS;
  14522. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14523. Hmac hmac;
  14524. int ret, times, itr;
  14525. const char* keys[]=
  14526. {
  14527. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14528. #ifndef HAVE_FIPS
  14529. "Jefe", /* smaller than minimum FIPS key size */
  14530. #endif
  14531. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14532. };
  14533. times = sizeof(keys) / sizeof(char*);
  14534. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14535. for (itr = 0; itr < times; itr++) {
  14536. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14537. (word32)XSTRLEN(keys[itr]));
  14538. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14539. wc_HmacFree(&hmac);
  14540. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14541. #else
  14542. ExpectIntEQ(ret, 0);
  14543. #endif
  14544. }
  14545. /* Bad args. */
  14546. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14547. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14548. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14549. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14550. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14551. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14552. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14553. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14554. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14555. #elif defined(HAVE_FIPS)
  14556. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14557. #else
  14558. ExpectIntEQ(ret, 0);
  14559. #endif
  14560. wc_HmacFree(&hmac);
  14561. #endif
  14562. return EXPECT_RESULT();
  14563. } /* END test_wc_Md5HmacSetKey */
  14564. /*
  14565. * testing wc_HmacSetKey() on wc_Sha hash.
  14566. */
  14567. static int test_wc_ShaHmacSetKey(void)
  14568. {
  14569. EXPECT_DECLS;
  14570. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14571. Hmac hmac;
  14572. int ret, times, itr;
  14573. const char* keys[]=
  14574. {
  14575. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14576. "\x0b\x0b\x0b",
  14577. #ifndef HAVE_FIPS
  14578. "Jefe", /* smaller than minimum FIPS key size */
  14579. #endif
  14580. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14581. "\xAA\xAA\xAA"
  14582. };
  14583. times = sizeof(keys) / sizeof(char*);
  14584. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14585. for (itr = 0; itr < times; itr++) {
  14586. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14587. (word32)XSTRLEN(keys[itr])), 0);
  14588. }
  14589. /* Bad args. */
  14590. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14591. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14592. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14594. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14595. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14596. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14597. #ifdef HAVE_FIPS
  14598. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14599. #else
  14600. ExpectIntEQ(ret, 0);
  14601. #endif
  14602. wc_HmacFree(&hmac);
  14603. #endif
  14604. return EXPECT_RESULT();
  14605. } /* END test_wc_ShaHmacSetKey() */
  14606. /*
  14607. * testing wc_HmacSetKey() on Sha224 hash.
  14608. */
  14609. static int test_wc_Sha224HmacSetKey(void)
  14610. {
  14611. EXPECT_DECLS;
  14612. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14613. Hmac hmac;
  14614. int ret, times, itr;
  14615. const char* keys[]=
  14616. {
  14617. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14618. "\x0b\x0b\x0b",
  14619. #ifndef HAVE_FIPS
  14620. "Jefe", /* smaller than minimum FIPS key size */
  14621. #endif
  14622. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14623. "\xAA\xAA\xAA"
  14624. };
  14625. times = sizeof(keys) / sizeof(char*);
  14626. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14627. for (itr = 0; itr < times; itr++) {
  14628. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14629. (word32)XSTRLEN(keys[itr])), 0);
  14630. }
  14631. /* Bad args. */
  14632. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14633. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14634. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14635. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14636. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14637. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14638. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14639. #ifdef HAVE_FIPS
  14640. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14641. #else
  14642. ExpectIntEQ(ret, 0);
  14643. #endif
  14644. wc_HmacFree(&hmac);
  14645. #endif
  14646. return EXPECT_RESULT();
  14647. } /* END test_wc_Sha224HmacSetKey() */
  14648. /*
  14649. * testing wc_HmacSetKey() on Sha256 hash
  14650. */
  14651. static int test_wc_Sha256HmacSetKey(void)
  14652. {
  14653. EXPECT_DECLS;
  14654. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14655. Hmac hmac;
  14656. int ret, times, itr;
  14657. const char* keys[]=
  14658. {
  14659. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14660. "\x0b\x0b\x0b",
  14661. #ifndef HAVE_FIPS
  14662. "Jefe", /* smaller than minimum FIPS key size */
  14663. #endif
  14664. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14665. "\xAA\xAA\xAA"
  14666. };
  14667. times = sizeof(keys) / sizeof(char*);
  14668. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14669. for (itr = 0; itr < times; itr++) {
  14670. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  14671. (word32)XSTRLEN(keys[itr])), 0);
  14672. }
  14673. /* Bad args. */
  14674. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  14675. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14676. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  14677. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14678. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14679. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14680. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  14681. #ifdef HAVE_FIPS
  14682. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14683. #else
  14684. ExpectIntEQ(ret, 0);
  14685. #endif
  14686. wc_HmacFree(&hmac);
  14687. #endif
  14688. return EXPECT_RESULT();
  14689. } /* END test_wc_Sha256HmacSetKey() */
  14690. /*
  14691. * testing wc_HmacSetKey on Sha384 hash.
  14692. */
  14693. static int test_wc_Sha384HmacSetKey(void)
  14694. {
  14695. EXPECT_DECLS;
  14696. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14697. Hmac hmac;
  14698. int ret, times, itr;
  14699. const char* keys[]=
  14700. {
  14701. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14702. "\x0b\x0b\x0b",
  14703. #ifndef HAVE_FIPS
  14704. "Jefe", /* smaller than minimum FIPS key size */
  14705. #endif
  14706. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14707. "\xAA\xAA\xAA"
  14708. };
  14709. times = sizeof(keys) / sizeof(char*);
  14710. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14711. for (itr = 0; itr < times; itr++) {
  14712. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  14713. (word32)XSTRLEN(keys[itr])), 0);
  14714. }
  14715. /* Bad args. */
  14716. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  14717. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14718. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  14719. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14720. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14721. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14722. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  14723. #ifdef HAVE_FIPS
  14724. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14725. #else
  14726. ExpectIntEQ(ret, 0);
  14727. #endif
  14728. wc_HmacFree(&hmac);
  14729. #endif
  14730. return EXPECT_RESULT();
  14731. } /* END test_wc_Sha384HmacSetKey() */
  14732. /*
  14733. * testing wc_HmacUpdate on wc_Md5 hash.
  14734. */
  14735. static int test_wc_Md5HmacUpdate(void)
  14736. {
  14737. EXPECT_DECLS;
  14738. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14739. Hmac hmac;
  14740. testVector a, b;
  14741. #ifdef HAVE_FIPS
  14742. const char* keys =
  14743. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14744. #else
  14745. const char* keys = "Jefe";
  14746. #endif
  14747. a.input = "what do ya want for nothing?";
  14748. a.inLen = XSTRLEN(a.input);
  14749. b.input = "Hi There";
  14750. b.inLen = XSTRLEN(b.input);
  14751. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14752. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  14753. (word32)XSTRLEN(keys)), 0);
  14754. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14755. /* Update Hmac. */
  14756. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14757. /* Test bad args. */
  14758. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14759. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14760. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14761. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14762. wc_HmacFree(&hmac);
  14763. #endif
  14764. return EXPECT_RESULT();
  14765. } /* END test_wc_Md5HmacUpdate */
  14766. /*
  14767. * testing wc_HmacUpdate on SHA hash.
  14768. */
  14769. static int test_wc_ShaHmacUpdate(void)
  14770. {
  14771. EXPECT_DECLS;
  14772. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14773. Hmac hmac;
  14774. testVector a, b;
  14775. #ifdef HAVE_FIPS
  14776. const char* keys =
  14777. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14778. #else
  14779. const char* keys = "Jefe";
  14780. #endif
  14781. a.input = "what do ya want for nothing?";
  14782. a.inLen = XSTRLEN(a.input);
  14783. b.input = "Hi There";
  14784. b.inLen = XSTRLEN(b.input);
  14785. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14786. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  14787. (word32)XSTRLEN(keys)), 0);
  14788. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14789. /* Update Hmac. */
  14790. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14791. /* Test bad args. */
  14792. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14793. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14794. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14795. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14796. wc_HmacFree(&hmac);
  14797. #endif
  14798. return EXPECT_RESULT();
  14799. } /* END test_wc_ShaHmacUpdate */
  14800. /*
  14801. * testing wc_HmacUpdate on SHA224 hash.
  14802. */
  14803. static int test_wc_Sha224HmacUpdate(void)
  14804. {
  14805. EXPECT_DECLS;
  14806. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14807. Hmac hmac;
  14808. testVector a, b;
  14809. #ifdef HAVE_FIPS
  14810. const char* keys =
  14811. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14812. #else
  14813. const char* keys = "Jefe";
  14814. #endif
  14815. a.input = "what do ya want for nothing?";
  14816. a.inLen = XSTRLEN(a.input);
  14817. b.input = "Hi There";
  14818. b.inLen = XSTRLEN(b.input);
  14819. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14820. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  14821. (word32)XSTRLEN(keys)), 0);
  14822. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14823. /* Update Hmac. */
  14824. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14825. /* Test bad args. */
  14826. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14827. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14828. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14829. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14830. wc_HmacFree(&hmac);
  14831. #endif
  14832. return EXPECT_RESULT();
  14833. } /* END test_wc_Sha224HmacUpdate */
  14834. /*
  14835. * testing wc_HmacUpdate on SHA256 hash.
  14836. */
  14837. static int test_wc_Sha256HmacUpdate(void)
  14838. {
  14839. EXPECT_DECLS;
  14840. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14841. Hmac hmac;
  14842. testVector a, b;
  14843. #ifdef HAVE_FIPS
  14844. const char* keys =
  14845. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14846. #else
  14847. const char* keys = "Jefe";
  14848. #endif
  14849. a.input = "what do ya want for nothing?";
  14850. a.inLen = XSTRLEN(a.input);
  14851. b.input = "Hi There";
  14852. b.inLen = XSTRLEN(b.input);
  14853. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14854. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  14855. (word32)XSTRLEN(keys)), 0);
  14856. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14857. /* Update Hmac. */
  14858. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14859. /* Test bad args. */
  14860. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14861. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14862. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14863. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14864. wc_HmacFree(&hmac);
  14865. #endif
  14866. return EXPECT_RESULT();
  14867. } /* END test_wc_Sha256HmacUpdate */
  14868. /*
  14869. * testing wc_HmacUpdate on SHA384 hash.
  14870. */
  14871. static int test_wc_Sha384HmacUpdate(void)
  14872. {
  14873. EXPECT_DECLS;
  14874. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14875. Hmac hmac;
  14876. testVector a, b;
  14877. #ifdef HAVE_FIPS
  14878. const char* keys =
  14879. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14880. #else
  14881. const char* keys = "Jefe";
  14882. #endif
  14883. a.input = "what do ya want for nothing?";
  14884. a.inLen = XSTRLEN(a.input);
  14885. b.input = "Hi There";
  14886. b.inLen = XSTRLEN(b.input);
  14887. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14888. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  14889. (word32)XSTRLEN(keys)), 0);
  14890. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14891. /* Update Hmac. */
  14892. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14893. /* Test bad args. */
  14894. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14895. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14896. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14897. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14898. wc_HmacFree(&hmac);
  14899. #endif
  14900. return EXPECT_RESULT();
  14901. } /* END test_wc_Sha384HmacUpdate */
  14902. /*
  14903. * Testing wc_HmacFinal() with MD5
  14904. */
  14905. static int test_wc_Md5HmacFinal(void)
  14906. {
  14907. EXPECT_DECLS;
  14908. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14909. Hmac hmac;
  14910. byte hash[WC_MD5_DIGEST_SIZE];
  14911. testVector a;
  14912. const char* key;
  14913. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14914. a.input = "Hi There";
  14915. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  14916. "\x9d";
  14917. a.inLen = XSTRLEN(a.input);
  14918. a.outLen = XSTRLEN(a.output);
  14919. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14920. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  14921. 0);
  14922. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14923. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14924. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  14925. /* Try bad parameters. */
  14926. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14927. #ifndef HAVE_FIPS
  14928. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14929. #endif
  14930. wc_HmacFree(&hmac);
  14931. #endif
  14932. return EXPECT_RESULT();
  14933. } /* END test_wc_Md5HmacFinal */
  14934. /*
  14935. * Testing wc_HmacFinal() with SHA
  14936. */
  14937. static int test_wc_ShaHmacFinal(void)
  14938. {
  14939. EXPECT_DECLS;
  14940. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14941. Hmac hmac;
  14942. byte hash[WC_SHA_DIGEST_SIZE];
  14943. testVector a;
  14944. const char* key;
  14945. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14946. "\x0b\x0b\x0b";
  14947. a.input = "Hi There";
  14948. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  14949. "\x8e\xf1\x46\xbe\x00";
  14950. a.inLen = XSTRLEN(a.input);
  14951. a.outLen = XSTRLEN(a.output);
  14952. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14953. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  14954. 0);
  14955. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14956. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14957. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  14958. /* Try bad parameters. */
  14959. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14960. #ifndef HAVE_FIPS
  14961. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14962. #endif
  14963. wc_HmacFree(&hmac);
  14964. #endif
  14965. return EXPECT_RESULT();
  14966. } /* END test_wc_ShaHmacFinal */
  14967. /*
  14968. * Testing wc_HmacFinal() with SHA224
  14969. */
  14970. static int test_wc_Sha224HmacFinal(void)
  14971. {
  14972. EXPECT_DECLS;
  14973. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14974. Hmac hmac;
  14975. byte hash[WC_SHA224_DIGEST_SIZE];
  14976. testVector a;
  14977. const char* key;
  14978. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14979. "\x0b\x0b\x0b";
  14980. a.input = "Hi There";
  14981. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  14982. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  14983. a.inLen = XSTRLEN(a.input);
  14984. a.outLen = XSTRLEN(a.output);
  14985. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14986. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  14987. (word32)XSTRLEN(key)), 0);
  14988. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14989. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  14990. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  14991. /* Try bad parameters. */
  14992. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14993. #ifndef HAVE_FIPS
  14994. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14995. #endif
  14996. wc_HmacFree(&hmac);
  14997. #endif
  14998. return EXPECT_RESULT();
  14999. } /* END test_wc_Sha224HmacFinal */
  15000. /*
  15001. * Testing wc_HmacFinal() with SHA256
  15002. */
  15003. static int test_wc_Sha256HmacFinal(void)
  15004. {
  15005. EXPECT_DECLS;
  15006. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15007. Hmac hmac;
  15008. byte hash[WC_SHA256_DIGEST_SIZE];
  15009. testVector a;
  15010. const char* key;
  15011. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15012. "\x0b\x0b\x0b";
  15013. a.input = "Hi There";
  15014. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  15015. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  15016. "\xcf\xf7";
  15017. a.inLen = XSTRLEN(a.input);
  15018. a.outLen = XSTRLEN(a.output);
  15019. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15020. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  15021. (word32)XSTRLEN(key)), 0);
  15022. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15023. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15024. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  15025. /* Try bad parameters. */
  15026. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15027. #ifndef HAVE_FIPS
  15028. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15029. #endif
  15030. wc_HmacFree(&hmac);
  15031. #endif
  15032. return EXPECT_RESULT();
  15033. } /* END test_wc_Sha256HmacFinal */
  15034. /*
  15035. * Testing wc_HmacFinal() with SHA384
  15036. */
  15037. static int test_wc_Sha384HmacFinal(void)
  15038. {
  15039. EXPECT_DECLS;
  15040. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15041. Hmac hmac;
  15042. byte hash[WC_SHA384_DIGEST_SIZE];
  15043. testVector a;
  15044. const char* key;
  15045. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15046. "\x0b\x0b\x0b";
  15047. a.input = "Hi There";
  15048. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  15049. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  15050. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  15051. "\xfa\x9c\xb6";
  15052. a.inLen = XSTRLEN(a.input);
  15053. a.outLen = XSTRLEN(a.output);
  15054. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15055. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  15056. (word32)XSTRLEN(key)), 0);
  15057. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15058. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15059. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  15060. /* Try bad parameters. */
  15061. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15062. #ifndef HAVE_FIPS
  15063. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15064. #endif
  15065. wc_HmacFree(&hmac);
  15066. #endif
  15067. return EXPECT_RESULT();
  15068. } /* END test_wc_Sha384HmacFinal */
  15069. /*
  15070. * Testing wc_InitCmac()
  15071. */
  15072. static int test_wc_InitCmac(void)
  15073. {
  15074. EXPECT_DECLS;
  15075. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  15076. Cmac cmac1;
  15077. Cmac cmac2;
  15078. Cmac cmac3;
  15079. /* AES 128 key. */
  15080. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15081. "\x09\x10\x11\x12\x13\x14\x15\x16";
  15082. /* AES 192 key. */
  15083. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15084. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15085. "\x01\x02\x03\x04\x05\x06\x07\x08";
  15086. /* AES 256 key. */
  15087. byte key3[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15088. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15089. "\x01\x02\x03\x04\x05\x06\x07\x08"
  15090. "\x09\x01\x11\x12\x13\x14\x15\x16";
  15091. word32 key1Sz = (word32)sizeof(key1) - 1;
  15092. word32 key2Sz = (word32)sizeof(key2) - 1;
  15093. word32 key3Sz = (word32)sizeof(key3) - 1;
  15094. int type = WC_CMAC_AES;
  15095. (void)key1;
  15096. (void)key1Sz;
  15097. (void)key2;
  15098. (void)key2Sz;
  15099. XMEMSET(&cmac1, 0, sizeof(Cmac));
  15100. XMEMSET(&cmac2, 0, sizeof(Cmac));
  15101. XMEMSET(&cmac3, 0, sizeof(Cmac));
  15102. #ifdef WOLFSSL_AES_128
  15103. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  15104. #endif
  15105. #ifdef WOLFSSL_AES_192
  15106. wc_AesFree(&cmac1.aes);
  15107. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  15108. #endif
  15109. #ifdef WOLFSSL_AES_256
  15110. wc_AesFree(&cmac2.aes);
  15111. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  15112. #endif
  15113. wc_AesFree(&cmac3.aes);
  15114. /* Test bad args. */
  15115. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15116. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15117. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15118. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15119. #endif
  15120. return EXPECT_RESULT();
  15121. } /* END test_wc_InitCmac */
  15122. /*
  15123. * Testing wc_CmacUpdate()
  15124. */
  15125. static int test_wc_CmacUpdate(void)
  15126. {
  15127. EXPECT_DECLS;
  15128. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15129. Cmac cmac;
  15130. byte key[] = {
  15131. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15132. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15133. };
  15134. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  15135. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  15136. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  15137. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  15138. "\xf4";
  15139. word32 inSz = (word32)sizeof(in) - 1;
  15140. word32 keySz = (word32)sizeof(key);
  15141. int type = WC_CMAC_AES;
  15142. XMEMSET(&cmac, 0, sizeof(Cmac));
  15143. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15144. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  15145. /* Test bad args. */
  15146. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15147. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15148. wc_AesFree(&cmac.aes);
  15149. #endif
  15150. return EXPECT_RESULT();
  15151. } /* END test_wc_CmacUpdate */
  15152. /*
  15153. * Testing wc_CmacFinal()
  15154. */
  15155. static int test_wc_CmacFinal(void)
  15156. {
  15157. EXPECT_DECLS;
  15158. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15159. Cmac cmac;
  15160. byte key[] = {
  15161. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15162. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15163. };
  15164. byte msg[] = {
  15165. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  15166. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  15167. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  15168. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  15169. 0xf4
  15170. };
  15171. /* Test vectors from CMACGenAES128.rsp from
  15172. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  15173. * Per RFC4493 truncation of lsb is possible.
  15174. */
  15175. byte expMac[] = {
  15176. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  15177. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  15178. };
  15179. byte mac[AES_BLOCK_SIZE];
  15180. word32 msgSz = (word32)sizeof(msg);
  15181. word32 keySz = (word32)sizeof(key);
  15182. word32 macSz = sizeof(mac);
  15183. word32 badMacSz = 17;
  15184. int expMacSz = sizeof(expMac);
  15185. int type = WC_CMAC_AES;
  15186. XMEMSET(&cmac, 0, sizeof(Cmac));
  15187. XMEMSET(mac, 0, macSz);
  15188. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15189. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  15190. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  15191. /* Pass in bad args. */
  15192. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15193. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15194. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15195. /* For the last call, use the API with implicit wc_CmacFree(). */
  15196. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15197. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15198. #else /* !HAVE_FIPS || FIPS>=5.3 */
  15199. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15200. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15201. /* Pass in bad args. */
  15202. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15203. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15204. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15205. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  15206. #endif
  15207. return EXPECT_RESULT();
  15208. } /* END test_wc_CmacFinal */
  15209. /*
  15210. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  15211. */
  15212. static int test_wc_AesCmacGenerate(void)
  15213. {
  15214. EXPECT_DECLS;
  15215. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15216. byte key[] = {
  15217. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15218. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15219. };
  15220. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15221. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15222. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15223. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15224. byte mac[AES_BLOCK_SIZE];
  15225. word32 keySz = sizeof(key);
  15226. word32 macSz = sizeof(mac);
  15227. word32 msgSz = sizeof(msg) - 1;
  15228. word32 expMacSz = sizeof(expMac) - 1;
  15229. XMEMSET(mac, 0, macSz);
  15230. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15231. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15232. /* Pass in bad args. */
  15233. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15235. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15237. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15239. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15241. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15242. /* Test bad args. */
  15243. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15244. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15245. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15247. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15249. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15251. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15253. #endif
  15254. return EXPECT_RESULT();
  15255. } /* END test_wc_AesCmacGenerate */
  15256. /*
  15257. * Testing streaming AES-GCM API.
  15258. */
  15259. static int test_wc_AesGcmStream(void)
  15260. {
  15261. EXPECT_DECLS;
  15262. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15263. defined(WOLFSSL_AESGCM_STREAM)
  15264. int i;
  15265. WC_RNG rng[1];
  15266. Aes aesEnc[1];
  15267. Aes aesDec[1];
  15268. byte tag[AES_BLOCK_SIZE];
  15269. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15270. byte out[AES_BLOCK_SIZE * 3 + 2];
  15271. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15272. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15273. byte key[AES_128_KEY_SIZE] = { 0, };
  15274. byte iv[AES_IV_SIZE] = { 1, };
  15275. byte ivOut[AES_IV_SIZE];
  15276. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15277. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15278. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15279. };
  15280. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15281. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15282. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15283. };
  15284. static const byte expTag[AES_BLOCK_SIZE] = {
  15285. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15286. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15287. };
  15288. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15289. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15290. XMEMSET(&aesDec, 0, sizeof(Aes));
  15291. /* Create a random for generating IV/nonce. */
  15292. ExpectIntEQ(wc_InitRng(rng), 0);
  15293. /* Initialize data structures. */
  15294. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15295. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15296. /* BadParameters to streaming init. */
  15297. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15298. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15299. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15300. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15301. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15303. /* Bad parameters to encrypt update. */
  15304. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15305. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15306. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15307. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15308. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15309. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15310. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15311. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15312. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15313. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15314. /* Bad parameters to decrypt update. */
  15315. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15316. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15317. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15318. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15319. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15321. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15323. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15324. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15325. /* Bad parameters to encrypt final. */
  15326. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15327. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15328. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15329. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15330. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15331. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15332. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15333. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15334. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15335. /* Bad parameters to decrypt final. */
  15336. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15337. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15338. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15339. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15340. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15341. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15342. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15343. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15344. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15345. /* Check calling final before setting key fails. */
  15346. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15347. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15348. /* Check calling update before setting key else fails. */
  15349. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15350. WC_NO_ERR_TRACE(MISSING_KEY));
  15351. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15352. WC_NO_ERR_TRACE(MISSING_KEY));
  15353. /* Set key but not IV. */
  15354. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15355. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15356. /* Check calling final before setting IV fails. */
  15357. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15358. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15359. /* Check calling update before setting IV else fails. */
  15360. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15361. WC_NO_ERR_TRACE(MISSING_IV));
  15362. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15363. WC_NO_ERR_TRACE(MISSING_IV));
  15364. /* Set IV using fixed part IV and external IV APIs. */
  15365. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15366. rng), 0);
  15367. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15368. GCM_NONCE_MID_SZ), 0);
  15369. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15370. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15371. /* Encrypt and decrypt data. */
  15372. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15373. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15374. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15375. /* Finalize and check tag matches. */
  15376. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15377. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15378. /* Set key and IV through streaming init API. */
  15379. wc_AesFree(aesEnc);
  15380. wc_AesFree(aesDec);
  15381. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15382. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15383. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15384. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15385. /* Encrypt/decrypt one block and AAD of one block. */
  15386. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15387. AES_BLOCK_SIZE), 0);
  15388. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15389. AES_BLOCK_SIZE), 0);
  15390. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15391. /* Finalize and check tag matches. */
  15392. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15393. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15394. /* Set key and IV through streaming init API. */
  15395. wc_AesFree(aesEnc);
  15396. wc_AesFree(aesDec);
  15397. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15398. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15399. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15400. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15401. /* No data to encrypt/decrypt one byte of AAD. */
  15402. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15403. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15404. /* Finalize and check tag matches. */
  15405. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15406. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15407. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15408. /* Set key and IV through streaming init API. */
  15409. wc_AesFree(aesEnc);
  15410. wc_AesFree(aesDec);
  15411. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15412. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15413. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15414. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15415. /* Encrypt/decrypt one byte and no AAD. */
  15416. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15417. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15418. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15419. /* Finalize and check tag matches. */
  15420. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15421. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15422. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15423. /* Set key and IV through streaming init API. */
  15424. wc_AesFree(aesEnc);
  15425. wc_AesFree(aesDec);
  15426. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15427. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15428. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15429. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15430. /* Encryption AES is one byte at a time */
  15431. for (i = 0; i < (int)sizeof(aad); i++) {
  15432. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15433. 0);
  15434. }
  15435. for (i = 0; i < (int)sizeof(in); i++) {
  15436. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15437. 0);
  15438. }
  15439. /* Decryption AES is two bytes at a time */
  15440. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15441. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15442. 0);
  15443. }
  15444. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15445. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15446. 0), 0);
  15447. }
  15448. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15449. /* Finalize and check tag matches. */
  15450. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15451. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15452. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15453. /* Check streaming encryption can be decrypted with one shot. */
  15454. wc_AesFree(aesDec);
  15455. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15456. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15457. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15458. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15459. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15460. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15461. wc_AesFree(aesEnc);
  15462. wc_AesFree(aesDec);
  15463. wc_FreeRng(rng);
  15464. #endif
  15465. return EXPECT_RESULT();
  15466. } /* END test_wc_AesGcmStream */
  15467. /*
  15468. * Testing streaming SM4 API.
  15469. */
  15470. static int test_wc_Sm4(void)
  15471. {
  15472. int res = TEST_SKIPPED;
  15473. #ifdef WOLFSSL_SM4
  15474. EXPECT_DECLS;
  15475. wc_Sm4 sm4;
  15476. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15477. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15478. unsigned char key[SM4_KEY_SIZE];
  15479. #endif
  15480. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15481. unsigned char iv[SM4_IV_SIZE];
  15482. #endif
  15483. /* Invalid parameters - wc_Sm4Init */
  15484. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15485. /* Valid cases - wc_Sm4Init */
  15486. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15487. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15488. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15489. XMEMSET(key, 0, sizeof(key));
  15490. /* Invalid parameters - wc_Sm4SetKey. */
  15491. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15492. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15493. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15494. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15495. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15496. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15497. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15498. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15499. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15500. /* Valid cases - wc_Sm4SetKey. */
  15501. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15502. #endif
  15503. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15504. XMEMSET(iv, 0, sizeof(iv));
  15505. /* Invalid parameters - wc_Sm4SetIV. */
  15506. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15507. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15508. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15509. /* Valid cases - wc_Sm4SetIV. */
  15510. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15511. #endif
  15512. /* Valid cases - wc_Sm4Free */
  15513. wc_Sm4Free(NULL);
  15514. wc_Sm4Free(&sm4);
  15515. res = EXPECT_RESULT();
  15516. #endif
  15517. return res;
  15518. } /* END test_wc_Sm4 */
  15519. /*
  15520. * Testing block based SM4-ECB API.
  15521. */
  15522. static int test_wc_Sm4Ecb(void)
  15523. {
  15524. int res = TEST_SKIPPED;
  15525. #ifdef WOLFSSL_SM4_ECB
  15526. EXPECT_DECLS;
  15527. wc_Sm4 sm4;
  15528. unsigned char key[SM4_KEY_SIZE];
  15529. unsigned char in[SM4_BLOCK_SIZE * 2];
  15530. unsigned char out[SM4_BLOCK_SIZE * 2];
  15531. unsigned char out2[SM4_BLOCK_SIZE];
  15532. XMEMSET(key, 0, sizeof(key));
  15533. XMEMSET(in, 0, sizeof(in));
  15534. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15535. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15536. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15537. /* Tested in test_wc_Sm4. */
  15538. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15539. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15540. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15541. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15542. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15543. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15544. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15545. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15546. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15547. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15548. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15549. /* Valid cases - wc_Sm4EcbEncrypt. */
  15550. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15551. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15552. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15553. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15554. /* In and out are same pointer. */
  15555. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15556. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15557. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15558. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15559. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15560. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15561. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15562. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15563. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15564. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15565. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15566. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15567. /* Valid cases - wc_Sm4EcbDecrypt. */
  15568. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15569. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15570. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15571. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15572. /* In and out are same pointer. */
  15573. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15574. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15575. wc_Sm4Free(&sm4);
  15576. res = EXPECT_RESULT();
  15577. #endif
  15578. return res;
  15579. } /* END test_wc_Sm4Ecb */
  15580. /*
  15581. * Testing block based SM4-CBC API.
  15582. */
  15583. static int test_wc_Sm4Cbc(void)
  15584. {
  15585. int res = TEST_SKIPPED;
  15586. #ifdef WOLFSSL_SM4_CBC
  15587. EXPECT_DECLS;
  15588. wc_Sm4 sm4;
  15589. unsigned char key[SM4_KEY_SIZE];
  15590. unsigned char iv[SM4_IV_SIZE];
  15591. unsigned char in[SM4_BLOCK_SIZE * 2];
  15592. unsigned char out[SM4_BLOCK_SIZE * 2];
  15593. unsigned char out2[SM4_BLOCK_SIZE];
  15594. XMEMSET(key, 0, sizeof(key));
  15595. XMEMSET(iv, 0, sizeof(iv));
  15596. XMEMSET(in, 0, sizeof(in));
  15597. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15598. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15599. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15600. /* Tested in test_wc_Sm4. */
  15601. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15602. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15603. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15604. /* Tested in test_wc_Sm4. */
  15605. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15606. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15607. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15608. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15609. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15610. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15611. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15612. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15613. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15614. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15615. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15616. /* Valid cases - wc_Sm4CbcEncrypt. */
  15617. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15618. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15619. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15620. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15621. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15622. /* In and out are same pointer. */
  15623. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15624. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15625. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15626. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15627. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15628. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15629. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15630. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15631. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15632. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15633. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15634. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15635. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15636. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15637. /* Valid cases - wc_Sm4CbcDecrypt. */
  15638. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15639. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15640. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15641. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15642. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15643. /* In and out are same pointer. */
  15644. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15645. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15646. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15647. wc_Sm4Free(&sm4);
  15648. res = EXPECT_RESULT();
  15649. #endif
  15650. return res;
  15651. } /* END test_wc_Sm4Cbc */
  15652. /*
  15653. * Testing streaming SM4-CTR API.
  15654. */
  15655. static int test_wc_Sm4Ctr(void)
  15656. {
  15657. int res = TEST_SKIPPED;
  15658. #ifdef WOLFSSL_SM4_CTR
  15659. EXPECT_DECLS;
  15660. wc_Sm4 sm4;
  15661. unsigned char key[SM4_KEY_SIZE];
  15662. unsigned char iv[SM4_IV_SIZE];
  15663. unsigned char in[SM4_BLOCK_SIZE * 4];
  15664. unsigned char out[SM4_BLOCK_SIZE * 4];
  15665. unsigned char out2[SM4_BLOCK_SIZE * 4];
  15666. word32 chunk;
  15667. word32 i;
  15668. XMEMSET(key, 0, sizeof(key));
  15669. XMEMSET(iv, 0, sizeof(iv));
  15670. XMEMSET(in, 0, sizeof(in));
  15671. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15672. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15673. /* Tested in test_wc_Sm4. */
  15674. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15675. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15676. /* Tested in test_wc_Sm4. */
  15677. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15678. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  15679. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15680. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15681. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15682. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15683. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15684. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15685. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15686. /* Valid cases - wc_Sm4CtrEncrypt. */
  15687. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  15688. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  15689. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15690. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  15691. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  15692. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15693. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15694. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  15695. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15696. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15697. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15698. /* In and out are same pointer. Also check encrypt of cipher text produces
  15699. * plaintext.
  15700. */
  15701. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15702. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  15703. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15704. /* Chunking tests. */
  15705. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15706. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  15707. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15708. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15709. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  15710. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  15711. }
  15712. if (i < (word32)sizeof(in)) {
  15713. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  15714. (word32)sizeof(in) - i), 0);
  15715. }
  15716. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  15717. }
  15718. for (i = 0; i < (word32)sizeof(iv); i++) {
  15719. iv[i] = 0xff;
  15720. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15721. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15722. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15723. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  15724. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  15725. }
  15726. wc_Sm4Free(&sm4);
  15727. res = EXPECT_RESULT();
  15728. #endif
  15729. return res;
  15730. } /* END test_wc_Sm4Ctr */
  15731. /*
  15732. * Testing stream SM4-GCM API.
  15733. */
  15734. static int test_wc_Sm4Gcm(void)
  15735. {
  15736. int res = TEST_SKIPPED;
  15737. #ifdef WOLFSSL_SM4_GCM
  15738. EXPECT_DECLS;
  15739. wc_Sm4 sm4;
  15740. unsigned char key[SM4_KEY_SIZE];
  15741. unsigned char nonce[GCM_NONCE_MAX_SZ];
  15742. unsigned char in[SM4_BLOCK_SIZE * 2];
  15743. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15744. unsigned char out[SM4_BLOCK_SIZE * 2];
  15745. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15746. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15747. unsigned char tag[SM4_BLOCK_SIZE];
  15748. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15749. word32 i;
  15750. XMEMSET(key, 0, sizeof(key));
  15751. XMEMSET(nonce, 0, sizeof(nonce));
  15752. XMEMSET(in, 0, sizeof(in));
  15753. XMEMSET(in2, 0, sizeof(in2));
  15754. XMEMSET(aad, 0, sizeof(aad));
  15755. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15756. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15757. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15758. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15759. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15760. /* Invalid parameters - wc_Sm4GcmSetKey. */
  15761. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15762. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15763. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15764. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15765. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15766. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15767. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15768. /* Valid parameters - wc_Sm4GcmSetKey. */
  15769. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15770. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  15771. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15772. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15773. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15774. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15775. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15776. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15777. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15778. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15779. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15780. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15781. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15782. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15783. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15784. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15785. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  15786. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15787. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15788. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15789. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  15790. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15791. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  15792. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15793. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  15794. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15795. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15796. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15797. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15798. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15799. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  15800. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15801. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15802. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15803. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15804. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15805. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15806. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15807. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15808. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15809. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15810. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15811. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15812. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15813. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15814. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  15815. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15816. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  15817. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15818. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  15819. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15820. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  15821. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15822. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  15823. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15824. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15825. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15826. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  15827. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15828. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15829. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15830. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15831. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15832. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15833. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15834. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15835. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  15836. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15837. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15838. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15839. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15840. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15841. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15842. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15843. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15844. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  15845. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  15846. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15847. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15848. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15849. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15850. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15851. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  15852. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  15853. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15854. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  15855. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15856. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15857. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15858. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15859. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15860. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  15861. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15862. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15863. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15864. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  15865. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  15866. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  15867. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  15868. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  15869. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  15870. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  15871. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  15872. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  15873. }
  15874. /* Check different in/out sizes. */
  15875. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  15876. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15877. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  15878. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15879. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  15880. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15881. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  15882. XMEMCPY(out2, out, i - 1);
  15883. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  15884. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15885. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  15886. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  15887. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15888. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  15889. }
  15890. /* Force the counter to roll over in first byte. */
  15891. {
  15892. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  15893. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  15894. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  15895. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15896. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  15897. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15898. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  15899. }
  15900. wc_Sm4Free(&sm4);
  15901. res = EXPECT_RESULT();
  15902. #endif
  15903. return res;
  15904. } /* END test_wc_Sm4Gcm */
  15905. /*
  15906. * Testing stream SM4-CCM API.
  15907. */
  15908. static int test_wc_Sm4Ccm(void)
  15909. {
  15910. int res = TEST_SKIPPED;
  15911. #ifdef WOLFSSL_SM4_CCM
  15912. EXPECT_DECLS;
  15913. wc_Sm4 sm4;
  15914. unsigned char key[SM4_KEY_SIZE];
  15915. unsigned char nonce[CCM_NONCE_MAX_SZ];
  15916. unsigned char in[SM4_BLOCK_SIZE * 2];
  15917. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15918. unsigned char out[SM4_BLOCK_SIZE * 2];
  15919. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15920. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15921. unsigned char tag[SM4_BLOCK_SIZE];
  15922. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15923. word32 i;
  15924. XMEMSET(key, 0, sizeof(key));
  15925. XMEMSET(nonce, 0, sizeof(nonce));
  15926. XMEMSET(in, 0, sizeof(in));
  15927. XMEMSET(in2, 0, sizeof(in2));
  15928. XMEMSET(aad, 0, sizeof(aad));
  15929. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15930. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  15931. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15932. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  15933. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15934. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15935. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  15936. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15937. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15938. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15939. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15940. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15941. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15942. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15943. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15944. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15945. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15946. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15947. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15948. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15949. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15950. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15951. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15952. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15953. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15954. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  15955. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15956. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  15957. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15958. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15959. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15960. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15961. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15962. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15963. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15964. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  15965. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15966. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15967. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15968. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15969. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15970. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15971. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  15972. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15973. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15974. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15975. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  15976. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15977. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15978. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15979. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15980. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15981. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  15982. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15983. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  15984. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15985. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  15986. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15987. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  15988. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15989. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15990. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15991. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  15992. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15993. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  15994. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15995. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15996. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15997. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  15998. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  15999. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16000. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16001. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16002. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16003. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16004. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16005. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16006. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16007. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16008. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16009. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16010. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16011. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16012. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16013. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16014. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16015. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16016. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16017. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16018. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16019. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16020. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16021. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  16022. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16023. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16024. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16025. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16026. }
  16027. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16028. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16029. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  16030. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16031. for (i = 0; i < 4; i++) {
  16032. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16033. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16034. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16035. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16036. }
  16037. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  16038. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16039. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16040. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16041. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16042. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16043. }
  16044. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  16045. * Even values in range 4..SM4_BLOCK_SIZE.
  16046. */
  16047. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16048. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16049. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16050. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16051. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16052. }
  16053. /* Check different in/out sizes. */
  16054. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  16055. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16056. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  16057. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16058. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  16059. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16060. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16061. XMEMCPY(out2, out, i - 1);
  16062. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  16063. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16064. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16065. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  16066. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16067. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16068. }
  16069. /* Force the counter to roll over in first byte. */
  16070. {
  16071. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16072. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16073. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16074. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16075. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16076. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16077. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16078. }
  16079. wc_Sm4Free(&sm4);
  16080. res = EXPECT_RESULT();
  16081. #endif
  16082. return res;
  16083. } /* END test_wc_Sm4Ccm */
  16084. /*
  16085. * unit test for wc_Des3_SetIV()
  16086. */
  16087. static int test_wc_Des3_SetIV(void)
  16088. {
  16089. EXPECT_DECLS;
  16090. #ifndef NO_DES3
  16091. Des3 des;
  16092. const byte key[] = {
  16093. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16094. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16095. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16096. };
  16097. const byte iv[] = {
  16098. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16099. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16100. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16101. };
  16102. XMEMSET(&des, 0, sizeof(Des3));
  16103. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16104. /* DES_ENCRYPTION or DES_DECRYPTION */
  16105. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16106. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16107. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  16108. /* Test explicitly wc_Des3_SetIV() */
  16109. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16110. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  16111. #endif
  16112. wc_Des3Free(&des);
  16113. #endif
  16114. return EXPECT_RESULT();
  16115. } /* END test_wc_Des3_SetIV */
  16116. /*
  16117. * unit test for wc_Des3_SetKey()
  16118. */
  16119. static int test_wc_Des3_SetKey(void)
  16120. {
  16121. EXPECT_DECLS;
  16122. #ifndef NO_DES3
  16123. Des3 des;
  16124. const byte key[] = {
  16125. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16126. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16127. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16128. };
  16129. const byte iv[] = {
  16130. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16131. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16132. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16133. };
  16134. XMEMSET(&des, 0, sizeof(Des3));
  16135. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16136. /* DES_ENCRYPTION or DES_DECRYPTION */
  16137. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16138. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16139. /* Test bad args. */
  16140. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16141. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16142. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16143. /* Default case. Should return 0. */
  16144. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  16145. wc_Des3Free(&des);
  16146. #endif
  16147. return EXPECT_RESULT();
  16148. } /* END test_wc_Des3_SetKey */
  16149. /*
  16150. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  16151. */
  16152. static int test_wc_Des3_CbcEncryptDecrypt(void)
  16153. {
  16154. EXPECT_DECLS;
  16155. #ifndef NO_DES3
  16156. Des3 des;
  16157. byte cipher[24];
  16158. byte plain[24];
  16159. const byte key[] = {
  16160. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16161. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16162. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16163. };
  16164. const byte iv[] = {
  16165. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16166. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16167. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16168. };
  16169. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16170. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16171. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16172. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16173. };
  16174. XMEMSET(&des, 0, sizeof(Des3));
  16175. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16176. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16177. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  16178. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  16179. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  16180. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16181. /* Pass in bad args. */
  16182. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16183. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16184. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  16185. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16186. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16187. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16188. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16189. wc_Des3Free(&des);
  16190. #endif
  16191. return EXPECT_RESULT();
  16192. } /* END wc_Des3_CbcEncrypt */
  16193. /*
  16194. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  16195. */
  16196. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  16197. {
  16198. EXPECT_DECLS;
  16199. #ifndef NO_DES3
  16200. word32 vectorSz, cipherSz;
  16201. byte cipher[24];
  16202. byte plain[24];
  16203. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16204. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16205. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16206. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16207. };
  16208. byte key[] = {
  16209. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16210. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16211. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16212. };
  16213. byte iv[] = {
  16214. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16215. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16216. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16217. };
  16218. vectorSz = sizeof(byte) * 24;
  16219. cipherSz = sizeof(byte) * 24;
  16220. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16221. 0);
  16222. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16223. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16224. /* pass in bad args. */
  16225. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16227. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16229. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16230. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16231. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16232. 0);
  16233. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16235. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16237. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16239. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16240. 0);
  16241. #endif
  16242. return EXPECT_RESULT();
  16243. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16244. /*
  16245. * Unit test for wc_Des3_EcbEncrypt
  16246. */
  16247. static int test_wc_Des3_EcbEncrypt(void)
  16248. {
  16249. EXPECT_DECLS;
  16250. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16251. Des3 des;
  16252. byte cipher[24];
  16253. word32 cipherSz = sizeof(cipher);
  16254. const byte key[] = {
  16255. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16256. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16257. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16258. };
  16259. const byte iv[] = {
  16260. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16261. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16262. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16263. };
  16264. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16265. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16266. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16267. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16268. };
  16269. XMEMSET(&des, 0, sizeof(Des3));
  16270. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16271. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16272. /* Bad Cases */
  16273. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16274. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16275. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16276. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16277. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16278. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16279. /* Good Cases */
  16280. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16281. wc_Des3Free(&des);
  16282. #endif
  16283. return EXPECT_RESULT();
  16284. } /* END test_wc_Des3_EcbEncrypt */
  16285. /*
  16286. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16287. */
  16288. static int test_wc_Chacha_SetKey(void)
  16289. {
  16290. EXPECT_DECLS;
  16291. #ifdef HAVE_CHACHA
  16292. ChaCha ctx;
  16293. const byte key[] = {
  16294. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16295. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16296. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16297. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16298. };
  16299. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16300. byte cipher[128];
  16301. XMEMSET(cipher, 0, sizeof(cipher));
  16302. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16303. /* Test bad args. */
  16304. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16305. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16306. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16307. /* Test bad args. */
  16308. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16309. #endif
  16310. return EXPECT_RESULT();
  16311. } /* END test_wc_Chacha_SetKey */
  16312. /*
  16313. * unit test for wc_Poly1305SetKey()
  16314. */
  16315. static int test_wc_Poly1305SetKey(void)
  16316. {
  16317. EXPECT_DECLS;
  16318. #ifdef HAVE_POLY1305
  16319. Poly1305 ctx;
  16320. const byte key[] =
  16321. {
  16322. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16323. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16324. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16325. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16326. };
  16327. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16328. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16329. /* Test bad args. */
  16330. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16331. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16332. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16333. #endif
  16334. return EXPECT_RESULT();
  16335. } /* END test_wc_Poly1305_SetKey() */
  16336. /*
  16337. * Testing wc_Chacha_Process()
  16338. */
  16339. static int test_wc_Chacha_Process(void)
  16340. {
  16341. EXPECT_DECLS;
  16342. #ifdef HAVE_CHACHA
  16343. ChaCha enc, dec;
  16344. byte cipher[128];
  16345. byte plain[128];
  16346. const byte key[] =
  16347. {
  16348. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16349. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16350. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16351. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16352. };
  16353. const char* input = "Everybody gets Friday off.";
  16354. word32 keySz = sizeof(key)/sizeof(byte);
  16355. unsigned long int inlen = XSTRLEN(input);
  16356. /* Initialize stack variables. */
  16357. XMEMSET(cipher, 0, 128);
  16358. XMEMSET(plain, 0, 128);
  16359. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16360. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16361. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16362. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16363. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16364. 0);
  16365. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16366. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16367. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16368. /* test checking and using leftovers, currently just in C code */
  16369. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16370. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16371. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16372. (word32)inlen - 2), 0);
  16373. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16374. (byte*)input + (inlen - 2), 2), 0);
  16375. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16376. (word32)inlen - 2), 0);
  16377. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16378. (byte*)input + (inlen - 2), 2), 0);
  16379. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16380. /* check edge cases with counter increment */
  16381. {
  16382. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16383. const byte expected[] = {
  16384. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16385. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16386. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16387. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16388. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16389. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16390. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16391. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16392. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16393. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16394. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16395. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16396. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16397. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16398. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16399. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16400. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16401. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16402. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16403. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16404. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16405. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16406. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16407. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16408. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16409. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16410. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16411. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16412. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16413. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16414. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16415. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16416. };
  16417. const byte iv2[] = {
  16418. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16419. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16420. };
  16421. byte input2[256];
  16422. int i;
  16423. for (i = 0; i < 256; i++)
  16424. input2[i] = i;
  16425. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16426. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16427. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16428. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16429. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16430. /* partial */
  16431. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16432. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16433. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16434. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16435. }
  16436. #endif
  16437. /* Test bad args. */
  16438. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16439. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16440. #endif
  16441. return EXPECT_RESULT();
  16442. } /* END test_wc_Chacha_Process */
  16443. /*
  16444. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16445. */
  16446. static int test_wc_ChaCha20Poly1305_aead(void)
  16447. {
  16448. EXPECT_DECLS;
  16449. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16450. const byte key[] = {
  16451. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16452. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16453. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16454. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16455. };
  16456. const byte plaintext[] = {
  16457. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16458. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16459. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16460. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16461. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16462. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16463. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16464. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16465. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16466. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16467. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16468. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16469. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16470. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16471. 0x74, 0x2e
  16472. };
  16473. const byte iv[] = {
  16474. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16475. 0x44, 0x45, 0x46, 0x47
  16476. };
  16477. const byte aad[] = { /* additional data */
  16478. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16479. 0xc4, 0xc5, 0xc6, 0xc7
  16480. };
  16481. const byte cipher[] = { /* expected output from operation */
  16482. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16483. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16484. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16485. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16486. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16487. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16488. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16489. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16490. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16491. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16492. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16493. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16494. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16495. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16496. 0x61, 0x16
  16497. };
  16498. const byte authTag[] = { /* expected output from operation */
  16499. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16500. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16501. };
  16502. byte generatedCiphertext[272];
  16503. byte generatedPlaintext[272];
  16504. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16505. /* Initialize stack variables. */
  16506. XMEMSET(generatedCiphertext, 0, 272);
  16507. XMEMSET(generatedPlaintext, 0, 272);
  16508. /* Test Encrypt */
  16509. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16510. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16511. 0);
  16512. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16513. sizeof(cipher)/sizeof(byte)), 0);
  16514. /* Test bad args. */
  16515. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16516. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16517. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16518. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16519. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16520. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16521. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16522. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16523. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16524. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16525. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16526. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16527. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16528. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16529. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16530. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16531. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16532. sizeof(cipher), authTag, generatedPlaintext), 0);
  16533. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16534. sizeof(plaintext)/sizeof(byte)), 0);
  16535. /* Test bad args. */
  16536. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16537. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16538. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16539. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16540. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16541. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16542. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16543. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16544. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16545. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16546. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16547. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16548. #endif
  16549. return EXPECT_RESULT();
  16550. } /* END test_wc_ChaCha20Poly1305_aead */
  16551. /*
  16552. * Testing function for wc_Rc2SetKey().
  16553. */
  16554. static int test_wc_Rc2SetKey(void)
  16555. {
  16556. EXPECT_DECLS;
  16557. #ifdef WC_RC2
  16558. Rc2 rc2;
  16559. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16560. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16561. /* valid key and IV */
  16562. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16563. iv, 40), 0);
  16564. /* valid key, no IV */
  16565. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16566. NULL, 40), 0);
  16567. /* bad arguments */
  16568. /* null Rc2 struct */
  16569. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16570. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16571. /* null key */
  16572. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16573. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16574. /* key size == 0 */
  16575. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16576. /* key size > 128 */
  16577. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16578. /* effective bits == 0 */
  16579. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16580. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16581. /* effective bits > 1024 */
  16582. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16583. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16584. #endif
  16585. return EXPECT_RESULT();
  16586. } /* END test_wc_Rc2SetKey */
  16587. /*
  16588. * Testing function for wc_Rc2SetIV().
  16589. */
  16590. static int test_wc_Rc2SetIV(void)
  16591. {
  16592. EXPECT_DECLS;
  16593. #ifdef WC_RC2
  16594. Rc2 rc2;
  16595. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16596. /* valid IV */
  16597. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16598. /* valid NULL IV */
  16599. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16600. /* bad arguments */
  16601. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16602. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16603. #endif
  16604. return EXPECT_RESULT();
  16605. } /* END test_wc_Rc2SetIV */
  16606. /*
  16607. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16608. */
  16609. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16610. {
  16611. EXPECT_DECLS;
  16612. #ifdef WC_RC2
  16613. Rc2 rc2;
  16614. int effectiveKeyBits = 63;
  16615. byte cipher[RC2_BLOCK_SIZE];
  16616. byte plain[RC2_BLOCK_SIZE];
  16617. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16618. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16619. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16620. XMEMSET(cipher, 0, sizeof(cipher));
  16621. XMEMSET(plain, 0, sizeof(plain));
  16622. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16623. NULL, effectiveKeyBits), 0);
  16624. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16625. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16626. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16627. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16628. /* Rc2EcbEncrypt bad arguments */
  16629. /* null Rc2 struct */
  16630. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16631. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16632. /* null out buffer */
  16633. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16634. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16635. /* null input buffer */
  16636. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16637. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16638. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16639. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16640. /* Rc2EcbDecrypt bad arguments */
  16641. /* null Rc2 struct */
  16642. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  16643. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16644. /* null out buffer */
  16645. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  16646. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16647. /* null input buffer */
  16648. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  16649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16650. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16651. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16652. #endif
  16653. return EXPECT_RESULT();
  16654. } /* END test_wc_Rc2EcbEncryptDecrypt */
  16655. /*
  16656. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  16657. */
  16658. static int test_wc_Rc2CbcEncryptDecrypt(void)
  16659. {
  16660. EXPECT_DECLS;
  16661. #ifdef WC_RC2
  16662. Rc2 rc2;
  16663. int effectiveKeyBits = 63;
  16664. byte cipher[RC2_BLOCK_SIZE*2];
  16665. byte plain[RC2_BLOCK_SIZE*2];
  16666. /* vector taken from test.c */
  16667. byte key[] = {
  16668. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16669. };
  16670. byte iv[] = {
  16671. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16672. };
  16673. byte input[] = {
  16674. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16675. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16676. };
  16677. byte output[] = {
  16678. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  16679. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  16680. };
  16681. XMEMSET(cipher, 0, sizeof(cipher));
  16682. XMEMSET(plain, 0, sizeof(plain));
  16683. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16684. iv, effectiveKeyBits), 0);
  16685. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  16686. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  16687. /* reset IV for decrypt */
  16688. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16689. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  16690. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  16691. /* Rc2CbcEncrypt bad arguments */
  16692. /* null Rc2 struct */
  16693. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  16694. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16695. /* null out buffer */
  16696. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  16697. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16698. /* null input buffer */
  16699. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  16700. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16701. /* Rc2CbcDecrypt bad arguments */
  16702. /* in size is 0 */
  16703. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  16704. /* null Rc2 struct */
  16705. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  16706. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16707. /* null out buffer */
  16708. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  16709. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16710. /* null input buffer */
  16711. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  16712. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16713. #endif
  16714. return EXPECT_RESULT();
  16715. } /* END test_wc_Rc2CbcEncryptDecrypt */
  16716. /*
  16717. * Testing function for wc_AesSetIV
  16718. */
  16719. static int test_wc_AesSetIV(void)
  16720. {
  16721. int res = TEST_SKIPPED;
  16722. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  16723. Aes aes;
  16724. int ret = 0;
  16725. byte key16[] =
  16726. {
  16727. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16728. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16729. };
  16730. byte iv1[] = "1234567890abcdef";
  16731. byte iv2[] = "0987654321fedcba";
  16732. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  16733. if (ret != 0)
  16734. return ret;
  16735. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  16736. iv1, AES_ENCRYPTION);
  16737. if (ret == 0) {
  16738. ret = wc_AesSetIV(&aes, iv2);
  16739. }
  16740. /* Test bad args. */
  16741. if (ret == 0) {
  16742. ret = wc_AesSetIV(NULL, iv1);
  16743. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  16744. /* NULL iv should return 0. */
  16745. ret = wc_AesSetIV(&aes, NULL);
  16746. }
  16747. else {
  16748. ret = WOLFSSL_FATAL_ERROR;
  16749. }
  16750. }
  16751. wc_AesFree(&aes);
  16752. res = TEST_RES_CHECK(ret == 0);
  16753. #endif
  16754. return res;
  16755. } /* test_wc_AesSetIV */
  16756. /*
  16757. * Testing function for wc_AesSetKey().
  16758. */
  16759. static int test_wc_AesSetKey(void)
  16760. {
  16761. EXPECT_DECLS;
  16762. #ifndef NO_AES
  16763. Aes aes;
  16764. byte key16[] = {
  16765. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16766. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16767. };
  16768. #ifdef WOLFSSL_AES_192
  16769. byte key24[] = {
  16770. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16771. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16772. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16773. };
  16774. #endif
  16775. #ifdef WOLFSSL_AES_256
  16776. byte key32[] = {
  16777. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16778. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16779. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16780. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16781. };
  16782. #endif
  16783. byte badKey16[] = {
  16784. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16785. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  16786. };
  16787. byte iv[] = "1234567890abcdef";
  16788. XMEMSET(&aes, 0, sizeof(Aes));
  16789. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16790. #ifdef WOLFSSL_AES_128
  16791. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  16792. iv, AES_ENCRYPTION), 0);
  16793. #endif
  16794. #ifdef WOLFSSL_AES_192
  16795. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  16796. iv, AES_ENCRYPTION), 0);
  16797. #endif
  16798. #ifdef WOLFSSL_AES_256
  16799. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  16800. iv, AES_ENCRYPTION), 0);
  16801. #endif
  16802. /* Pass in bad args. */
  16803. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  16804. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16805. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  16806. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  16807. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16808. wc_AesFree(&aes);
  16809. #endif
  16810. return EXPECT_RESULT();
  16811. } /* END test_wc_AesSetKey */
  16812. /*
  16813. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  16814. * and wc_AesCbcDecryptWithKey()
  16815. */
  16816. static int test_wc_AesCbcEncryptDecrypt(void)
  16817. {
  16818. EXPECT_DECLS;
  16819. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  16820. defined(WOLFSSL_AES_256)
  16821. Aes aes;
  16822. byte key32[] = {
  16823. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16824. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16825. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16826. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16827. };
  16828. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  16829. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  16830. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  16831. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  16832. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  16833. };
  16834. byte iv[] = "1234567890abcdef";
  16835. byte enc[sizeof(vector)];
  16836. byte dec[sizeof(vector)];
  16837. byte dec2[sizeof(vector)];
  16838. /* Init stack variables. */
  16839. XMEMSET(&aes, 0, sizeof(Aes));
  16840. XMEMSET(enc, 0, sizeof(enc));
  16841. XMEMSET(dec, 0, sizeof(vector));
  16842. XMEMSET(dec2, 0, sizeof(vector));
  16843. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  16844. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  16845. AES_ENCRYPTION), 0);
  16846. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  16847. /* Re init for decrypt and set flag. */
  16848. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  16849. AES_DECRYPTION), 0);
  16850. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  16851. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  16852. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  16853. sizeof(key32)/sizeof(byte), iv), 0);
  16854. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  16855. /* Pass in bad args */
  16856. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  16857. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16858. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  16859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16860. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  16861. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16862. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  16863. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  16864. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  16865. #endif
  16866. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  16867. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  16868. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  16869. "mode (v2), skip test");
  16870. #else
  16871. /* Test passing in size of 0 */
  16872. XMEMSET(enc, 0, sizeof(enc));
  16873. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  16874. /* Check enc was not modified */
  16875. {
  16876. int i;
  16877. for (i = 0; i < (int)sizeof(enc); i++)
  16878. ExpectIntEQ(enc[i], 0);
  16879. }
  16880. #endif
  16881. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16882. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  16883. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16884. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  16885. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16886. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  16887. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  16888. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  16889. #else
  16890. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  16891. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16892. #endif
  16893. /* Test passing in size of 0 */
  16894. XMEMSET(dec, 0, sizeof(dec));
  16895. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  16896. /* Check dec was not modified */
  16897. {
  16898. int i;
  16899. for (i = 0; i < (int)sizeof(dec); i++)
  16900. ExpectIntEQ(dec[i], 0);
  16901. }
  16902. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  16903. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16904. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  16905. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16906. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  16907. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16908. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  16909. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16910. wc_AesFree(&aes);
  16911. #endif
  16912. return EXPECT_RESULT();
  16913. } /* END test_wc_AesCbcEncryptDecrypt */
  16914. /*
  16915. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  16916. */
  16917. static int test_wc_AesCtrEncryptDecrypt(void)
  16918. {
  16919. EXPECT_DECLS;
  16920. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  16921. Aes aesEnc;
  16922. Aes aesDec;
  16923. byte key32[] = {
  16924. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16925. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16926. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16927. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16928. };
  16929. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16930. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16931. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16932. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16933. };
  16934. byte iv[] = "1234567890abcdef";
  16935. byte enc[AES_BLOCK_SIZE * 2];
  16936. byte dec[AES_BLOCK_SIZE * 2];
  16937. /* Init stack variables. */
  16938. XMEMSET(&aesEnc, 0, sizeof(Aes));
  16939. XMEMSET(&aesDec, 0, sizeof(Aes));
  16940. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  16941. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  16942. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  16943. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  16944. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  16945. AES_ENCRYPTION), 0);
  16946. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  16947. sizeof(vector)/sizeof(byte)), 0);
  16948. /* Decrypt with wc_AesCtrEncrypt() */
  16949. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  16950. AES_ENCRYPTION), 0);
  16951. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  16952. 0);
  16953. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  16954. /* Test bad args. */
  16955. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  16956. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16957. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  16958. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16959. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  16960. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16961. wc_AesFree(&aesEnc);
  16962. wc_AesFree(&aesDec);
  16963. #endif
  16964. return EXPECT_RESULT();
  16965. } /* END test_wc_AesCtrEncryptDecrypt */
  16966. /*
  16967. * test function for wc_AesGcmSetKey()
  16968. */
  16969. static int test_wc_AesGcmSetKey(void)
  16970. {
  16971. EXPECT_DECLS;
  16972. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  16973. Aes aes;
  16974. #ifdef WOLFSSL_AES_128
  16975. byte key16[] = {
  16976. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16977. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16978. };
  16979. #endif
  16980. #ifdef WOLFSSL_AES_192
  16981. byte key24[] = {
  16982. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16983. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16984. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16985. };
  16986. #endif
  16987. #ifdef WOLFSSL_AES_256
  16988. byte key32[] = {
  16989. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16990. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16991. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16992. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16993. };
  16994. #endif
  16995. byte badKey16[] = {
  16996. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16997. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  16998. };
  16999. byte badKey24[] = {
  17000. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17001. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17002. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  17003. };
  17004. byte badKey32[] = {
  17005. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  17006. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17007. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17008. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17009. };
  17010. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17011. #ifdef WOLFSSL_AES_128
  17012. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  17013. #endif
  17014. #ifdef WOLFSSL_AES_192
  17015. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  17016. #endif
  17017. #ifdef WOLFSSL_AES_256
  17018. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17019. #endif
  17020. /* Pass in bad args. */
  17021. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  17022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17023. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  17024. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17025. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  17026. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17027. wc_AesFree(&aes);
  17028. #endif
  17029. return EXPECT_RESULT();
  17030. } /* END test_wc_AesGcmSetKey */
  17031. /*
  17032. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  17033. */
  17034. static int test_wc_AesGcmEncryptDecrypt(void)
  17035. {
  17036. EXPECT_DECLS;
  17037. /* WOLFSSL_AFALG requires 12 byte IV */
  17038. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  17039. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  17040. Aes aes;
  17041. byte key32[] = {
  17042. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17043. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17044. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17045. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17046. };
  17047. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17048. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17049. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17050. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17051. };
  17052. const byte a[] = {
  17053. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17054. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17055. 0xab, 0xad, 0xda, 0xd2
  17056. };
  17057. byte iv[] = "1234567890a";
  17058. byte longIV[] = "1234567890abcdefghij";
  17059. byte enc[sizeof(vector)];
  17060. byte resultT[AES_BLOCK_SIZE];
  17061. byte dec[sizeof(vector)];
  17062. /* Init stack variables. */
  17063. XMEMSET(&aes, 0, sizeof(Aes));
  17064. XMEMSET(enc, 0, sizeof(vector));
  17065. XMEMSET(dec, 0, sizeof(vector));
  17066. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  17067. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17068. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17069. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17070. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17071. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  17072. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17073. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17074. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  17075. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  17076. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17077. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17078. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17079. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17080. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17081. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17082. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  17083. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17084. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17085. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  17086. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17087. /* FIPS does not check the lower bound of ivSz */
  17088. #else
  17089. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  17090. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17091. #endif
  17092. /* This case is now considered good. Long IVs are now allowed.
  17093. * Except for the original FIPS release, it still has an upper
  17094. * bound on the IV length. */
  17095. #if (!defined(HAVE_FIPS) || \
  17096. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17097. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17098. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  17099. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17100. 0);
  17101. #else
  17102. (void)longIV;
  17103. #endif /* Old FIPS */
  17104. /* END wc_AesGcmEncrypt */
  17105. #ifdef HAVE_AES_DECRYPT
  17106. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17107. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17108. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17109. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  17110. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17111. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17112. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  17113. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17114. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17115. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  17116. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17117. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17118. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17119. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  17120. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17121. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  17122. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17123. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17124. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  17125. #else
  17126. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17127. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17128. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17129. #endif
  17130. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17131. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  17132. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17133. /* FIPS does not check the lower bound of ivSz */
  17134. #else
  17135. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  17136. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17137. #endif
  17138. #endif /* HAVE_AES_DECRYPT */
  17139. wc_AesFree(&aes);
  17140. #endif
  17141. return EXPECT_RESULT();
  17142. } /* END test_wc_AesGcmEncryptDecrypt */
  17143. /*
  17144. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  17145. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  17146. */
  17147. static int test_wc_AesGcmMixedEncDecLongIV(void)
  17148. {
  17149. EXPECT_DECLS;
  17150. #if (!defined(HAVE_FIPS) || \
  17151. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17152. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  17153. const byte key[] = {
  17154. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17155. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17156. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17157. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17158. };
  17159. const byte in[] = {
  17160. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17161. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17162. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17163. };
  17164. const byte aad[] = {
  17165. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17166. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17167. 0xab, 0xad, 0xda, 0xd2
  17168. };
  17169. Aes aesEnc;
  17170. Aes aesDec;
  17171. byte iv[] = "1234567890abcdefghij";
  17172. byte out[sizeof(in)];
  17173. byte plain[sizeof(in)];
  17174. byte tag[AES_BLOCK_SIZE];
  17175. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17176. XMEMSET(&aesDec, 0, sizeof(Aes));
  17177. XMEMSET(out, 0, sizeof(out));
  17178. XMEMSET(plain, 0, sizeof(plain));
  17179. XMEMSET(tag, 0, sizeof(tag));
  17180. /* Perform one-shot encryption using long IV */
  17181. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17182. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  17183. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  17184. tag, sizeof(tag), aad, sizeof(aad)), 0);
  17185. /* Perform streaming decryption using long IV */
  17186. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17187. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  17188. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  17189. sizeof(aad)), 0);
  17190. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  17191. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  17192. /* Free resources */
  17193. wc_AesFree(&aesEnc);
  17194. wc_AesFree(&aesDec);
  17195. #endif
  17196. return EXPECT_RESULT();
  17197. } /* END wc_AesGcmMixedEncDecLongIV */
  17198. /*
  17199. * unit test for wc_GmacSetKey()
  17200. */
  17201. static int test_wc_GmacSetKey(void)
  17202. {
  17203. EXPECT_DECLS;
  17204. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17205. Gmac gmac;
  17206. byte key16[] = {
  17207. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17208. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17209. };
  17210. #ifdef WOLFSSL_AES_192
  17211. byte key24[] = {
  17212. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17213. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17214. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17215. };
  17216. #endif
  17217. #ifdef WOLFSSL_AES_256
  17218. byte key32[] = {
  17219. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17220. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17221. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17222. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17223. };
  17224. #endif
  17225. byte badKey16[] = {
  17226. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17227. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17228. };
  17229. byte badKey24[] = {
  17230. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17231. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17232. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17233. };
  17234. byte badKey32[] = {
  17235. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17236. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17237. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17238. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17239. };
  17240. XMEMSET(&gmac, 0, sizeof(Gmac));
  17241. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17242. #ifdef WOLFSSL_AES_128
  17243. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17244. #endif
  17245. #ifdef WOLFSSL_AES_192
  17246. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17247. #endif
  17248. #ifdef WOLFSSL_AES_256
  17249. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17250. #endif
  17251. /* Pass in bad args. */
  17252. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17254. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17256. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17257. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17258. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17260. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17262. wc_AesFree(&gmac.aes);
  17263. #endif
  17264. return EXPECT_RESULT();
  17265. } /* END test_wc_GmacSetKey */
  17266. /*
  17267. * unit test for wc_GmacUpdate
  17268. */
  17269. static int test_wc_GmacUpdate(void)
  17270. {
  17271. EXPECT_DECLS;
  17272. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17273. Gmac gmac;
  17274. #ifdef WOLFSSL_AES_128
  17275. const byte key16[] = {
  17276. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17277. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17278. };
  17279. #endif
  17280. #ifdef WOLFSSL_AES_192
  17281. byte key24[] = {
  17282. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17283. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17284. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17285. };
  17286. #endif
  17287. #ifdef WOLFSSL_AES_256
  17288. byte key32[] = {
  17289. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17290. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17291. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17292. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17293. };
  17294. #endif
  17295. #ifdef WOLFSSL_AES_128
  17296. const byte authIn[] = {
  17297. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17298. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17299. };
  17300. #endif
  17301. #ifdef WOLFSSL_AES_192
  17302. const byte authIn2[] = {
  17303. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17304. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17305. };
  17306. #endif
  17307. const byte authIn3[] = {
  17308. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17309. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17310. };
  17311. #ifdef WOLFSSL_AES_128
  17312. const byte tag1[] = { /* Known. */
  17313. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17314. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17315. };
  17316. #endif
  17317. #ifdef WOLFSSL_AES_192
  17318. const byte tag2[] = { /* Known */
  17319. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17320. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17321. };
  17322. #endif
  17323. const byte tag3[] = { /* Known */
  17324. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17325. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17326. };
  17327. #ifdef WOLFSSL_AES_128
  17328. const byte iv[] = {
  17329. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17330. 0xe2, 0x8c, 0x8f, 0x16
  17331. };
  17332. #endif
  17333. #ifdef WOLFSSL_AES_192
  17334. const byte iv2[] = {
  17335. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17336. 0x7e, 0x1a, 0x6f, 0xbc
  17337. };
  17338. #endif
  17339. const byte iv3[] = {
  17340. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17341. 0xc3, 0xfb, 0x6c, 0x8a
  17342. };
  17343. byte tagOut[16];
  17344. byte tagOut2[24];
  17345. byte tagOut3[32];
  17346. /* Init stack variables. */
  17347. XMEMSET(&gmac, 0, sizeof(Gmac));
  17348. XMEMSET(tagOut, 0, sizeof(tagOut));
  17349. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17350. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17351. #ifdef WOLFSSL_AES_128
  17352. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17353. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17354. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17355. tagOut, sizeof(tag1)), 0);
  17356. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17357. wc_AesFree(&gmac.aes);
  17358. #endif
  17359. #ifdef WOLFSSL_AES_192
  17360. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17361. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17362. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17363. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17364. tagOut2, sizeof(tag2)), 0);
  17365. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17366. wc_AesFree(&gmac.aes);
  17367. #endif
  17368. #ifdef WOLFSSL_AES_256
  17369. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17370. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17371. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17372. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17373. tagOut3, sizeof(tag3)), 0);
  17374. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17375. wc_AesFree(&gmac.aes);
  17376. #endif
  17377. /* Pass bad args. */
  17378. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17379. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17380. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17381. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17382. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17383. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17384. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17385. wc_AesFree(&gmac.aes);
  17386. #endif
  17387. return EXPECT_RESULT();
  17388. } /* END test_wc_GmacUpdate */
  17389. /*
  17390. * testing wc_CamelliaSetKey
  17391. */
  17392. static int test_wc_CamelliaSetKey(void)
  17393. {
  17394. EXPECT_DECLS;
  17395. #ifdef HAVE_CAMELLIA
  17396. Camellia camellia;
  17397. /*128-bit key*/
  17398. static const byte key16[] = {
  17399. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17400. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17401. };
  17402. /* 192-bit key */
  17403. static const byte key24[] = {
  17404. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17405. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17406. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17407. };
  17408. /* 256-bit key */
  17409. static const byte key32[] = {
  17410. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17411. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17412. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17413. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17414. };
  17415. static const byte iv[] = {
  17416. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17417. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17418. };
  17419. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17420. 0);
  17421. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17422. NULL), 0);
  17423. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17424. 0);
  17425. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17426. NULL), 0);
  17427. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17428. 0);
  17429. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17430. NULL), 0);
  17431. /* Bad args. */
  17432. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17434. #endif
  17435. return EXPECT_RESULT();
  17436. } /* END test_wc_CammeliaSetKey */
  17437. /*
  17438. * Testing wc_CamelliaSetIV()
  17439. */
  17440. static int test_wc_CamelliaSetIV(void)
  17441. {
  17442. EXPECT_DECLS;
  17443. #ifdef HAVE_CAMELLIA
  17444. Camellia camellia;
  17445. static const byte iv[] = {
  17446. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17447. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17448. };
  17449. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17450. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17451. /* Bad args. */
  17452. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17453. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17454. #endif
  17455. return EXPECT_RESULT();
  17456. } /* END test_wc_CamelliaSetIV*/
  17457. /*
  17458. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17459. */
  17460. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17461. {
  17462. EXPECT_DECLS;
  17463. #ifdef HAVE_CAMELLIA
  17464. Camellia camellia;
  17465. static const byte key24[] = {
  17466. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17467. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17468. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17469. };
  17470. static const byte iv[] = {
  17471. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17472. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17473. };
  17474. static const byte plainT[] = {
  17475. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17476. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17477. };
  17478. byte enc[sizeof(plainT)];
  17479. byte dec[sizeof(enc)];
  17480. /* Init stack variables.*/
  17481. XMEMSET(enc, 0, 16);
  17482. XMEMSET(enc, 0, 16);
  17483. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17484. 0);
  17485. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17486. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17487. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17488. /* Pass bad args. */
  17489. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17490. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17491. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17492. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17493. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17494. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17495. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17496. #endif
  17497. return EXPECT_RESULT();
  17498. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17499. /*
  17500. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17501. */
  17502. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17503. {
  17504. EXPECT_DECLS;
  17505. #ifdef HAVE_CAMELLIA
  17506. Camellia camellia;
  17507. static const byte key24[] = {
  17508. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17509. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17510. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17511. };
  17512. static const byte plainT[] = {
  17513. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17514. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17515. };
  17516. byte enc[CAMELLIA_BLOCK_SIZE];
  17517. byte dec[CAMELLIA_BLOCK_SIZE];
  17518. /* Init stack variables. */
  17519. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17520. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17521. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17522. NULL), 0);
  17523. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17524. CAMELLIA_BLOCK_SIZE), 0);
  17525. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17526. NULL), 0);
  17527. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17528. 0);
  17529. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17530. /* Pass in bad args. */
  17531. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17532. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17533. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17534. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17535. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17536. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17537. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17538. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17539. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17540. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17541. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17542. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17543. #endif
  17544. return EXPECT_RESULT();
  17545. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17546. /*
  17547. * Testing wc_Arc4SetKey()
  17548. */
  17549. static int test_wc_Arc4SetKey(void)
  17550. {
  17551. EXPECT_DECLS;
  17552. #ifndef NO_RC4
  17553. Arc4 arc;
  17554. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17555. int keyLen = 8;
  17556. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17557. /* Test bad args. */
  17558. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17559. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17560. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17561. #endif
  17562. return EXPECT_RESULT();
  17563. } /* END test_wc_Arc4SetKey */
  17564. /*
  17565. * Testing wc_Arc4Process for ENC/DEC.
  17566. */
  17567. static int test_wc_Arc4Process(void)
  17568. {
  17569. EXPECT_DECLS;
  17570. #ifndef NO_RC4
  17571. Arc4 enc;
  17572. Arc4 dec;
  17573. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17574. int keyLen = 8;
  17575. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17576. byte cipher[8];
  17577. byte plain[8];
  17578. /* Init stack variables */
  17579. XMEMSET(&enc, 0, sizeof(Arc4));
  17580. XMEMSET(&dec, 0, sizeof(Arc4));
  17581. XMEMSET(cipher, 0, sizeof(cipher));
  17582. XMEMSET(plain, 0, sizeof(plain));
  17583. /* Use for async. */
  17584. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17585. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17586. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17587. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17588. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17589. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17590. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17591. /* Bad args. */
  17592. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17593. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17594. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17595. wc_Arc4Free(&enc);
  17596. wc_Arc4Free(&dec);
  17597. #endif
  17598. return EXPECT_RESULT();
  17599. } /* END test_wc_Arc4Process */
  17600. /*
  17601. * Testing wc_Init RsaKey()
  17602. */
  17603. static int test_wc_InitRsaKey(void)
  17604. {
  17605. EXPECT_DECLS;
  17606. #ifndef NO_RSA
  17607. RsaKey key;
  17608. XMEMSET(&key, 0, sizeof(RsaKey));
  17609. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17610. /* Test bad args. */
  17611. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17612. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17613. #endif
  17614. return EXPECT_RESULT();
  17615. } /* END test_wc_InitRsaKey */
  17616. /*
  17617. * Testing wc_RsaPrivateKeyDecode()
  17618. */
  17619. static int test_wc_RsaPrivateKeyDecode(void)
  17620. {
  17621. EXPECT_DECLS;
  17622. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17623. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17624. RsaKey key;
  17625. byte* tmp = NULL;
  17626. word32 idx = 0;
  17627. int bytes = 0;
  17628. XMEMSET(&key, 0, sizeof(RsaKey));
  17629. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17630. DYNAMIC_TYPE_TMP_BUFFER));
  17631. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17632. if (tmp != NULL) {
  17633. #ifdef USE_CERT_BUFFERS_1024
  17634. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17635. bytes = sizeof_client_key_der_1024;
  17636. #else
  17637. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17638. bytes = sizeof_client_key_der_2048;
  17639. #endif /* Use cert buffers. */
  17640. }
  17641. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17642. /* Test bad args. */
  17643. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  17644. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17645. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  17646. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17647. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17648. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17649. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17650. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17651. #endif
  17652. return EXPECT_RESULT();
  17653. } /* END test_wc_RsaPrivateKeyDecode */
  17654. /*
  17655. * Testing wc_RsaPublicKeyDecode()
  17656. */
  17657. static int test_wc_RsaPublicKeyDecode(void)
  17658. {
  17659. EXPECT_DECLS;
  17660. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17661. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17662. RsaKey keyPub;
  17663. byte* tmp = NULL;
  17664. word32 idx = 0;
  17665. int bytes = 0;
  17666. word32 keySz = 0;
  17667. word32 tstKeySz = 0;
  17668. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17669. XFILE f = XBADFILE;
  17670. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  17671. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  17672. byte buf[4096];
  17673. #endif
  17674. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  17675. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  17676. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  17677. if (tmp != NULL) {
  17678. #ifdef USE_CERT_BUFFERS_1024
  17679. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  17680. bytes = sizeof_client_keypub_der_1024;
  17681. keySz = 1024;
  17682. #else
  17683. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  17684. bytes = sizeof_client_keypub_der_2048;
  17685. keySz = 2048;
  17686. #endif
  17687. }
  17688. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  17689. /* Pass in bad args. */
  17690. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  17691. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17692. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  17693. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17694. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17695. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17696. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  17697. /* Test for getting modulus key size */
  17698. idx = 0;
  17699. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  17700. &tstKeySz, NULL, NULL), 0);
  17701. ExpectIntEQ(tstKeySz, keySz/8);
  17702. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17703. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  17704. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17705. if (f != XBADFILE) {
  17706. XFCLOSE(f);
  17707. f = XBADFILE;
  17708. }
  17709. idx = 0;
  17710. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17711. NULL), 0);
  17712. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  17713. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17714. if (f != XBADFILE)
  17715. XFCLOSE(f);
  17716. idx = 0;
  17717. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17718. NULL), 0);
  17719. #endif
  17720. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17721. #endif
  17722. return EXPECT_RESULT();
  17723. } /* END test_wc_RsaPublicKeyDecode */
  17724. /*
  17725. * Testing wc_RsaPublicKeyDecodeRaw()
  17726. */
  17727. static int test_wc_RsaPublicKeyDecodeRaw(void)
  17728. {
  17729. EXPECT_DECLS;
  17730. #if !defined(NO_RSA)
  17731. RsaKey key;
  17732. const byte n = 0x23;
  17733. const byte e = 0x03;
  17734. int nSz = sizeof(n);
  17735. int eSz = sizeof(e);
  17736. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17737. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  17738. /* Pass in bad args. */
  17739. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  17740. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17741. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  17742. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17743. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  17744. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17745. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17746. #endif
  17747. return EXPECT_RESULT();
  17748. } /* END test_wc_RsaPublicKeyDecodeRaw */
  17749. /*
  17750. * Testing wc_RsaPrivateKeyDecodeRaw()
  17751. */
  17752. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  17753. {
  17754. EXPECT_DECLS;
  17755. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  17756. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  17757. RsaKey key;
  17758. const byte n = 33;
  17759. const byte e = 3;
  17760. const byte d = 7;
  17761. const byte u = 2;
  17762. const byte p = 3;
  17763. const byte q = 11;
  17764. const byte dp = 1;
  17765. const byte dq = 7;
  17766. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17767. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17768. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17769. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17770. NULL, 0, &key), 0);
  17771. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17772. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17773. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17774. NULL, 0, &key), 0);
  17775. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17776. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17777. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17778. &dq, sizeof(dq), &key), 0);
  17779. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17780. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17781. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17782. &dq, sizeof(dq), &key), 0);
  17783. /* Pass in bad args. */
  17784. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  17785. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17786. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17787. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17788. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  17789. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17790. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17791. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17792. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17793. NULL, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17794. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17795. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17796. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17797. &e, 0, &d, sizeof(d), &u, sizeof(u),
  17798. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17799. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17800. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17801. &e, sizeof(e), NULL, sizeof(d), &u, sizeof(u),
  17802. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17803. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17804. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17805. &e, sizeof(e), &d, 0, &u, sizeof(u),
  17806. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17807. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17808. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17809. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17810. NULL, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17811. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17812. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17813. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17814. &p, 0, &q, sizeof(q), &dp, sizeof(dp),
  17815. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17816. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17817. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17818. &p, sizeof(p), NULL, sizeof(q), &dp, sizeof(dp),
  17819. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17820. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17821. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17822. &p, sizeof(p), &q, 0, &dp, sizeof(dp),
  17823. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17824. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  17825. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17826. &e, sizeof(e), &d, sizeof(d), &u, 0,
  17827. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17828. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17829. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17830. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  17831. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17832. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17833. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17834. &e, sizeof(e), &d, sizeof(d), &u, 0,
  17835. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  17836. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17837. #endif
  17838. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17839. #endif
  17840. return EXPECT_RESULT();
  17841. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  17842. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  17843. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  17844. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  17845. * trying until it gets a probable prime. */
  17846. #ifdef HAVE_FIPS
  17847. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  17848. {
  17849. int ret;
  17850. for (;;) {
  17851. ret = wc_MakeRsaKey(key, size, e, rng);
  17852. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  17853. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  17854. "trying again.\n");
  17855. }
  17856. return ret;
  17857. }
  17858. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  17859. #else
  17860. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  17861. #endif
  17862. #endif
  17863. /*
  17864. * Testing wc_MakeRsaKey()
  17865. */
  17866. static int test_wc_MakeRsaKey(void)
  17867. {
  17868. EXPECT_DECLS;
  17869. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  17870. RsaKey genKey;
  17871. WC_RNG rng;
  17872. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  17873. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  17874. int bits = 1024;
  17875. #else
  17876. int bits = 2048;
  17877. #endif
  17878. XMEMSET(&genKey, 0, sizeof(RsaKey));
  17879. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17880. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  17881. ExpectIntEQ(wc_InitRng(&rng), 0);
  17882. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  17883. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  17884. /* Test bad args. */
  17885. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17886. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  17887. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17888. /* e < 3 */
  17889. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17890. /* e & 1 == 0 */
  17891. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17892. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  17893. #endif
  17894. return EXPECT_RESULT();
  17895. } /* END test_wc_MakeRsaKey */
  17896. /*
  17897. * Test the bounds checking on the cipher text versus the key modulus.
  17898. * 1. Make a new RSA key.
  17899. * 2. Set c to 1.
  17900. * 3. Decrypt c into k. (error)
  17901. * 4. Copy the key modulus to c and sub 1 from the copy.
  17902. * 5. Decrypt c into k. (error)
  17903. * Valid bounds test cases are covered by all the other RSA tests.
  17904. */
  17905. static int test_RsaDecryptBoundsCheck(void)
  17906. {
  17907. EXPECT_DECLS;
  17908. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  17909. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  17910. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  17911. WC_RNG rng;
  17912. RsaKey key;
  17913. byte flatC[256];
  17914. word32 flatCSz;
  17915. byte out[256];
  17916. word32 outSz = sizeof(out);
  17917. XMEMSET(&key, 0, sizeof(RsaKey));
  17918. XMEMSET(&rng, 0, sizeof(WC_RNG));
  17919. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17920. ExpectIntEQ(wc_InitRng(&rng), 0);
  17921. if (EXPECT_SUCCESS()) {
  17922. const byte* derKey;
  17923. word32 derKeySz;
  17924. word32 idx = 0;
  17925. #ifdef USE_CERT_BUFFERS_1024
  17926. derKey = server_key_der_1024;
  17927. derKeySz = (word32)sizeof_server_key_der_1024;
  17928. flatCSz = 128;
  17929. #else
  17930. derKey = server_key_der_2048;
  17931. derKeySz = (word32)sizeof_server_key_der_2048;
  17932. flatCSz = 256;
  17933. #endif
  17934. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  17935. }
  17936. if (EXPECT_SUCCESS()) {
  17937. XMEMSET(flatC, 0, flatCSz);
  17938. flatC[flatCSz-1] = 1;
  17939. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  17940. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  17941. if (EXPECT_SUCCESS()) {
  17942. mp_int c;
  17943. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  17944. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  17945. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  17946. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  17947. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  17948. mp_clear(&c);
  17949. }
  17950. }
  17951. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17952. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  17953. #endif
  17954. return EXPECT_RESULT();
  17955. } /* END test_wc_RsaDecryptBoundsCheck */
  17956. /*
  17957. * Testing wc_SetKeyUsage()
  17958. */
  17959. static int test_wc_SetKeyUsage(void)
  17960. {
  17961. EXPECT_DECLS;
  17962. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  17963. Cert myCert;
  17964. ExpectIntEQ(wc_InitCert(&myCert), 0);
  17965. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  17966. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  17967. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  17968. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  17969. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  17970. /* Test bad args. */
  17971. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17972. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17973. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  17974. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  17975. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  17976. WC_NO_ERR_TRACE(KEYUSAGE_E));
  17977. #endif
  17978. return EXPECT_RESULT();
  17979. } /* END test_wc_SetKeyUsage */
  17980. /*
  17981. * Testing wc_CheckProbablePrime()
  17982. */
  17983. static int test_wc_CheckProbablePrime(void)
  17984. {
  17985. EXPECT_DECLS;
  17986. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  17987. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  17988. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  17989. RsaKey key;
  17990. WC_RNG rng;
  17991. byte e[3];
  17992. word32 eSz = (word32)sizeof(e);
  17993. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  17994. word32 nSz = (word32)sizeof(n);
  17995. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  17996. word32 dSz = (word32)sizeof(d);
  17997. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  17998. word32 pSz = (word32)sizeof(p);
  17999. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18000. word32 qSz = (word32)sizeof(q);
  18001. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  18002. int* isPrime;
  18003. int test[5];
  18004. isPrime = test;
  18005. XMEMSET(&key, 0, sizeof(RsaKey));
  18006. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18007. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18008. ExpectIntEQ(wc_InitRng(&rng), 0);
  18009. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18010. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  18011. WC_RSA_EXPONENT, &rng), 0);
  18012. PRIVATE_KEY_UNLOCK();
  18013. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  18014. &qSz), 0);
  18015. PRIVATE_KEY_LOCK();
  18016. /* Bad cases */
  18017. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  18018. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18019. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  18020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18021. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  18022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18023. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  18024. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18025. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  18026. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18027. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  18028. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18029. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  18030. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18031. /* Good case */
  18032. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  18033. 0);
  18034. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18035. wc_FreeRng(&rng);
  18036. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  18037. #endif
  18038. return EXPECT_RESULT();
  18039. } /* END test_wc_CheckProbablePrime */
  18040. /*
  18041. * Testing wc_RsaPSS_Verify()
  18042. */
  18043. static int test_wc_RsaPSS_Verify(void)
  18044. {
  18045. EXPECT_DECLS;
  18046. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18047. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18048. RsaKey key;
  18049. WC_RNG rng;
  18050. int sz = 256;
  18051. const char* szMessage = "This is the string to be signed";
  18052. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18053. unsigned char pDecrypted[2048/8];
  18054. byte* pt = pDecrypted;
  18055. word32 outLen = sizeof(pDecrypted);
  18056. XMEMSET(&key, 0, sizeof(RsaKey));
  18057. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18058. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18059. ExpectIntEQ(wc_InitRng(&rng), 0);
  18060. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18061. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18062. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  18063. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  18064. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18065. /* Bad cases */
  18066. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  18067. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18068. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  18069. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18070. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  18071. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18072. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  18073. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18074. /* Good case */
  18075. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  18076. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18077. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18078. wc_FreeRng(&rng);
  18079. #endif
  18080. return EXPECT_RESULT();
  18081. } /* END test_wc_RsaPSS_Verify */
  18082. /*
  18083. * Testing wc_RsaPSS_VerifyCheck()
  18084. */
  18085. static int test_wc_RsaPSS_VerifyCheck(void)
  18086. {
  18087. EXPECT_DECLS;
  18088. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18089. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18090. RsaKey key;
  18091. WC_RNG rng;
  18092. int sz = 256; /* 2048/8 */
  18093. byte digest[32];
  18094. word32 digestSz = sizeof(digest);
  18095. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18096. word32 pSignatureSz = sizeof(pSignature);
  18097. unsigned char pDecrypted[2048/8];
  18098. byte* pt = pDecrypted;
  18099. word32 outLen = sizeof(pDecrypted);
  18100. XMEMSET(&key, 0, sizeof(RsaKey));
  18101. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18102. XMEMSET(digest, 0, sizeof(digest));
  18103. XMEMSET(pSignature, 0, sizeof(pSignature));
  18104. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18105. ExpectIntEQ(wc_InitRng(&rng), 0);
  18106. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18107. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18108. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18109. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18110. 0);
  18111. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  18112. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18113. /* Bad cases */
  18114. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  18115. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18116. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  18117. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18118. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  18119. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18120. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  18121. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18122. /* Good case */
  18123. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  18124. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18125. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18126. wc_FreeRng(&rng);
  18127. #endif
  18128. return EXPECT_RESULT();
  18129. } /* END test_wc_RsaPSS_VerifyCheck */
  18130. /*
  18131. * Testing wc_RsaPSS_VerifyCheckInline()
  18132. */
  18133. static int test_wc_RsaPSS_VerifyCheckInline(void)
  18134. {
  18135. EXPECT_DECLS;
  18136. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18137. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18138. RsaKey key;
  18139. WC_RNG rng;
  18140. int sz = 256;
  18141. byte digest[32];
  18142. word32 digestSz = sizeof(digest);
  18143. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18144. unsigned char pDecrypted[2048/8];
  18145. byte* pt = pDecrypted;
  18146. XMEMSET(&key, 0, sizeof(RsaKey));
  18147. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18148. XMEMSET(digest, 0, sizeof(digest));
  18149. XMEMSET(pSignature, 0, sizeof(pSignature));
  18150. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18151. ExpectIntEQ(wc_InitRng(&rng), 0);
  18152. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18153. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18154. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18155. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18156. 0);
  18157. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  18158. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18159. /* Bad Cases */
  18160. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  18161. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18162. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  18163. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18164. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  18165. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18166. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18167. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18168. /* Good case */
  18169. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18170. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18171. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18172. wc_FreeRng(&rng);
  18173. #endif
  18174. return EXPECT_RESULT();
  18175. } /* END test_wc_RsaPSS_VerifyCheckInline */
  18176. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18177. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  18178. {
  18179. (void)flag;
  18180. (void)type;
  18181. (void)file;
  18182. (void)line;
  18183. }
  18184. #endif
  18185. /*
  18186. * Testing wc_LockMutex_ex
  18187. */
  18188. static int test_wc_LockMutex_ex(void)
  18189. {
  18190. EXPECT_DECLS;
  18191. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18192. int flag = CRYPTO_LOCK;
  18193. int type = 0;
  18194. const char* file = "./test-LockMutex_ex.txt";
  18195. int line = 0;
  18196. /* without SetMutexCb */
  18197. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  18198. /* with SetMutexCb */
  18199. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18200. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  18201. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18202. #endif
  18203. return EXPECT_RESULT();
  18204. } /* End test_wc_LockMutex_ex*/
  18205. /*
  18206. * Testing wc_SetMutexCb
  18207. */
  18208. static int test_wc_SetMutexCb(void)
  18209. {
  18210. EXPECT_DECLS;
  18211. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18212. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18213. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18214. #endif
  18215. return EXPECT_RESULT();
  18216. } /* End test_wc_SetMutexCb*/
  18217. /*
  18218. * Testing wc_RsaKeyToDer()
  18219. */
  18220. static int test_wc_RsaKeyToDer(void)
  18221. {
  18222. EXPECT_DECLS;
  18223. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18224. RsaKey genKey;
  18225. WC_RNG rng;
  18226. byte* der = NULL;
  18227. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18228. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18229. int bits = 1024;
  18230. word32 derSz = 611;
  18231. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18232. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18233. #else
  18234. int bits = 2048;
  18235. word32 derSz = 1196;
  18236. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18237. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18238. #endif
  18239. XMEMSET(&rng, 0, sizeof(rng));
  18240. XMEMSET(&genKey, 0, sizeof(genKey));
  18241. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18242. /* Init structures. */
  18243. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18244. ExpectIntEQ(wc_InitRng(&rng), 0);
  18245. /* Make key. */
  18246. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18247. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18248. /* Pass good/bad args. */
  18249. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18250. /* Get just the output length */
  18251. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18252. /* Try Public Key. */
  18253. genKey.type = 0;
  18254. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18255. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18256. /* Put back to Private Key */
  18257. genKey.type = 1;
  18258. #endif
  18259. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18260. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18261. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18262. #endif
  18263. return EXPECT_RESULT();
  18264. } /* END test_wc_RsaKeyToDer */
  18265. /*
  18266. * Testing wc_RsaKeyToPublicDer()
  18267. */
  18268. static int test_wc_RsaKeyToPublicDer(void)
  18269. {
  18270. EXPECT_DECLS;
  18271. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18272. RsaKey key;
  18273. WC_RNG rng;
  18274. byte* der = NULL;
  18275. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18276. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18277. int bits = 1024;
  18278. word32 derLen = 162;
  18279. #else
  18280. int bits = 2048;
  18281. word32 derLen = 294;
  18282. #endif
  18283. int ret;
  18284. XMEMSET(&rng, 0, sizeof(rng));
  18285. XMEMSET(&key, 0, sizeof(key));
  18286. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18287. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18288. ExpectIntEQ(wc_InitRng(&rng), 0);
  18289. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18290. /* test getting size only */
  18291. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18292. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18293. /* test getting size only */
  18294. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18295. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18296. /* Pass in bad args. */
  18297. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18298. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18299. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18300. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18301. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18302. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18303. #endif
  18304. return EXPECT_RESULT();
  18305. } /* END test_wc_RsaKeyToPublicDer */
  18306. /*
  18307. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18308. */
  18309. static int test_wc_RsaPublicEncryptDecrypt(void)
  18310. {
  18311. EXPECT_DECLS;
  18312. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18313. RsaKey key;
  18314. WC_RNG rng;
  18315. const char inStr[] = TEST_STRING;
  18316. const word32 plainLen = (word32)TEST_STRING_SZ;
  18317. const word32 inLen = (word32)TEST_STRING_SZ;
  18318. int bits = TEST_RSA_BITS;
  18319. const word32 cipherLen = TEST_RSA_BYTES;
  18320. word32 cipherLenResult = cipherLen;
  18321. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18322. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18323. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18324. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18325. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18326. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18327. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18328. ExpectNotNull(in);
  18329. ExpectNotNull(plain);
  18330. ExpectNotNull(cipher);
  18331. #endif
  18332. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18333. /* Initialize stack structures. */
  18334. XMEMSET(&key, 0, sizeof(RsaKey));
  18335. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18336. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18337. ExpectIntEQ(wc_InitRng(&rng), 0);
  18338. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18339. /* Encrypt. */
  18340. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18341. cipherLen, &key, &rng), 0);
  18342. /* Pass bad args - tested in another testing function.*/
  18343. /* Decrypt */
  18344. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18345. /* Bind rng */
  18346. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18347. #endif
  18348. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18349. &key), 0);
  18350. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18351. /* Pass bad args - tested in another testing function.*/
  18352. WC_FREE_VAR(in, NULL);
  18353. WC_FREE_VAR(plain, NULL);
  18354. WC_FREE_VAR(cipher, NULL);
  18355. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18356. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18357. #endif
  18358. return EXPECT_RESULT();
  18359. } /* END test_wc_RsaPublicEncryptDecrypt */
  18360. /*
  18361. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18362. */
  18363. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18364. {
  18365. EXPECT_DECLS;
  18366. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18367. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18368. RsaKey key;
  18369. WC_RNG rng;
  18370. const char inStr[] = TEST_STRING;
  18371. const word32 inLen = (word32)TEST_STRING_SZ;
  18372. const word32 plainSz = (word32)TEST_STRING_SZ;
  18373. byte* res = NULL;
  18374. int idx = 0;
  18375. int bits = TEST_RSA_BITS;
  18376. const word32 cipherSz = TEST_RSA_BYTES;
  18377. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18378. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18379. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18380. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18381. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18382. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18383. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18384. ExpectNotNull(in);
  18385. ExpectNotNull(plain);
  18386. ExpectNotNull(cipher);
  18387. #endif
  18388. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18389. /* Initialize stack structures. */
  18390. XMEMSET(&key, 0, sizeof(RsaKey));
  18391. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18392. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18393. ExpectIntEQ(wc_InitRng(&rng), 0);
  18394. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18395. /* Encrypt */
  18396. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18397. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18398. /* Pass bad args - tested in another testing function.*/
  18399. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18400. /* Decrypt */
  18401. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18402. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18403. #endif
  18404. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18405. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18406. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18407. /* Pass bad args - tested in another testing function.*/
  18408. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18409. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18410. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18411. #endif
  18412. WC_FREE_VAR(in, NULL);
  18413. WC_FREE_VAR(plain, NULL);
  18414. WC_FREE_VAR(cipher, NULL);
  18415. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18416. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18417. #endif
  18418. return EXPECT_RESULT();
  18419. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18420. /*
  18421. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18422. */
  18423. static int test_wc_RsaSSL_SignVerify(void)
  18424. {
  18425. EXPECT_DECLS;
  18426. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18427. RsaKey key;
  18428. WC_RNG rng;
  18429. const char inStr[] = TEST_STRING;
  18430. const word32 plainSz = (word32)TEST_STRING_SZ;
  18431. const word32 inLen = (word32)TEST_STRING_SZ;
  18432. word32 idx = 0;
  18433. int bits = TEST_RSA_BITS;
  18434. const word32 outSz = TEST_RSA_BYTES;
  18435. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18436. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18437. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18438. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18439. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18440. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18441. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18442. ExpectNotNull(in);
  18443. ExpectNotNull(out);
  18444. ExpectNotNull(plain);
  18445. #endif
  18446. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18447. XMEMSET(&key, 0, sizeof(RsaKey));
  18448. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18449. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18450. ExpectIntEQ(wc_InitRng(&rng), 0);
  18451. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18452. /* Sign. */
  18453. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18454. idx = (int)outSz;
  18455. /* Test bad args. */
  18456. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18458. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18460. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18462. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18464. /* Verify. */
  18465. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18466. /* Pass bad args. */
  18467. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18469. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18470. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18471. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18472. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18473. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18474. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18475. WC_FREE_VAR(in, NULL);
  18476. WC_FREE_VAR(out, NULL);
  18477. WC_FREE_VAR(plain, NULL);
  18478. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18479. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18480. #endif
  18481. return EXPECT_RESULT();
  18482. } /* END test_wc_RsaSSL_SignVerify */
  18483. /*
  18484. * Testing wc_RsaEncryptSize()
  18485. */
  18486. static int test_wc_RsaEncryptSize(void)
  18487. {
  18488. EXPECT_DECLS;
  18489. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18490. RsaKey key;
  18491. WC_RNG rng;
  18492. XMEMSET(&key, 0, sizeof(RsaKey));
  18493. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18494. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18495. ExpectIntEQ(wc_InitRng(&rng), 0);
  18496. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18497. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18498. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18499. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18500. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18501. #endif
  18502. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18503. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18504. /* Pass in bad arg. */
  18505. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18506. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18507. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18508. #endif
  18509. return EXPECT_RESULT();
  18510. } /* END test_wc_RsaEncryptSize*/
  18511. /*
  18512. * Testing wc_RsaFlattenPublicKey()
  18513. */
  18514. static int test_wc_RsaFlattenPublicKey(void)
  18515. {
  18516. EXPECT_DECLS;
  18517. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18518. RsaKey key;
  18519. WC_RNG rng;
  18520. byte e[256];
  18521. byte n[256];
  18522. word32 eSz = sizeof(e);
  18523. word32 nSz = sizeof(n);
  18524. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18525. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4))
  18526. int bits = 1024;
  18527. #else
  18528. int bits = 2048;
  18529. #endif
  18530. XMEMSET(&key, 0, sizeof(RsaKey));
  18531. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18532. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18533. ExpectIntEQ(wc_InitRng(&rng), 0);
  18534. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18535. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18536. /* Pass bad args. */
  18537. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18538. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18539. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18540. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18541. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18542. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18543. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18544. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18545. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18546. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18547. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18548. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18549. #endif
  18550. return EXPECT_RESULT();
  18551. } /* END test_wc_RsaFlattenPublicKey */
  18552. /*
  18553. * unit test for wc_AesCcmSetKey
  18554. */
  18555. static int test_wc_AesCcmSetKey(void)
  18556. {
  18557. EXPECT_DECLS;
  18558. #ifdef HAVE_AESCCM
  18559. Aes aes;
  18560. const byte key16[] = {
  18561. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18562. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18563. };
  18564. const byte key24[] = {
  18565. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18566. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18567. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18568. };
  18569. const byte key32[] = {
  18570. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18571. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18572. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18573. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18574. };
  18575. XMEMSET(&aes, 0, sizeof(Aes));
  18576. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18577. #ifdef WOLFSSL_AES_128
  18578. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18579. #endif
  18580. #ifdef WOLFSSL_AES_192
  18581. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18582. #endif
  18583. #ifdef WOLFSSL_AES_256
  18584. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18585. #endif
  18586. /* Test bad args. */
  18587. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18588. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18589. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18590. wc_AesFree(&aes);
  18591. #endif
  18592. return EXPECT_RESULT();
  18593. } /* END test_wc_AesCcmSetKey */
  18594. /*
  18595. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18596. */
  18597. static int test_wc_AesCcmEncryptDecrypt(void)
  18598. {
  18599. EXPECT_DECLS;
  18600. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18601. Aes aes;
  18602. const byte key16[] = {
  18603. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18604. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18605. };
  18606. /* plaintext */
  18607. const byte plainT[] = {
  18608. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18609. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18610. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18611. };
  18612. /* nonce */
  18613. const byte iv[] = {
  18614. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18615. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18616. };
  18617. const byte c[] = { /* cipher text. */
  18618. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18619. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18620. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18621. };
  18622. const byte t[] = { /* Auth tag */
  18623. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18624. };
  18625. const byte authIn[] = {
  18626. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18627. };
  18628. byte cipherOut[sizeof(plainT)];
  18629. byte authTag[sizeof(t)];
  18630. #ifdef HAVE_AES_DECRYPT
  18631. byte plainOut[sizeof(cipherOut)];
  18632. #endif
  18633. XMEMSET(&aes, 0, sizeof(Aes));
  18634. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18635. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18636. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18637. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  18638. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  18639. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  18640. #ifdef HAVE_AES_DECRYPT
  18641. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18642. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  18643. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  18644. #endif
  18645. /* Pass in bad args. Encrypt*/
  18646. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  18647. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18648. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18649. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  18650. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18651. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18652. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  18653. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18654. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18655. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18656. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18657. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18658. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18659. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  18660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18661. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18662. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18663. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18664. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18665. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18667. #ifdef HAVE_AES_DECRYPT
  18668. /* Pass in bad args. Decrypt*/
  18669. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  18670. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18671. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18672. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  18673. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18674. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18675. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  18676. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18677. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18678. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18679. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18680. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18681. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18682. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  18683. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18684. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18685. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18687. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18688. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18689. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18690. #endif
  18691. wc_AesFree(&aes);
  18692. #endif /* HAVE_AESCCM */
  18693. return EXPECT_RESULT();
  18694. } /* END test_wc_AesCcmEncryptDecrypt */
  18695. #if defined(WOLFSSL_AES_EAX) && \
  18696. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  18697. /*
  18698. * Testing test_wc_AesEaxVectors()
  18699. */
  18700. static int test_wc_AesEaxVectors(void)
  18701. {
  18702. EXPECT_DECLS;
  18703. typedef struct {
  18704. byte key[AES_256_KEY_SIZE];
  18705. int key_length;
  18706. byte iv[AES_BLOCK_SIZE];
  18707. int iv_length;
  18708. byte aad[AES_BLOCK_SIZE * 2];
  18709. int aad_length;
  18710. byte msg[AES_BLOCK_SIZE * 5];
  18711. int msg_length;
  18712. byte ct[AES_BLOCK_SIZE * 5];
  18713. int ct_length;
  18714. byte tag[AES_BLOCK_SIZE];
  18715. int tag_length;
  18716. int valid;
  18717. } AadVector;
  18718. /* Test vectors obtained from Google wycheproof project
  18719. * https://github.com/google/wycheproof
  18720. * from testvectors/aes_eax_test.json
  18721. */
  18722. const AadVector vectors[] = {
  18723. {
  18724. /* key, key length */
  18725. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  18726. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  18727. /* iv, iv length */
  18728. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  18729. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  18730. /* aad, aad length */
  18731. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  18732. /* msg, msg length */
  18733. {0x00}, 0,
  18734. /* ct, ct length */
  18735. {0x00}, 0,
  18736. /* tag, tag length */
  18737. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  18738. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  18739. /* valid */
  18740. 1,
  18741. },
  18742. {
  18743. /* key, key length */
  18744. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  18745. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  18746. /* iv, iv length */
  18747. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  18748. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  18749. /* aad, aad length */
  18750. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  18751. /* msg, msg length */
  18752. {0xf7, 0xfb}, 2,
  18753. /* ct, ct length */
  18754. {0x19, 0xdd}, 2,
  18755. /* tag, tag length */
  18756. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  18757. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  18758. /* valid */
  18759. 1,
  18760. },
  18761. {
  18762. /* key, key length */
  18763. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  18764. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  18765. /* iv, iv length */
  18766. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  18767. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  18768. /* aad, aad length */
  18769. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  18770. /* msg, msg length */
  18771. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  18772. /* ct, ct length */
  18773. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  18774. /* tag, tag length */
  18775. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  18776. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  18777. /* valid */
  18778. 1,
  18779. },
  18780. {
  18781. /* key, key length */
  18782. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  18783. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  18784. /* iv, iv length */
  18785. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  18786. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  18787. /* aad, aad length */
  18788. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  18789. /* msg, msg length */
  18790. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  18791. /* ct, ct length */
  18792. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  18793. /* tag, tag length */
  18794. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  18795. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  18796. /* valid */
  18797. 1,
  18798. },
  18799. {
  18800. /* key, key length */
  18801. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  18802. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  18803. /* iv, iv length */
  18804. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  18805. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  18806. /* aad, aad length */
  18807. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  18808. /* msg, msg length */
  18809. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  18810. /* ct, ct length */
  18811. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  18812. /* tag, tag length */
  18813. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  18814. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  18815. /* valid */
  18816. 1,
  18817. },
  18818. {
  18819. /* key, key length */
  18820. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  18821. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  18822. /* iv, iv length */
  18823. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  18824. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  18825. /* aad, aad length */
  18826. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  18827. /* msg, msg length */
  18828. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  18829. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  18830. /* ct, ct length */
  18831. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  18832. 0x0e, 0x72, 0x84, 0x14}, 12,
  18833. /* tag, tag length */
  18834. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  18835. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  18836. /* valid */
  18837. 1,
  18838. },
  18839. {
  18840. /* key, key length */
  18841. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  18842. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  18843. /* iv, iv length */
  18844. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  18845. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  18846. /* aad, aad length */
  18847. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  18848. /* msg, msg length */
  18849. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  18850. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  18851. 0x36}, 17,
  18852. /* ct, ct length */
  18853. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  18854. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  18855. 0x30}, 17,
  18856. /* tag, tag length */
  18857. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  18858. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  18859. /* valid */
  18860. 1,
  18861. },
  18862. {
  18863. /* key, key length */
  18864. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  18865. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  18866. /* iv, iv length */
  18867. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  18868. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  18869. /* aad, aad length */
  18870. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  18871. /* msg, msg length */
  18872. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  18873. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  18874. 0x2d, 0x56}, 18,
  18875. /* ct, ct length */
  18876. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  18877. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  18878. 0x8c, 0xc3}, 18,
  18879. /* tag, tag length */
  18880. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  18881. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  18882. /* valid */
  18883. 1,
  18884. },
  18885. {
  18886. /* key, key length */
  18887. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  18888. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  18889. /* iv, iv length */
  18890. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  18891. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  18892. /* aad, aad length */
  18893. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  18894. /* msg, msg length */
  18895. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  18896. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  18897. 0xef, 0x11}, 18,
  18898. /* ct, ct length */
  18899. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  18900. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  18901. 0xb1, 0xe8}, 18,
  18902. /* tag, tag length */
  18903. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  18904. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  18905. /* valid */
  18906. 1,
  18907. },
  18908. {
  18909. /* key, key length */
  18910. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  18911. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  18912. /* iv, iv length */
  18913. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  18914. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  18915. /* aad, aad length */
  18916. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  18917. /* msg, msg length */
  18918. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  18919. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  18920. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  18921. /* ct, ct length */
  18922. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  18923. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  18924. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  18925. /* tag, tag length */
  18926. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  18927. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  18928. /* valid */
  18929. 1,
  18930. },
  18931. {
  18932. /* key, key length */
  18933. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18934. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18935. /* iv, iv length */
  18936. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  18937. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  18938. /* aad, aad length */
  18939. {0x00}, 0,
  18940. /* msg, msg length */
  18941. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18942. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18943. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18944. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18945. /* ct, ct length */
  18946. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  18947. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  18948. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  18949. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  18950. /* tag, tag length */
  18951. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  18952. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  18953. /* valid */
  18954. 1,
  18955. },
  18956. {
  18957. /* key, key length */
  18958. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18959. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18960. /* iv, iv length */
  18961. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  18962. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  18963. /* aad, aad length */
  18964. {0x00}, 0,
  18965. /* msg, msg length */
  18966. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18967. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18968. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18969. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18970. /* ct, ct length */
  18971. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  18972. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  18973. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  18974. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  18975. /* tag, tag length */
  18976. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  18977. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  18978. /* valid */
  18979. 1,
  18980. },
  18981. {
  18982. /* key, key length */
  18983. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  18984. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  18985. /* iv, iv length */
  18986. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  18987. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  18988. /* aad, aad length */
  18989. {0x00}, 0,
  18990. /* msg, msg length */
  18991. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18992. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18993. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  18994. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  18995. /* ct, ct length */
  18996. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  18997. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  18998. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  18999. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  19000. /* tag, tag length */
  19001. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  19002. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  19003. /* valid */
  19004. 1,
  19005. },
  19006. {
  19007. /* key, key length */
  19008. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19009. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19010. /* iv, iv length */
  19011. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  19012. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  19013. /* aad, aad length */
  19014. {0x00}, 0,
  19015. /* msg, msg length */
  19016. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19017. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19018. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19019. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19020. /* ct, ct length */
  19021. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  19022. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  19023. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  19024. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  19025. /* tag, tag length */
  19026. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  19027. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  19028. /* valid */
  19029. 1,
  19030. },
  19031. {
  19032. /* key, key length */
  19033. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19034. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19035. /* iv, iv length */
  19036. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  19037. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  19038. /* aad, aad length */
  19039. {0x00}, 0,
  19040. /* msg, msg length */
  19041. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19042. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19043. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19044. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19045. /* ct, ct length */
  19046. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  19047. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  19048. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  19049. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  19050. /* tag, tag length */
  19051. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  19052. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  19053. /* valid */
  19054. 1,
  19055. },
  19056. {
  19057. /* key, key length */
  19058. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19059. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19060. /* iv, iv length */
  19061. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  19062. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  19063. /* aad, aad length */
  19064. {0x00}, 0,
  19065. /* msg, msg length */
  19066. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19067. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19068. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19069. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19070. /* ct, ct length */
  19071. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  19072. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  19073. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  19074. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  19075. /* tag, tag length */
  19076. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  19077. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  19078. /* valid */
  19079. 1,
  19080. },
  19081. {
  19082. /* key, key length */
  19083. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19084. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19085. /* iv, iv length */
  19086. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  19087. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  19088. /* aad, aad length */
  19089. {0x00}, 0,
  19090. /* msg, msg length */
  19091. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19092. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19093. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19094. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19095. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19096. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19097. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19098. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  19099. /* ct, ct length */
  19100. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  19101. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  19102. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  19103. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  19104. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  19105. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  19106. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  19107. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  19108. /* tag, tag length */
  19109. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  19110. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  19111. /* valid */
  19112. 1,
  19113. },
  19114. {
  19115. /* key, key length */
  19116. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19117. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19118. /* iv, iv length */
  19119. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  19120. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  19121. /* aad, aad length */
  19122. {0x00}, 0,
  19123. /* msg, msg length */
  19124. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19126. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19127. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19128. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19129. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19130. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19131. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19132. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  19133. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  19134. /* ct, ct length */
  19135. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  19136. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  19137. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  19138. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  19139. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  19140. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  19141. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  19142. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  19143. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  19144. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  19145. /* tag, tag length */
  19146. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  19147. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  19148. /* valid */
  19149. 1,
  19150. },
  19151. {
  19152. /* key, key length */
  19153. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  19154. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  19155. /* iv, iv length */
  19156. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  19157. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  19158. /* aad, aad length */
  19159. {0x00}, 0,
  19160. /* msg, msg length */
  19161. {0x00}, 0,
  19162. /* ct, ct length */
  19163. {0x00}, 0,
  19164. /* tag, tag length */
  19165. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  19166. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  19167. /* valid */
  19168. 1,
  19169. },
  19170. {
  19171. /* key, key length */
  19172. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  19173. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  19174. /* iv, iv length */
  19175. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  19176. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  19177. /* aad, aad length */
  19178. {0x00}, 0,
  19179. /* msg, msg length */
  19180. {0x01}, 1,
  19181. /* ct, ct length */
  19182. {0x1d}, 1,
  19183. /* tag, tag length */
  19184. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  19185. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  19186. /* valid */
  19187. 1,
  19188. },
  19189. {
  19190. /* key, key length */
  19191. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  19192. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  19193. /* iv, iv length */
  19194. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  19195. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  19196. /* aad, aad length */
  19197. {0x00}, 0,
  19198. /* msg, msg length */
  19199. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  19200. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  19201. /* ct, ct length */
  19202. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  19203. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  19204. /* tag, tag length */
  19205. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  19206. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  19207. /* valid */
  19208. 1,
  19209. },
  19210. {
  19211. /* key, key length */
  19212. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  19213. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  19214. /* iv, iv length */
  19215. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  19216. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  19217. /* aad, aad length */
  19218. {0x00}, 0,
  19219. /* msg, msg length */
  19220. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19221. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19222. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19223. /* ct, ct length */
  19224. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19225. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19226. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19227. /* tag, tag length */
  19228. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19229. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19230. /* valid */
  19231. 1,
  19232. },
  19233. {
  19234. /* key, key length */
  19235. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19236. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19237. /* iv, iv length */
  19238. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19239. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19240. /* aad, aad length */
  19241. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19242. /* msg, msg length */
  19243. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19244. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19245. /* ct, ct length */
  19246. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19247. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19248. /* tag, tag length */
  19249. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19250. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19251. /* valid */
  19252. 1,
  19253. },
  19254. {
  19255. /* key, key length */
  19256. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19257. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19258. /* iv, iv length */
  19259. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19260. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19261. /* aad, aad length */
  19262. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19263. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19264. /* msg, msg length */
  19265. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19266. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19267. /* ct, ct length */
  19268. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19269. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19270. /* tag, tag length */
  19271. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19272. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19273. /* valid */
  19274. 1,
  19275. },
  19276. {
  19277. /* key, key length */
  19278. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19279. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19280. /* iv, iv length */
  19281. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19282. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19283. /* aad, aad length */
  19284. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19285. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19286. /* msg, msg length */
  19287. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19288. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19289. /* ct, ct length */
  19290. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19291. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19292. /* tag, tag length */
  19293. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19294. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19295. /* valid */
  19296. 1,
  19297. },
  19298. {
  19299. /* key, key length */
  19300. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19301. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19302. /* iv, iv length */
  19303. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19304. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19305. /* aad, aad length */
  19306. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19307. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19308. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19309. /* msg, msg length */
  19310. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19311. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19312. /* ct, ct length */
  19313. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19314. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19315. /* tag, tag length */
  19316. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19317. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19318. /* valid */
  19319. 1,
  19320. },
  19321. {
  19322. /* key, key length */
  19323. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19324. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19325. /* iv, iv length */
  19326. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19327. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19328. /* aad, aad length */
  19329. {0x00}, 0,
  19330. /* msg, msg length */
  19331. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19332. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19333. /* ct, ct length */
  19334. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19335. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19336. /* tag, tag length */
  19337. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19338. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19339. /* valid */
  19340. 0,
  19341. },
  19342. {
  19343. /* key, key length */
  19344. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19345. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19346. /* iv, iv length */
  19347. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19348. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19349. /* aad, aad length */
  19350. {0x00}, 0,
  19351. /* msg, msg length */
  19352. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19353. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19354. /* ct, ct length */
  19355. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19356. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19357. /* tag, tag length */
  19358. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19359. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19360. /* valid */
  19361. 0,
  19362. },
  19363. {
  19364. /* key, key length */
  19365. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19366. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19367. /* iv, iv length */
  19368. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19369. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19370. /* aad, aad length */
  19371. {0x00}, 0,
  19372. /* msg, msg length */
  19373. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19374. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19375. /* ct, ct length */
  19376. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19377. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19378. /* tag, tag length */
  19379. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19380. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19381. /* valid */
  19382. 0,
  19383. },
  19384. {
  19385. /* key, key length */
  19386. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19387. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19388. /* iv, iv length */
  19389. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19390. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19391. /* aad, aad length */
  19392. {0x00}, 0,
  19393. /* msg, msg length */
  19394. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19395. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19396. /* ct, ct length */
  19397. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19398. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19399. /* tag, tag length */
  19400. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19401. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19402. /* valid */
  19403. 0,
  19404. },
  19405. {
  19406. /* key, key length */
  19407. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19408. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19409. /* iv, iv length */
  19410. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19411. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19412. /* aad, aad length */
  19413. {0x00}, 0,
  19414. /* msg, msg length */
  19415. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19416. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19417. /* ct, ct length */
  19418. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19419. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19420. /* tag, tag length */
  19421. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19422. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19423. /* valid */
  19424. 0,
  19425. },
  19426. {
  19427. /* key, key length */
  19428. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19429. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19430. /* iv, iv length */
  19431. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19432. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19433. /* aad, aad length */
  19434. {0x00}, 0,
  19435. /* msg, msg length */
  19436. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19437. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19438. /* ct, ct length */
  19439. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19440. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19441. /* tag, tag length */
  19442. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19443. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19444. /* valid */
  19445. 0,
  19446. },
  19447. {
  19448. /* key, key length */
  19449. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19450. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19451. /* iv, iv length */
  19452. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19453. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19454. /* aad, aad length */
  19455. {0x00}, 0,
  19456. /* msg, msg length */
  19457. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19458. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19459. /* ct, ct length */
  19460. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19461. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19462. /* tag, tag length */
  19463. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19464. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19465. /* valid */
  19466. 0,
  19467. },
  19468. {
  19469. /* key, key length */
  19470. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19471. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19472. /* iv, iv length */
  19473. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19474. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19475. /* aad, aad length */
  19476. {0x00}, 0,
  19477. /* msg, msg length */
  19478. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19479. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19480. /* ct, ct length */
  19481. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19482. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19483. /* tag, tag length */
  19484. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19485. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19486. /* valid */
  19487. 0,
  19488. },
  19489. {
  19490. /* key, key length */
  19491. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19492. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19493. /* iv, iv length */
  19494. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19495. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19496. /* aad, aad length */
  19497. {0x00}, 0,
  19498. /* msg, msg length */
  19499. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19500. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19501. /* ct, ct length */
  19502. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19503. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19504. /* tag, tag length */
  19505. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19506. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19507. /* valid */
  19508. 0,
  19509. },
  19510. {
  19511. /* key, key length */
  19512. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19513. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19514. /* iv, iv length */
  19515. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19516. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19517. /* aad, aad length */
  19518. {0x00}, 0,
  19519. /* msg, msg length */
  19520. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19521. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19522. /* ct, ct length */
  19523. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19524. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19525. /* tag, tag length */
  19526. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19527. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19528. /* valid */
  19529. 0,
  19530. },
  19531. {
  19532. /* key, key length */
  19533. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19534. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19535. /* iv, iv length */
  19536. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19537. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19538. /* aad, aad length */
  19539. {0x00}, 0,
  19540. /* msg, msg length */
  19541. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19542. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19543. /* ct, ct length */
  19544. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19545. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19546. /* tag, tag length */
  19547. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19548. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19549. /* valid */
  19550. 0,
  19551. },
  19552. {
  19553. /* key, key length */
  19554. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19555. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19556. /* iv, iv length */
  19557. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19558. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19559. /* aad, aad length */
  19560. {0x00}, 0,
  19561. /* msg, msg length */
  19562. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19563. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19564. /* ct, ct length */
  19565. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19566. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19567. /* tag, tag length */
  19568. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19569. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19570. /* valid */
  19571. 0,
  19572. },
  19573. {
  19574. /* key, key length */
  19575. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19576. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19577. /* iv, iv length */
  19578. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19579. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19580. /* aad, aad length */
  19581. {0x00}, 0,
  19582. /* msg, msg length */
  19583. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19584. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19585. /* ct, ct length */
  19586. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19587. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19588. /* tag, tag length */
  19589. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19590. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19591. /* valid */
  19592. 0,
  19593. },
  19594. {
  19595. /* key, key length */
  19596. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19597. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19598. /* iv, iv length */
  19599. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19600. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19601. /* aad, aad length */
  19602. {0x00}, 0,
  19603. /* msg, msg length */
  19604. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19605. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19606. /* ct, ct length */
  19607. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19608. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19609. /* tag, tag length */
  19610. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19611. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19612. /* valid */
  19613. 0,
  19614. },
  19615. {
  19616. /* key, key length */
  19617. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19618. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19619. /* iv, iv length */
  19620. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19621. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19622. /* aad, aad length */
  19623. {0x00}, 0,
  19624. /* msg, msg length */
  19625. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19626. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19627. /* ct, ct length */
  19628. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19629. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19630. /* tag, tag length */
  19631. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19632. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19633. /* valid */
  19634. 0,
  19635. },
  19636. {
  19637. /* key, key length */
  19638. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19639. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19640. /* iv, iv length */
  19641. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19642. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19643. /* aad, aad length */
  19644. {0x00}, 0,
  19645. /* msg, msg length */
  19646. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19647. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19648. /* ct, ct length */
  19649. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19650. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19651. /* tag, tag length */
  19652. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19653. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  19654. /* valid */
  19655. 0,
  19656. },
  19657. {
  19658. /* key, key length */
  19659. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19660. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19661. /* iv, iv length */
  19662. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19663. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19664. /* aad, aad length */
  19665. {0x00}, 0,
  19666. /* msg, msg length */
  19667. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19668. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19669. /* ct, ct length */
  19670. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19671. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19672. /* tag, tag length */
  19673. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19674. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  19675. /* valid */
  19676. 0,
  19677. },
  19678. {
  19679. /* key, key length */
  19680. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19681. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19682. /* iv, iv length */
  19683. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19684. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19685. /* aad, aad length */
  19686. {0x00}, 0,
  19687. /* msg, msg length */
  19688. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19689. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19690. /* ct, ct length */
  19691. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19692. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19693. /* tag, tag length */
  19694. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19695. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  19696. /* valid */
  19697. 0,
  19698. },
  19699. {
  19700. /* key, key length */
  19701. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19702. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19703. /* iv, iv length */
  19704. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19705. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19706. /* aad, aad length */
  19707. {0x00}, 0,
  19708. /* msg, msg length */
  19709. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19710. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19711. /* ct, ct length */
  19712. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19713. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19714. /* tag, tag length */
  19715. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19716. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19717. /* valid */
  19718. 0,
  19719. },
  19720. {
  19721. /* key, key length */
  19722. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19723. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19724. /* iv, iv length */
  19725. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19726. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19727. /* aad, aad length */
  19728. {0x00}, 0,
  19729. /* msg, msg length */
  19730. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19731. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19732. /* ct, ct length */
  19733. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19734. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19735. /* tag, tag length */
  19736. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19737. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19738. /* valid */
  19739. 0,
  19740. },
  19741. {
  19742. /* key, key length */
  19743. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19744. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19745. /* iv, iv length */
  19746. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19747. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19748. /* aad, aad length */
  19749. {0x00}, 0,
  19750. /* msg, msg length */
  19751. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19752. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19753. /* ct, ct length */
  19754. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19755. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19756. /* tag, tag length */
  19757. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  19758. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19759. /* valid */
  19760. 0,
  19761. },
  19762. {
  19763. /* key, key length */
  19764. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19765. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19766. /* iv, iv length */
  19767. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19768. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19769. /* aad, aad length */
  19770. {0x00}, 0,
  19771. /* msg, msg length */
  19772. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19773. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19774. /* ct, ct length */
  19775. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19776. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19777. /* tag, tag length */
  19778. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19779. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19780. /* valid */
  19781. 0,
  19782. },
  19783. {
  19784. /* key, key length */
  19785. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19786. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19787. /* iv, iv length */
  19788. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19789. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19790. /* aad, aad length */
  19791. {0x00}, 0,
  19792. /* msg, msg length */
  19793. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19794. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19795. /* ct, ct length */
  19796. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19797. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19798. /* tag, tag length */
  19799. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  19800. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  19801. /* valid */
  19802. 0,
  19803. },
  19804. {
  19805. /* key, key length */
  19806. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19807. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19808. /* iv, iv length */
  19809. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19810. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19811. /* aad, aad length */
  19812. {0x00}, 0,
  19813. /* msg, msg length */
  19814. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19815. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19816. /* ct, ct length */
  19817. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19818. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19819. /* tag, tag length */
  19820. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19821. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  19822. /* valid */
  19823. 0,
  19824. },
  19825. {
  19826. /* key, key length */
  19827. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19828. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19829. /* iv, iv length */
  19830. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19831. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19832. /* aad, aad length */
  19833. {0x00}, 0,
  19834. /* msg, msg length */
  19835. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19836. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19837. /* ct, ct length */
  19838. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19839. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19840. /* tag, tag length */
  19841. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  19842. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  19843. /* valid */
  19844. 0,
  19845. },
  19846. {
  19847. /* key, key length */
  19848. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19849. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19850. /* iv, iv length */
  19851. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19852. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19853. /* aad, aad length */
  19854. {0x00}, 0,
  19855. /* msg, msg length */
  19856. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19857. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19858. /* ct, ct length */
  19859. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19860. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19861. /* tag, tag length */
  19862. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  19863. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  19864. /* valid */
  19865. 0,
  19866. },
  19867. {
  19868. /* key, key length */
  19869. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19870. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19871. /* iv, iv length */
  19872. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19873. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19874. /* aad, aad length */
  19875. {0x00}, 0,
  19876. /* msg, msg length */
  19877. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19878. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19879. /* ct, ct length */
  19880. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19881. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19882. /* tag, tag length */
  19883. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  19884. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  19885. /* valid */
  19886. 0,
  19887. },
  19888. };
  19889. byte ciphertext[sizeof(vectors[0].ct)];
  19890. byte authtag[sizeof(vectors[0].tag)];
  19891. int i;
  19892. int len;
  19893. int ret;
  19894. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  19895. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  19896. len = sizeof(authtag);
  19897. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  19898. ciphertext,
  19899. vectors[i].msg, vectors[i].msg_length,
  19900. vectors[i].iv, vectors[i].iv_length,
  19901. authtag, len,
  19902. vectors[i].aad, vectors[i].aad_length),
  19903. 0);
  19904. /* check ciphertext matches vector */
  19905. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  19906. 0);
  19907. /* check that computed tag matches vector only for vectors marked as valid */
  19908. ret = XMEMCMP(authtag, vectors[i].tag, len);
  19909. if (vectors[i].valid) {
  19910. ExpectIntEQ(ret, 0);
  19911. }
  19912. else {
  19913. ExpectIntNE(ret, 0);
  19914. }
  19915. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  19916. /* Decrypt, checking that the computed auth tags match */
  19917. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  19918. ciphertext,
  19919. vectors[i].ct, vectors[i].ct_length,
  19920. vectors[i].iv, vectors[i].iv_length,
  19921. authtag, len,
  19922. vectors[i].aad, vectors[i].aad_length),
  19923. 0);
  19924. /* check decrypted ciphertext matches vector plaintext */
  19925. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  19926. 0);
  19927. }
  19928. return EXPECT_RESULT();
  19929. } /* END test_wc_AesEaxVectors */
  19930. /*
  19931. * Testing test_wc_AesEaxEncryptAuth()
  19932. */
  19933. static int test_wc_AesEaxEncryptAuth(void)
  19934. {
  19935. EXPECT_DECLS;
  19936. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19937. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19938. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19939. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19940. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19941. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  19942. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  19943. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  19944. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  19945. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  19946. byte ciphertext[sizeof(msg)];
  19947. byte authtag[AES_BLOCK_SIZE];
  19948. int i;
  19949. int len;
  19950. len = sizeof(authtag);
  19951. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19952. ciphertext,
  19953. msg, sizeof(msg),
  19954. iv, sizeof(iv),
  19955. authtag, (word32)len,
  19956. aad, sizeof(aad)),
  19957. 0);
  19958. /* Test null checking */
  19959. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  19960. ciphertext,
  19961. msg, sizeof(msg),
  19962. iv, sizeof(iv),
  19963. authtag, (word32)len,
  19964. aad, sizeof(aad)),
  19965. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19966. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19967. NULL,
  19968. msg, sizeof(msg),
  19969. iv, sizeof(iv),
  19970. authtag, (word32)len,
  19971. aad, sizeof(aad)),
  19972. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19973. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19974. ciphertext,
  19975. NULL, sizeof(msg),
  19976. iv, sizeof(iv),
  19977. authtag, (word32)len,
  19978. aad, sizeof(aad)),
  19979. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19980. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19981. ciphertext,
  19982. msg, sizeof(msg),
  19983. NULL, sizeof(iv),
  19984. authtag, (word32)len,
  19985. aad, sizeof(aad)),
  19986. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19987. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19988. ciphertext,
  19989. msg, sizeof(msg),
  19990. iv, sizeof(iv),
  19991. NULL, (word32)len,
  19992. aad, sizeof(aad)),
  19993. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19994. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  19995. ciphertext,
  19996. msg, sizeof(msg),
  19997. iv, sizeof(iv),
  19998. authtag, (word32)len,
  19999. NULL, sizeof(aad)),
  20000. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20001. /* Test bad key lengths */
  20002. for (i = 0; i <= 32; i++) {
  20003. int exp_ret;
  20004. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20005. || i == AES_256_KEY_SIZE) {
  20006. exp_ret = 0;
  20007. }
  20008. else {
  20009. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20010. }
  20011. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  20012. ciphertext,
  20013. msg, sizeof(msg),
  20014. iv, sizeof(iv),
  20015. authtag, (word32)len,
  20016. aad, sizeof(aad)),
  20017. exp_ret);
  20018. }
  20019. /* Test auth tag size out of range */
  20020. len = AES_BLOCK_SIZE + 1;
  20021. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20022. ciphertext,
  20023. msg, sizeof(msg),
  20024. iv, sizeof(iv),
  20025. authtag, (word32)len,
  20026. aad, sizeof(aad)),
  20027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20028. return EXPECT_RESULT();
  20029. } /* END test_wc_AesEaxEncryptAuth() */
  20030. /*
  20031. * Testing test_wc_AesEaxDecryptAuth()
  20032. */
  20033. static int test_wc_AesEaxDecryptAuth(void)
  20034. {
  20035. EXPECT_DECLS;
  20036. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20037. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20038. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20039. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20040. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20041. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20042. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20043. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20044. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20045. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20046. /* Garbage tag that should always fail for above aad */
  20047. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  20048. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  20049. byte plaintext[sizeof(ct)];
  20050. int i;
  20051. int len;
  20052. len = sizeof(tag);
  20053. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20054. plaintext,
  20055. ct, sizeof(ct),
  20056. iv, sizeof(iv),
  20057. tag, (word32)len,
  20058. aad, sizeof(aad)),
  20059. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  20060. /* Test null checking */
  20061. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  20062. plaintext,
  20063. ct, sizeof(ct),
  20064. iv, sizeof(iv),
  20065. tag, (word32)len,
  20066. aad, sizeof(aad)),
  20067. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20068. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20069. NULL,
  20070. ct, sizeof(ct),
  20071. iv, sizeof(iv),
  20072. tag, (word32)len,
  20073. aad, sizeof(aad)),
  20074. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20075. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20076. plaintext,
  20077. NULL, sizeof(ct),
  20078. iv, sizeof(iv),
  20079. tag, (word32)len,
  20080. aad, sizeof(aad)),
  20081. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20082. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20083. plaintext,
  20084. ct, sizeof(ct),
  20085. NULL, sizeof(iv),
  20086. tag, (word32)len,
  20087. aad, sizeof(aad)),
  20088. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20089. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20090. plaintext,
  20091. ct, sizeof(ct),
  20092. iv, sizeof(iv),
  20093. NULL, (word32)len,
  20094. aad, sizeof(aad)),
  20095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20096. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20097. plaintext,
  20098. ct, sizeof(ct),
  20099. iv, sizeof(iv),
  20100. tag, (word32)len,
  20101. NULL, sizeof(aad)),
  20102. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20103. /* Test bad key lengths */
  20104. for (i = 0; i <= 32; i++) {
  20105. int exp_ret;
  20106. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20107. || i == AES_256_KEY_SIZE) {
  20108. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  20109. }
  20110. else {
  20111. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20112. }
  20113. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  20114. plaintext,
  20115. ct, sizeof(ct),
  20116. iv, sizeof(iv),
  20117. tag, (word32)len,
  20118. aad, sizeof(aad)),
  20119. exp_ret);
  20120. }
  20121. /* Test auth tag size out of range */
  20122. len = AES_BLOCK_SIZE + 1;
  20123. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20124. plaintext,
  20125. ct, sizeof(ct),
  20126. iv, sizeof(iv),
  20127. tag, (word32)len,
  20128. aad, sizeof(aad)),
  20129. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20130. return EXPECT_RESULT();
  20131. } /* END test_wc_AesEaxDecryptAuth() */
  20132. #endif /* WOLFSSL_AES_EAX &&
  20133. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  20134. */
  20135. /*
  20136. * Testing wc_InitDsaKey()
  20137. */
  20138. static int test_wc_InitDsaKey(void)
  20139. {
  20140. EXPECT_DECLS;
  20141. #ifndef NO_DSA
  20142. DsaKey key;
  20143. XMEMSET(&key, 0, sizeof(DsaKey));
  20144. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20145. /* Pass in bad args. */
  20146. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20147. wc_FreeDsaKey(&key);
  20148. #endif
  20149. return EXPECT_RESULT();
  20150. } /* END test_wc_InitDsaKey */
  20151. /*
  20152. * Testing wc_DsaSign() and wc_DsaVerify()
  20153. */
  20154. static int test_wc_DsaSignVerify(void)
  20155. {
  20156. EXPECT_DECLS;
  20157. #if !defined(NO_DSA)
  20158. DsaKey key;
  20159. WC_RNG rng;
  20160. wc_Sha sha;
  20161. byte signature[DSA_SIG_SIZE];
  20162. byte hash[WC_SHA_DIGEST_SIZE];
  20163. word32 idx = 0;
  20164. word32 bytes;
  20165. int answer;
  20166. #ifdef USE_CERT_BUFFERS_1024
  20167. byte tmp[ONEK_BUF];
  20168. XMEMSET(tmp, 0, sizeof(tmp));
  20169. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20170. bytes = sizeof_dsa_key_der_1024;
  20171. #elif defined(USE_CERT_BUFFERS_2048)
  20172. byte tmp[TWOK_BUF];
  20173. XMEMSET(tmp, 0, sizeof(tmp));
  20174. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20175. bytes = sizeof_dsa_key_der_2048;
  20176. #else
  20177. byte tmp[TWOK_BUF];
  20178. XFILE fp = XBADFILE;
  20179. XMEMSET(tmp, 0, sizeof(tmp));
  20180. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20181. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20182. if (fp != XBADFILE)
  20183. XFCLOSE(fp);
  20184. #endif /* END USE_CERT_BUFFERS_1024 */
  20185. ExpectIntEQ(wc_InitSha(&sha), 0);
  20186. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  20187. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  20188. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20189. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20190. ExpectIntEQ(wc_InitRng(&rng), 0);
  20191. /* Sign. */
  20192. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  20193. /* Test bad args. */
  20194. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20195. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20196. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20197. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20198. /* Verify. */
  20199. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  20200. ExpectIntEQ(answer, 1);
  20201. /* Pass in bad args. */
  20202. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20203. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20204. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20205. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20206. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  20207. /* hard set q to 0 and test fail case */
  20208. mp_free(&key.q);
  20209. mp_init(&key.q);
  20210. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20211. mp_set(&key.q, 1);
  20212. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20213. #endif
  20214. DoExpectIntEQ(wc_FreeRng(&rng),0);
  20215. wc_FreeDsaKey(&key);
  20216. wc_ShaFree(&sha);
  20217. #endif
  20218. return EXPECT_RESULT();
  20219. } /* END test_wc_DsaSign */
  20220. /*
  20221. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20222. */
  20223. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20224. {
  20225. EXPECT_DECLS;
  20226. #if !defined(NO_DSA)
  20227. DsaKey key;
  20228. word32 bytes = 0;
  20229. word32 idx = 0;
  20230. int ret = 0;
  20231. #ifdef USE_CERT_BUFFERS_1024
  20232. byte tmp[ONEK_BUF];
  20233. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20234. bytes = sizeof_dsa_key_der_1024;
  20235. #elif defined(USE_CERT_BUFFERS_2048)
  20236. byte tmp[TWOK_BUF];
  20237. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20238. bytes = sizeof_dsa_key_der_2048;
  20239. #else
  20240. byte tmp[TWOK_BUF];
  20241. XFILE fp = XBADFILE;
  20242. XMEMSET(tmp, 0, sizeof(tmp));
  20243. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20244. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20245. if (fp != XBADFILE)
  20246. XFCLOSE(fp);
  20247. #endif /* END USE_CERT_BUFFERS_1024 */
  20248. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20249. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20250. /* Test bad args. */
  20251. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20252. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20253. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20254. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20255. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20256. wc_FreeDsaKey(&key);
  20257. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20258. idx = 0; /* Reset */
  20259. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20260. /* Test bad args. */
  20261. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20262. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20263. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20264. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20265. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20266. wc_FreeDsaKey(&key);
  20267. #endif /* !NO_DSA */
  20268. return EXPECT_RESULT();
  20269. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20270. /*
  20271. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20272. */
  20273. static int test_wc_MakeDsaKey(void)
  20274. {
  20275. EXPECT_DECLS;
  20276. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20277. DsaKey genKey;
  20278. WC_RNG rng;
  20279. XMEMSET(&genKey, 0, sizeof(genKey));
  20280. XMEMSET(&rng, 0, sizeof(rng));
  20281. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20282. ExpectIntEQ(wc_InitRng(&rng), 0);
  20283. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20284. /* Test bad args. */
  20285. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20286. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20287. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20288. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20289. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20290. /* Test bad args. */
  20291. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20292. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20293. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20294. wc_FreeDsaKey(&genKey);
  20295. #endif
  20296. return EXPECT_RESULT();
  20297. } /* END test_wc_MakeDsaKey */
  20298. /*
  20299. * Testing wc_DsaKeyToDer()
  20300. */
  20301. static int test_wc_DsaKeyToDer(void)
  20302. {
  20303. EXPECT_DECLS;
  20304. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20305. DsaKey key;
  20306. word32 bytes;
  20307. word32 idx = 0;
  20308. #ifdef USE_CERT_BUFFERS_1024
  20309. byte tmp[ONEK_BUF];
  20310. byte der[ONEK_BUF];
  20311. XMEMSET(tmp, 0, sizeof(tmp));
  20312. XMEMSET(der, 0, sizeof(der));
  20313. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20314. bytes = sizeof_dsa_key_der_1024;
  20315. #elif defined(USE_CERT_BUFFERS_2048)
  20316. byte tmp[TWOK_BUF];
  20317. byte der[TWOK_BUF];
  20318. XMEMSET(tmp, 0, sizeof(tmp));
  20319. XMEMSET(der, 0, sizeof(der));
  20320. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20321. bytes = sizeof_dsa_key_der_2048;
  20322. #else
  20323. byte tmp[TWOK_BUF];
  20324. byte der[TWOK_BUF];
  20325. XFILE fp = XBADFILE;
  20326. XMEMSET(tmp, 0, sizeof(tmp));
  20327. XMEMSET(der, 0, sizeof(der));
  20328. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20329. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20330. if (fp != XBADFILE)
  20331. XFCLOSE(fp);
  20332. #endif /* END USE_CERT_BUFFERS_1024 */
  20333. XMEMSET(&key, 0, sizeof(DsaKey));
  20334. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20335. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20336. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20337. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20338. /* Test bad args. */
  20339. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20340. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20341. wc_FreeDsaKey(&key);
  20342. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20343. return EXPECT_RESULT();
  20344. } /* END test_wc_DsaKeyToDer */
  20345. /*
  20346. * Testing wc_DsaKeyToPublicDer()
  20347. * (indirectly testing setDsaPublicKey())
  20348. */
  20349. static int test_wc_DsaKeyToPublicDer(void)
  20350. {
  20351. EXPECT_DECLS;
  20352. #ifndef HAVE_SELFTEST
  20353. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20354. DsaKey key;
  20355. WC_RNG rng;
  20356. byte* der = NULL;
  20357. word32 sz = 0;
  20358. word32 idx = 0;
  20359. XMEMSET(&key, 0, sizeof(DsaKey));
  20360. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20361. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20362. DYNAMIC_TYPE_TMP_BUFFER));
  20363. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20364. ExpectIntEQ(wc_InitRng(&rng), 0);
  20365. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20366. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20367. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20368. wc_FreeDsaKey(&key);
  20369. idx = 0;
  20370. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20371. /* Test without the SubjectPublicKeyInfo header */
  20372. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20373. wc_FreeDsaKey(&key);
  20374. idx = 0;
  20375. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20376. /* Test bad args. */
  20377. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20378. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20379. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20380. wc_FreeDsaKey(&key);
  20381. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20382. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20383. #endif /* !HAVE_SELFTEST */
  20384. return EXPECT_RESULT();
  20385. } /* END test_wc_DsaKeyToPublicDer */
  20386. /*
  20387. * Testing wc_DsaImportParamsRaw()
  20388. */
  20389. static int test_wc_DsaImportParamsRaw(void)
  20390. {
  20391. EXPECT_DECLS;
  20392. #if !defined(NO_DSA)
  20393. DsaKey key;
  20394. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20395. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20396. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20397. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20398. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20399. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20400. "80a0093113a8bd73";
  20401. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20402. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20403. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20404. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20405. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20406. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20407. "76341a7e7d9";
  20408. /* invalid p and q parameters */
  20409. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20410. const char* invalidQ = "96c5390a";
  20411. XMEMSET(&key, 0, sizeof(DsaKey));
  20412. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20413. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20414. /* test bad args */
  20415. /* null key struct */
  20416. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20417. /* null param pointers */
  20418. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20419. /* illegal p length */
  20420. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20421. /* illegal q length */
  20422. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20423. wc_FreeDsaKey(&key);
  20424. #endif
  20425. return EXPECT_RESULT();
  20426. } /* END test_wc_DsaImportParamsRaw */
  20427. /*
  20428. * Testing wc_DsaImportParamsRawCheck()
  20429. */
  20430. static int test_wc_DsaImportParamsRawCheck(void)
  20431. {
  20432. EXPECT_DECLS;
  20433. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20434. DsaKey key;
  20435. int trusted = 0;
  20436. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20437. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20438. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20439. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20440. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20441. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20442. "80a0093113a8bd73";
  20443. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20444. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20445. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20446. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20447. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20448. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20449. "76341a7e7d9";
  20450. /* invalid p and q parameters */
  20451. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20452. const char* invalidQ = "96c5390a";
  20453. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20454. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20455. /* test bad args */
  20456. /* null key struct */
  20457. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20458. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20459. /* null param pointers */
  20460. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20461. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20462. /* illegal p length */
  20463. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20464. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20465. /* illegal q length */
  20466. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20468. wc_FreeDsaKey(&key);
  20469. #endif
  20470. return EXPECT_RESULT();
  20471. } /* END test_wc_DsaImportParamsRawCheck */
  20472. /*
  20473. * Testing wc_DsaExportParamsRaw()
  20474. */
  20475. static int test_wc_DsaExportParamsRaw(void)
  20476. {
  20477. EXPECT_DECLS;
  20478. #if !defined(NO_DSA)
  20479. DsaKey key;
  20480. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20481. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20482. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20483. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20484. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20485. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20486. "80a0093113a8bd73";
  20487. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20488. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20489. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20490. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20491. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20492. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20493. "76341a7e7d9";
  20494. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20495. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20496. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20497. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20498. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20499. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20500. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20501. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20502. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20503. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20504. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20505. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20506. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20507. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20508. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20509. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20510. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20511. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20512. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20513. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20514. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20515. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20516. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20517. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20518. byte pOut[MAX_DSA_PARAM_SIZE];
  20519. byte qOut[MAX_DSA_PARAM_SIZE];
  20520. byte gOut[MAX_DSA_PARAM_SIZE];
  20521. word32 pOutSz;
  20522. word32 qOutSz;
  20523. word32 gOutSz;
  20524. XMEMSET(&key, 0, sizeof(DsaKey));
  20525. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20526. /* first test using imported raw parameters, for expected */
  20527. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20528. pOutSz = sizeof(pOut);
  20529. qOutSz = sizeof(qOut);
  20530. gOutSz = sizeof(gOut);
  20531. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20532. &gOutSz), 0);
  20533. /* validate exported parameters are correct */
  20534. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20535. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20536. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20537. /* test bad args */
  20538. /* null key struct */
  20539. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20540. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20541. /* null output pointers */
  20542. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20543. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20544. /* null output size pointers */
  20545. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20546. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20547. /* p output buffer size too small */
  20548. pOutSz = 1;
  20549. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20550. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20551. pOutSz = sizeof(pOut);
  20552. /* q output buffer size too small */
  20553. qOutSz = 1;
  20554. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20555. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20556. qOutSz = sizeof(qOut);
  20557. /* g output buffer size too small */
  20558. gOutSz = 1;
  20559. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20560. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20561. wc_FreeDsaKey(&key);
  20562. #endif
  20563. return EXPECT_RESULT();
  20564. } /* END test_wc_DsaExportParamsRaw */
  20565. /*
  20566. * Testing wc_DsaExportKeyRaw()
  20567. */
  20568. static int test_wc_DsaExportKeyRaw(void)
  20569. {
  20570. EXPECT_DECLS;
  20571. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20572. DsaKey key;
  20573. WC_RNG rng;
  20574. byte xOut[MAX_DSA_PARAM_SIZE];
  20575. byte yOut[MAX_DSA_PARAM_SIZE];
  20576. word32 xOutSz, yOutSz;
  20577. XMEMSET(&key, 0, sizeof(key));
  20578. XMEMSET(&rng, 0, sizeof(rng));
  20579. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20580. ExpectIntEQ(wc_InitRng(&rng), 0);
  20581. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20582. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20583. /* try successful export */
  20584. xOutSz = sizeof(xOut);
  20585. yOutSz = sizeof(yOut);
  20586. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20587. /* test bad args */
  20588. /* null key struct */
  20589. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20590. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20591. /* null output pointers */
  20592. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20593. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20594. /* null output size pointers */
  20595. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20597. /* x output buffer size too small */
  20598. xOutSz = 1;
  20599. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20600. WC_NO_ERR_TRACE(BUFFER_E));
  20601. xOutSz = sizeof(xOut);
  20602. /* y output buffer size too small */
  20603. yOutSz = 1;
  20604. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20605. WC_NO_ERR_TRACE(BUFFER_E));
  20606. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20607. wc_FreeDsaKey(&key);
  20608. #endif
  20609. return EXPECT_RESULT();
  20610. } /* END test_wc_DsaExportParamsRaw */
  20611. /*
  20612. * Testing wc_ed25519_make_key().
  20613. */
  20614. static int test_wc_ed25519_make_key(void)
  20615. {
  20616. EXPECT_DECLS;
  20617. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20618. ed25519_key key;
  20619. WC_RNG rng;
  20620. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20621. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20622. XMEMSET(&key, 0, sizeof(ed25519_key));
  20623. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20624. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20625. ExpectIntEQ(wc_InitRng(&rng), 0);
  20626. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20627. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20628. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20629. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20630. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20631. /* Test bad args. */
  20632. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20633. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20634. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20635. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20636. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20637. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20638. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  20639. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20640. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20641. wc_ed25519_free(&key);
  20642. #endif
  20643. return EXPECT_RESULT();
  20644. } /* END test_wc_ed25519_make_key */
  20645. /*
  20646. * Testing wc_ed25519_init()
  20647. */
  20648. static int test_wc_ed25519_init(void)
  20649. {
  20650. EXPECT_DECLS;
  20651. #if defined(HAVE_ED25519)
  20652. ed25519_key key;
  20653. XMEMSET(&key, 0, sizeof(ed25519_key));
  20654. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20655. /* Test bad args. */
  20656. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20657. wc_ed25519_free(&key);
  20658. #endif
  20659. return EXPECT_RESULT();
  20660. } /* END test_wc_ed25519_init */
  20661. /*
  20662. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  20663. */
  20664. static int test_wc_ed25519_sign_msg(void)
  20665. {
  20666. EXPECT_DECLS;
  20667. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  20668. WC_RNG rng;
  20669. ed25519_key key;
  20670. byte msg[] = "Everybody gets Friday off.\n";
  20671. byte sig[ED25519_SIG_SIZE+1];
  20672. word32 msglen = sizeof(msg);
  20673. word32 siglen = ED25519_SIG_SIZE;
  20674. word32 badSigLen = ED25519_SIG_SIZE - 1;
  20675. #ifdef HAVE_ED25519_VERIFY
  20676. int verify_ok = 0; /*1 = Verify success.*/
  20677. #endif
  20678. /* Initialize stack variables. */
  20679. XMEMSET(&key, 0, sizeof(ed25519_key));
  20680. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20681. XMEMSET(sig, 0, sizeof(sig));
  20682. /* Initialize key. */
  20683. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20684. ExpectIntEQ(wc_InitRng(&rng), 0);
  20685. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20686. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  20687. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20688. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  20689. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20690. /* Test bad args. */
  20691. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  20692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20693. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  20694. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20695. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  20696. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20697. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  20698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20699. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  20700. WC_NO_ERR_TRACE(BUFFER_E));
  20701. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  20702. badSigLen -= 1;
  20703. #ifdef HAVE_ED25519_VERIFY
  20704. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20705. &key), 0);
  20706. ExpectIntEQ(verify_ok, 1);
  20707. /* Test bad args. */
  20708. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  20709. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20710. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  20711. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20712. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  20713. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20714. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  20715. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20716. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  20717. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20718. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20719. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20720. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  20721. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20722. #endif /* Verify. */
  20723. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20724. wc_ed25519_free(&key);
  20725. #endif
  20726. return EXPECT_RESULT();
  20727. } /* END test_wc_ed25519_sign_msg */
  20728. /*
  20729. * Testing wc_ed25519_import_public()
  20730. */
  20731. static int test_wc_ed25519_import_public(void)
  20732. {
  20733. EXPECT_DECLS;
  20734. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20735. ed25519_key pubKey;
  20736. WC_RNG rng;
  20737. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  20738. word32 inlen = sizeof(in);
  20739. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  20740. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20741. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  20742. ExpectIntEQ(wc_InitRng(&rng), 0);
  20743. #ifdef HAVE_ED25519_MAKE_KEY
  20744. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  20745. #endif
  20746. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  20747. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  20748. /* Test bad args. */
  20749. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20750. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20751. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20752. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20753. wc_ed25519_free(&pubKey);
  20754. #endif
  20755. return EXPECT_RESULT();
  20756. } /* END wc_ed25519_import_public */
  20757. /*
  20758. * Testing wc_ed25519_import_private_key()
  20759. */
  20760. static int test_wc_ed25519_import_private_key(void)
  20761. {
  20762. EXPECT_DECLS;
  20763. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20764. ed25519_key key;
  20765. WC_RNG rng;
  20766. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  20767. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  20768. word32 privKeySz = sizeof(privKey);
  20769. word32 pubKeySz = sizeof(pubKey);
  20770. #ifdef HAVE_ED25519_KEY_EXPORT
  20771. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  20772. word32 bothKeysSz = sizeof(bothKeys);
  20773. #endif
  20774. XMEMSET(&key, 0, sizeof(ed25519_key));
  20775. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20776. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20777. ExpectIntEQ(wc_InitRng(&rng), 0);
  20778. #ifdef HAVE_ED25519_MAKE_KEY
  20779. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20780. #endif
  20781. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  20782. pubKeySz, &key, 1), 0);
  20783. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  20784. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  20785. #ifdef HAVE_ED25519_KEY_EXPORT
  20786. PRIVATE_KEY_UNLOCK();
  20787. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  20788. PRIVATE_KEY_LOCK();
  20789. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  20790. &key, 1), 0);
  20791. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  20792. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  20793. #endif
  20794. /* Test bad args. */
  20795. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  20796. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20797. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  20798. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20799. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  20800. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20801. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  20802. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20803. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  20804. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20805. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  20806. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20807. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20808. wc_ed25519_free(&key);
  20809. #endif
  20810. return EXPECT_RESULT();
  20811. } /* END test_wc_ed25519_import_private_key */
  20812. /*
  20813. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  20814. */
  20815. static int test_wc_ed25519_export(void)
  20816. {
  20817. EXPECT_DECLS;
  20818. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  20819. ed25519_key key;
  20820. WC_RNG rng;
  20821. byte priv[ED25519_PRV_KEY_SIZE];
  20822. byte pub[ED25519_PUB_KEY_SIZE];
  20823. word32 privSz = sizeof(priv);
  20824. word32 pubSz = sizeof(pub);
  20825. #ifndef HAVE_ED25519_MAKE_KEY
  20826. const byte privKey[] = {
  20827. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20828. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20829. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20830. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20831. };
  20832. const byte pubKey[] = {
  20833. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20834. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20835. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20836. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20837. };
  20838. #endif
  20839. XMEMSET(&key, 0, sizeof(ed25519_key));
  20840. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20841. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20842. ExpectIntEQ(wc_InitRng(&rng), 0);
  20843. #ifdef HAVE_ED25519_MAKE_KEY
  20844. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20845. #else
  20846. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20847. pubKey, sizeof(pubKey), &key, 1), 0);
  20848. #endif
  20849. PRIVATE_KEY_UNLOCK();
  20850. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  20851. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  20852. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  20853. /* Test bad args. */
  20854. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20855. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20856. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20857. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  20858. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  20859. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  20860. /* Test bad args. */
  20861. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  20862. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20863. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  20864. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20865. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  20866. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20867. PRIVATE_KEY_LOCK();
  20868. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20869. wc_ed25519_free(&key);
  20870. #endif
  20871. return EXPECT_RESULT();
  20872. } /* END test_wc_ed25519_export */
  20873. /*
  20874. * Testing wc_ed25519_size()
  20875. */
  20876. static int test_wc_ed25519_size(void)
  20877. {
  20878. EXPECT_DECLS;
  20879. #if defined(HAVE_ED25519)
  20880. ed25519_key key;
  20881. WC_RNG rng;
  20882. #ifndef HAVE_ED25519_MAKE_KEY
  20883. const byte privKey[] = {
  20884. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20885. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20886. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20887. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20888. };
  20889. const byte pubKey[] = {
  20890. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20891. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20892. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20893. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20894. };
  20895. #endif
  20896. XMEMSET(&key, 0, sizeof(ed25519_key));
  20897. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20898. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20899. ExpectIntEQ(wc_InitRng(&rng), 0);
  20900. #ifdef HAVE_ED25519_MAKE_KEY
  20901. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20902. #else
  20903. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20904. pubKey, sizeof(pubKey), &key, 1), 0);
  20905. #endif
  20906. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  20907. /* Test bad args. */
  20908. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20909. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  20910. /* Test bad args. */
  20911. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20912. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  20913. /* Test bad args. */
  20914. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20915. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  20916. /* Test bad args. */
  20917. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20918. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20919. wc_ed25519_free(&key);
  20920. #endif
  20921. return EXPECT_RESULT();
  20922. } /* END test_wc_ed25519_size */
  20923. /*
  20924. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  20925. */
  20926. static int test_wc_ed25519_exportKey(void)
  20927. {
  20928. EXPECT_DECLS;
  20929. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  20930. WC_RNG rng;
  20931. ed25519_key key;
  20932. byte priv[ED25519_PRV_KEY_SIZE];
  20933. byte pub[ED25519_PUB_KEY_SIZE];
  20934. byte privOnly[ED25519_PRV_KEY_SIZE];
  20935. word32 privSz = sizeof(priv);
  20936. word32 pubSz = sizeof(pub);
  20937. word32 privOnlySz = sizeof(privOnly);
  20938. #ifndef HAVE_ED25519_MAKE_KEY
  20939. const byte privKey[] = {
  20940. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  20941. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  20942. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  20943. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  20944. };
  20945. const byte pubKey[] = {
  20946. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  20947. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  20948. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  20949. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  20950. };
  20951. #endif
  20952. XMEMSET(&key, 0, sizeof(ed25519_key));
  20953. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20954. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20955. ExpectIntEQ(wc_InitRng(&rng), 0);
  20956. #ifdef HAVE_ED25519_MAKE_KEY
  20957. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20958. #else
  20959. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  20960. pubKey, sizeof(pubKey), &key, 1), 0);
  20961. #endif
  20962. PRIVATE_KEY_UNLOCK();
  20963. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  20964. /* Test bad args. */
  20965. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  20966. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20967. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  20968. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20969. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20970. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  20971. /* Test bad args. */
  20972. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  20973. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20974. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  20975. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20976. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  20977. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20978. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  20979. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20980. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  20981. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20982. PRIVATE_KEY_LOCK();
  20983. /* Cross check output. */
  20984. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  20985. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20986. wc_ed25519_free(&key);
  20987. #endif
  20988. return EXPECT_RESULT();
  20989. } /* END test_wc_ed25519_exportKey */
  20990. /*
  20991. * Testing wc_Ed25519PublicKeyToDer
  20992. */
  20993. static int test_wc_Ed25519PublicKeyToDer(void)
  20994. {
  20995. EXPECT_DECLS;
  20996. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  20997. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  20998. ed25519_key key;
  20999. byte derBuf[1024];
  21000. XMEMSET(&key, 0, sizeof(ed25519_key));
  21001. /* Test bad args */
  21002. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21003. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21004. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21005. wc_ed25519_free(&key);
  21006. /* Test good args */
  21007. if (EXPECT_SUCCESS()) {
  21008. WC_RNG rng;
  21009. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21010. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21011. ExpectIntEQ(wc_InitRng(&rng), 0);
  21012. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21013. /* length only */
  21014. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  21015. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  21016. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  21017. (word32)sizeof(derBuf), 1), 0);
  21018. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21019. wc_ed25519_free(&key);
  21020. }
  21021. #endif
  21022. return EXPECT_RESULT();
  21023. } /* END testing wc_Ed25519PublicKeyToDer */
  21024. /*
  21025. * Testing wc_curve25519_init and wc_curve25519_free.
  21026. */
  21027. static int test_wc_curve25519_init(void)
  21028. {
  21029. EXPECT_DECLS;
  21030. #if defined(HAVE_CURVE25519)
  21031. curve25519_key key;
  21032. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21033. /* Test bad args for wc_curve25519_init */
  21034. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21035. /* Test good args for wc_curve_25519_free */
  21036. wc_curve25519_free(&key);
  21037. /* Test bad args for wc_curve25519 free. */
  21038. wc_curve25519_free(NULL);
  21039. #endif
  21040. return EXPECT_RESULT();
  21041. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  21042. /*
  21043. * Testing test_wc_curve25519_size.
  21044. */
  21045. static int test_wc_curve25519_size(void)
  21046. {
  21047. EXPECT_DECLS;
  21048. #if defined(HAVE_CURVE25519)
  21049. curve25519_key key;
  21050. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21051. /* Test good args for wc_curve25519_size */
  21052. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21053. /* Test bad args for wc_curve25519_size */
  21054. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  21055. wc_curve25519_free(&key);
  21056. #endif
  21057. return EXPECT_RESULT();
  21058. } /* END test_wc_curve25519_size*/
  21059. /*
  21060. * Testing test_wc_curve25519_export_key_raw().
  21061. */
  21062. static int test_wc_curve25519_export_key_raw(void)
  21063. {
  21064. EXPECT_DECLS;
  21065. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21066. curve25519_key key;
  21067. WC_RNG rng;
  21068. byte privateKey[CURVE25519_KEYSIZE];
  21069. byte publicKey[CURVE25519_KEYSIZE];
  21070. word32 prvkSz;
  21071. word32 pubkSz;
  21072. byte prik[CURVE25519_KEYSIZE];
  21073. byte pubk[CURVE25519_KEYSIZE];
  21074. word32 prksz;
  21075. word32 pbksz;
  21076. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21077. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21078. ExpectIntEQ(wc_InitRng(&rng), 0);
  21079. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21080. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21081. prvkSz = CURVE25519_KEYSIZE;
  21082. pubkSz = CURVE25519_KEYSIZE;
  21083. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  21084. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21085. prvkSz = CURVE25519_KEYSIZE;
  21086. pubkSz = CURVE25519_KEYSIZE;
  21087. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  21088. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21089. prvkSz = CURVE25519_KEYSIZE;
  21090. pubkSz = CURVE25519_KEYSIZE;
  21091. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  21092. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21093. /* prvkSz = CURVE25519_KEYSIZE; */
  21094. pubkSz = CURVE25519_KEYSIZE;
  21095. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21096. NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21097. prvkSz = CURVE25519_KEYSIZE;
  21098. pubkSz = CURVE25519_KEYSIZE;
  21099. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21100. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21101. /* cross-testing */
  21102. prksz = CURVE25519_KEYSIZE;
  21103. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  21104. pbksz = CURVE25519_KEYSIZE;
  21105. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  21106. prvkSz = CURVE25519_KEYSIZE;
  21107. /* pubkSz = CURVE25519_KEYSIZE; */
  21108. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21109. publicKey, &pubkSz), 0);
  21110. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21111. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21112. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21113. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21114. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21115. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21116. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21117. wc_curve25519_free(&key);
  21118. #endif
  21119. return EXPECT_RESULT();
  21120. } /* end of test_wc_curve25519_export_key_raw */
  21121. /*
  21122. * Testing test_wc_curve25519_export_key_raw_ex().
  21123. */
  21124. static int test_wc_curve25519_export_key_raw_ex(void)
  21125. {
  21126. EXPECT_DECLS;
  21127. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21128. curve25519_key key;
  21129. WC_RNG rng;
  21130. byte privateKey[CURVE25519_KEYSIZE];
  21131. byte publicKey[CURVE25519_KEYSIZE];
  21132. word32 prvkSz;
  21133. word32 pubkSz;
  21134. byte prik[CURVE25519_KEYSIZE];
  21135. byte pubk[CURVE25519_KEYSIZE];
  21136. word32 prksz;
  21137. word32 pbksz;
  21138. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21139. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21140. ExpectIntEQ(wc_InitRng(&rng), 0);
  21141. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21142. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21143. prvkSz = CURVE25519_KEYSIZE;
  21144. pubkSz = CURVE25519_KEYSIZE;
  21145. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21146. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21147. prvkSz = CURVE25519_KEYSIZE;
  21148. pubkSz = CURVE25519_KEYSIZE;
  21149. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21150. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21151. prvkSz = CURVE25519_KEYSIZE;
  21152. pubkSz = CURVE25519_KEYSIZE;
  21153. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21154. NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21155. /* prvkSz = CURVE25519_KEYSIZE; */
  21156. pubkSz = CURVE25519_KEYSIZE;
  21157. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21158. &prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21159. prvkSz = CURVE25519_KEYSIZE;
  21160. pubkSz = CURVE25519_KEYSIZE;
  21161. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21162. &prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21163. prvkSz = CURVE25519_KEYSIZE;
  21164. /* pubkSz = CURVE25519_KEYSIZE; */
  21165. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21166. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21167. prvkSz = CURVE25519_KEYSIZE;
  21168. pubkSz = CURVE25519_KEYSIZE;
  21169. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21170. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21171. prvkSz = CURVE25519_KEYSIZE;
  21172. pubkSz = CURVE25519_KEYSIZE;
  21173. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21174. NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21175. /* prvkSz = CURVE25519_KEYSIZE; */
  21176. pubkSz = CURVE25519_KEYSIZE;
  21177. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21178. &prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21179. prvkSz = CURVE25519_KEYSIZE;
  21180. pubkSz = CURVE25519_KEYSIZE;
  21181. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21182. &prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21183. /* illegal value for endian */
  21184. prvkSz = CURVE25519_KEYSIZE;
  21185. /* pubkSz = CURVE25519_KEYSIZE; */
  21186. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21187. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21188. /* cross-testing */
  21189. prksz = CURVE25519_KEYSIZE;
  21190. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  21191. pbksz = CURVE25519_KEYSIZE;
  21192. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  21193. prvkSz = CURVE25519_KEYSIZE;
  21194. /* pubkSz = CURVE25519_KEYSIZE; */
  21195. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21196. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21197. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21198. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21199. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21200. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21201. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21202. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21203. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21204. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  21205. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21206. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21207. /* try once with another endian */
  21208. prvkSz = CURVE25519_KEYSIZE;
  21209. pubkSz = CURVE25519_KEYSIZE;
  21210. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  21211. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21212. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21213. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21214. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21215. wc_curve25519_free(&key);
  21216. #endif
  21217. return EXPECT_RESULT();
  21218. } /* end of test_wc_curve25519_export_key_raw_ex */
  21219. /*
  21220. * Testing wc_curve25519_make_key
  21221. */
  21222. static int test_wc_curve25519_make_key(void)
  21223. {
  21224. EXPECT_DECLS;
  21225. #if defined(HAVE_CURVE25519)
  21226. curve25519_key key;
  21227. WC_RNG rng;
  21228. int keysize;
  21229. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21230. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21231. ExpectIntEQ(wc_InitRng(&rng), 0);
  21232. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21233. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21234. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21235. /* test bad cases*/
  21236. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21237. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21238. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21239. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21240. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21241. wc_curve25519_free(&key);
  21242. #endif
  21243. return EXPECT_RESULT();
  21244. } /* END test_wc_curve25519_make_key*/
  21245. /*
  21246. * Testing wc_curve25519_shared_secret_ex
  21247. */
  21248. static int test_wc_curve25519_shared_secret_ex(void)
  21249. {
  21250. EXPECT_DECLS;
  21251. #if defined(HAVE_CURVE25519)
  21252. curve25519_key private_key;
  21253. curve25519_key public_key;
  21254. WC_RNG rng;
  21255. byte out[CURVE25519_KEYSIZE];
  21256. word32 outLen = sizeof(out);
  21257. int endian = EC25519_BIG_ENDIAN;
  21258. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21259. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21260. ExpectIntEQ(wc_InitRng(&rng), 0);
  21261. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21262. 0);
  21263. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21264. 0);
  21265. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21266. &outLen, endian), 0);
  21267. /* test bad cases*/
  21268. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21269. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21270. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21271. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21272. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21273. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21274. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21275. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21276. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21277. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21278. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21279. * increasing to 0x8f checks for error being returned*/
  21280. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21281. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21282. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21283. outLen = outLen - 2;
  21284. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21285. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21286. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21287. wc_curve25519_free(&private_key);
  21288. wc_curve25519_free(&public_key);
  21289. #endif
  21290. return EXPECT_RESULT();
  21291. } /* END test_wc_curve25519_shared_secret_ex*/
  21292. /*
  21293. * Testing wc_curve25519_make_pub
  21294. */
  21295. static int test_wc_curve25519_make_pub(void)
  21296. {
  21297. EXPECT_DECLS;
  21298. #ifdef HAVE_CURVE25519
  21299. curve25519_key key;
  21300. WC_RNG rng;
  21301. byte out[CURVE25519_KEYSIZE];
  21302. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21303. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21304. ExpectIntEQ(wc_InitRng(&rng), 0);
  21305. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21306. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21307. (int)sizeof(key.k), key.k), 0);
  21308. /* test bad cases*/
  21309. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21310. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21311. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21312. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21313. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21314. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21315. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21316. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21317. /* verify clamping test */
  21318. key.k[0] |= ~248;
  21319. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21320. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21321. key.k[0] &= 248;
  21322. /* repeat the expected-to-succeed test. */
  21323. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21324. key.k), 0);
  21325. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21326. wc_curve25519_free(&key);
  21327. #endif
  21328. return EXPECT_RESULT();
  21329. } /* END test_wc_curve25519_make_pub */
  21330. /*
  21331. * Testing test_wc_curve25519_export_public_ex
  21332. */
  21333. static int test_wc_curve25519_export_public_ex(void)
  21334. {
  21335. EXPECT_DECLS;
  21336. #if defined(HAVE_CURVE25519)
  21337. curve25519_key key;
  21338. WC_RNG rng;
  21339. byte out[CURVE25519_KEYSIZE];
  21340. word32 outLen = sizeof(out);
  21341. int endian = EC25519_BIG_ENDIAN;
  21342. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21343. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21344. ExpectIntEQ(wc_InitRng(&rng), 0);
  21345. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21346. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21347. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21348. /* test bad cases*/
  21349. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21350. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21351. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21352. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21353. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21354. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21355. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21356. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21357. outLen = outLen - 2;
  21358. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21359. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21360. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21361. wc_curve25519_free(&key);
  21362. #endif
  21363. return EXPECT_RESULT();
  21364. } /* END test_wc_curve25519_export_public_ex*/
  21365. /*
  21366. * Testing test_wc_curve25519_import_private_raw_ex
  21367. */
  21368. static int test_wc_curve25519_import_private_raw_ex(void)
  21369. {
  21370. EXPECT_DECLS;
  21371. #if defined(HAVE_CURVE25519)
  21372. curve25519_key key;
  21373. WC_RNG rng;
  21374. byte priv[CURVE25519_KEYSIZE];
  21375. byte pub[CURVE25519_KEYSIZE];
  21376. word32 privSz = sizeof(priv);
  21377. word32 pubSz = sizeof(pub);
  21378. int endian = EC25519_BIG_ENDIAN;
  21379. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21380. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21381. ExpectIntEQ(wc_InitRng(&rng), 0);
  21382. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21383. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21384. endian), 0);
  21385. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21386. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21387. &key, endian), 0);
  21388. /* test bad cases*/
  21389. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21390. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21391. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21392. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21393. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21394. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21395. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21396. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21397. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21398. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21399. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21400. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21401. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21402. &key, EC25519_LITTLE_ENDIAN), 0);
  21403. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21404. wc_curve25519_free(&key);
  21405. #endif
  21406. return EXPECT_RESULT();
  21407. } /* END test_wc_curve25519_import_private_raw_ex*/
  21408. /*
  21409. * Testing test_wc_curve25519_import_private
  21410. */
  21411. static int test_wc_curve25519_import_private(void)
  21412. {
  21413. EXPECT_DECLS;
  21414. #if defined(HAVE_CURVE25519)
  21415. curve25519_key key;
  21416. WC_RNG rng;
  21417. byte priv[CURVE25519_KEYSIZE];
  21418. word32 privSz = sizeof(priv);
  21419. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21420. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21421. ExpectIntEQ(wc_InitRng(&rng), 0);
  21422. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21423. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21424. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21425. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21426. wc_curve25519_free(&key);
  21427. #endif
  21428. return EXPECT_RESULT();
  21429. } /* END test_wc_curve25519_import*/
  21430. /*
  21431. * Testing test_wc_curve25519_export_private_raw_ex
  21432. */
  21433. static int test_wc_curve25519_export_private_raw_ex(void)
  21434. {
  21435. EXPECT_DECLS;
  21436. #if defined(HAVE_CURVE25519)
  21437. curve25519_key key;
  21438. byte out[CURVE25519_KEYSIZE];
  21439. word32 outLen = sizeof(out);
  21440. int endian = EC25519_BIG_ENDIAN;
  21441. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21442. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21443. 0);
  21444. /* test bad cases*/
  21445. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21446. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21447. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21448. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21449. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21450. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21451. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21452. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21453. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21454. EC25519_LITTLE_ENDIAN), 0);
  21455. outLen = outLen - 2;
  21456. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21457. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21458. wc_curve25519_free(&key);
  21459. #endif
  21460. return EXPECT_RESULT();
  21461. } /* END test_wc_curve25519_export_private_raw_ex*/
  21462. /*
  21463. * Testing wc_ed448_make_key().
  21464. */
  21465. static int test_wc_ed448_make_key(void)
  21466. {
  21467. EXPECT_DECLS;
  21468. #if defined(HAVE_ED448)
  21469. ed448_key key;
  21470. WC_RNG rng;
  21471. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21472. XMEMSET(&key, 0, sizeof(ed448_key));
  21473. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21474. ExpectIntEQ(wc_ed448_init(&key), 0);
  21475. ExpectIntEQ(wc_InitRng(&rng), 0);
  21476. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21477. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21478. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21479. /* Test bad args. */
  21480. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21481. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21482. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21483. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21484. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21485. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21486. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21487. wc_ed448_free(&key);
  21488. #endif
  21489. return EXPECT_RESULT();
  21490. } /* END test_wc_ed448_make_key */
  21491. /*
  21492. * Testing wc_ed448_init()
  21493. */
  21494. static int test_wc_ed448_init(void)
  21495. {
  21496. EXPECT_DECLS;
  21497. #if defined(HAVE_ED448)
  21498. ed448_key key;
  21499. XMEMSET(&key, 0, sizeof(ed448_key));
  21500. ExpectIntEQ(wc_ed448_init(&key), 0);
  21501. /* Test bad args. */
  21502. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21503. wc_ed448_free(&key);
  21504. #endif
  21505. return EXPECT_RESULT();
  21506. } /* END test_wc_ed448_init */
  21507. /*
  21508. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21509. */
  21510. static int test_wc_ed448_sign_msg(void)
  21511. {
  21512. EXPECT_DECLS;
  21513. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21514. ed448_key key;
  21515. WC_RNG rng;
  21516. byte msg[] = "Everybody gets Friday off.\n";
  21517. byte sig[ED448_SIG_SIZE];
  21518. word32 msglen = sizeof(msg);
  21519. word32 siglen = sizeof(sig);
  21520. word32 badSigLen = sizeof(sig) - 1;
  21521. #ifdef HAVE_ED448_VERIFY
  21522. int verify_ok = 0; /*1 = Verify success.*/
  21523. #endif
  21524. /* Initialize stack variables. */
  21525. XMEMSET(&key, 0, sizeof(ed448_key));
  21526. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21527. XMEMSET(sig, 0, siglen);
  21528. /* Initialize key. */
  21529. ExpectIntEQ(wc_ed448_init(&key), 0);
  21530. ExpectIntEQ(wc_InitRng(&rng), 0);
  21531. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21532. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21533. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21534. /* Test bad args. */
  21535. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21536. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21537. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21538. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21539. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21540. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21541. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21542. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21543. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21544. WC_NO_ERR_TRACE(BUFFER_E));
  21545. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21546. badSigLen -= 1;
  21547. #ifdef HAVE_ED448_VERIFY
  21548. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21549. NULL, 0), 0);
  21550. ExpectIntEQ(verify_ok, 1);
  21551. /* Test bad args. */
  21552. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21553. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21554. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21555. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21556. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21557. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21558. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21559. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21560. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21561. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21562. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21563. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21564. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21565. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21566. #endif /* Verify. */
  21567. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21568. wc_ed448_free(&key);
  21569. #endif
  21570. return EXPECT_RESULT();
  21571. } /* END test_wc_ed448_sign_msg */
  21572. /*
  21573. * Testing wc_ed448_import_public()
  21574. */
  21575. static int test_wc_ed448_import_public(void)
  21576. {
  21577. EXPECT_DECLS;
  21578. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21579. ed448_key pubKey;
  21580. WC_RNG rng;
  21581. const byte in[] =
  21582. "Ed448PublicKeyUnitTest.................................\n";
  21583. word32 inlen = sizeof(in);
  21584. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21585. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21586. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21587. ExpectIntEQ(wc_InitRng(&rng), 0);
  21588. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21589. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21590. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21591. /* Test bad args. */
  21592. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21593. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21594. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21595. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21596. wc_ed448_free(&pubKey);
  21597. #endif
  21598. return EXPECT_RESULT();
  21599. } /* END wc_ed448_import_public */
  21600. /*
  21601. * Testing wc_ed448_import_private_key()
  21602. */
  21603. static int test_wc_ed448_import_private_key(void)
  21604. {
  21605. EXPECT_DECLS;
  21606. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21607. ed448_key key;
  21608. WC_RNG rng;
  21609. const byte privKey[] =
  21610. "Ed448PrivateKeyUnitTest................................\n";
  21611. const byte pubKey[] =
  21612. "Ed448PublicKeyUnitTest.................................\n";
  21613. word32 privKeySz = sizeof(privKey);
  21614. word32 pubKeySz = sizeof(pubKey);
  21615. #ifdef HAVE_ED448_KEY_EXPORT
  21616. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21617. word32 bothKeysSz = sizeof(bothKeys);
  21618. #endif
  21619. XMEMSET(&key, 0, sizeof(ed448_key));
  21620. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21621. ExpectIntEQ(wc_ed448_init(&key), 0);
  21622. ExpectIntEQ(wc_InitRng(&rng), 0);
  21623. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21624. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21625. pubKeySz, &key, 1), 0);
  21626. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21627. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21628. #ifdef HAVE_ED448_KEY_EXPORT
  21629. PRIVATE_KEY_UNLOCK();
  21630. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21631. PRIVATE_KEY_LOCK();
  21632. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21633. &key, 1), 0);
  21634. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21635. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21636. #endif
  21637. /* Test bad args. */
  21638. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21639. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21640. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  21641. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21642. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21643. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21644. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  21645. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21646. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21647. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21648. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  21649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21650. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21651. wc_ed448_free(&key);
  21652. #endif
  21653. return EXPECT_RESULT();
  21654. } /* END test_wc_ed448_import_private_key */
  21655. /*
  21656. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  21657. */
  21658. static int test_wc_ed448_export(void)
  21659. {
  21660. EXPECT_DECLS;
  21661. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21662. ed448_key key;
  21663. WC_RNG rng;
  21664. byte priv[ED448_PRV_KEY_SIZE];
  21665. byte pub[ED448_PUB_KEY_SIZE];
  21666. word32 privSz = sizeof(priv);
  21667. word32 pubSz = sizeof(pub);
  21668. XMEMSET(&key, 0, sizeof(ed448_key));
  21669. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21670. ExpectIntEQ(wc_ed448_init(&key), 0);
  21671. ExpectIntEQ(wc_InitRng(&rng), 0);
  21672. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21673. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  21674. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  21675. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21676. /* Test bad args. */
  21677. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21678. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21679. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21680. PRIVATE_KEY_UNLOCK();
  21681. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  21682. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  21683. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21684. /* Test bad args. */
  21685. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  21686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21687. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  21688. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21689. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21690. PRIVATE_KEY_LOCK();
  21691. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21692. wc_ed448_free(&key);
  21693. #endif
  21694. return EXPECT_RESULT();
  21695. } /* END test_wc_ed448_export */
  21696. /*
  21697. * Testing wc_ed448_size()
  21698. */
  21699. static int test_wc_ed448_size(void)
  21700. {
  21701. EXPECT_DECLS;
  21702. #if defined(HAVE_ED448)
  21703. ed448_key key;
  21704. WC_RNG rng;
  21705. XMEMSET(&key, 0, sizeof(ed448_key));
  21706. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21707. ExpectIntEQ(wc_ed448_init(&key), 0);
  21708. ExpectIntEQ(wc_InitRng(&rng), 0);
  21709. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21710. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  21711. /* Test bad args. */
  21712. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21713. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  21714. /* Test bad args. */
  21715. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21716. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  21717. /* Test bad args. */
  21718. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21719. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  21720. /* Test bad args. */
  21721. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21722. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21723. wc_ed448_free(&key);
  21724. #endif
  21725. return EXPECT_RESULT();
  21726. } /* END test_wc_ed448_size */
  21727. /*
  21728. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  21729. */
  21730. static int test_wc_ed448_exportKey(void)
  21731. {
  21732. EXPECT_DECLS;
  21733. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21734. ed448_key key;
  21735. WC_RNG rng;
  21736. byte priv[ED448_PRV_KEY_SIZE];
  21737. byte pub[ED448_PUB_KEY_SIZE];
  21738. byte privOnly[ED448_PRV_KEY_SIZE];
  21739. word32 privSz = sizeof(priv);
  21740. word32 pubSz = sizeof(pub);
  21741. word32 privOnlySz = sizeof(privOnly);
  21742. XMEMSET(&key, 0, sizeof(ed448_key));
  21743. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21744. ExpectIntEQ(wc_ed448_init(&key), 0);
  21745. ExpectIntEQ(wc_InitRng(&rng), 0);
  21746. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21747. PRIVATE_KEY_UNLOCK();
  21748. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  21749. /* Test bad args. */
  21750. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  21751. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21752. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21753. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21754. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21755. /* Test bad args. */
  21756. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  21757. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21758. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  21759. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21760. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  21761. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21762. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  21763. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21764. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  21765. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21766. PRIVATE_KEY_LOCK();
  21767. /* Cross check output. */
  21768. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21769. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21770. wc_ed448_free(&key);
  21771. #endif
  21772. return EXPECT_RESULT();
  21773. } /* END test_wc_ed448_exportKey */
  21774. /*
  21775. * Testing wc_Ed448PublicKeyToDer
  21776. */
  21777. static int test_wc_Ed448PublicKeyToDer(void)
  21778. {
  21779. EXPECT_DECLS;
  21780. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  21781. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21782. ed448_key key;
  21783. byte derBuf[1024];
  21784. XMEMSET(&key, 0, sizeof(ed448_key));
  21785. /* Test bad args */
  21786. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21787. ExpectIntEQ(wc_ed448_init(&key), 0);
  21788. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21789. wc_ed448_free(&key);
  21790. /* Test good args */
  21791. if (EXPECT_SUCCESS()) {
  21792. WC_RNG rng;
  21793. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21794. ExpectIntEQ(wc_ed448_init(&key), 0);
  21795. ExpectIntEQ(wc_InitRng(&rng), 0);
  21796. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21797. /* length only */
  21798. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  21799. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  21800. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  21801. (word32)sizeof(derBuf), 1), 0);
  21802. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21803. wc_ed448_free(&key);
  21804. }
  21805. #endif
  21806. return EXPECT_RESULT();
  21807. } /* END testing wc_Ed448PublicKeyToDer */
  21808. /*
  21809. * Testing wc_curve448_init and wc_curve448_free.
  21810. */
  21811. static int test_wc_curve448_init(void)
  21812. {
  21813. EXPECT_DECLS;
  21814. #if defined(HAVE_CURVE448)
  21815. curve448_key key;
  21816. /* Test bad args for wc_curve448_init */
  21817. ExpectIntEQ(wc_curve448_init(&key), 0);
  21818. /* Test bad args for wc_curve448_init */
  21819. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21820. /* Test good args for wc_curve_448_free */
  21821. wc_curve448_free(&key);
  21822. /* Test bad args for wc_curve448_free */
  21823. wc_curve448_free(NULL);
  21824. #endif
  21825. return EXPECT_RESULT();
  21826. } /* END test_wc_curve448_init and wc_curve_448_free*/
  21827. /*
  21828. * Testing wc_curve448_make_key
  21829. */
  21830. static int test_wc_curve448_make_key(void)
  21831. {
  21832. EXPECT_DECLS;
  21833. #if defined(HAVE_CURVE448)
  21834. curve448_key key;
  21835. WC_RNG rng;
  21836. int keysize;
  21837. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21838. ExpectIntEQ(wc_curve448_init(&key), 0);
  21839. ExpectIntEQ(wc_InitRng(&rng), 0);
  21840. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21841. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  21842. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  21843. /* test bad cases */
  21844. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21845. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21846. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21847. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21848. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21849. wc_curve448_free(&key);
  21850. #endif
  21851. return EXPECT_RESULT();
  21852. } /* END test_wc_curve448_make_key*/
  21853. /*
  21854. * Testing test_wc_curve448_shared_secret_ex
  21855. */
  21856. static int test_wc_curve448_shared_secret_ex(void)
  21857. {
  21858. EXPECT_DECLS;
  21859. #if defined(HAVE_CURVE448)
  21860. curve448_key private_key;
  21861. curve448_key public_key;
  21862. WC_RNG rng;
  21863. byte out[CURVE448_KEY_SIZE];
  21864. word32 outLen = sizeof(out);
  21865. int endian = EC448_BIG_ENDIAN;
  21866. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21867. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  21868. ExpectIntEQ(wc_InitRng(&rng), 0);
  21869. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  21870. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  21871. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  21872. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21873. &outLen, endian), 0);
  21874. /* test bad cases */
  21875. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21876. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21877. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  21878. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21879. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  21880. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21881. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  21882. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21883. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21884. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21885. outLen = outLen - 2;
  21886. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  21887. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21888. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21889. wc_curve448_free(&private_key);
  21890. wc_curve448_free(&public_key);
  21891. #endif
  21892. return EXPECT_RESULT();
  21893. } /* END test_wc_curve448_shared_secret_ex*/
  21894. /*
  21895. * Testing test_wc_curve448_export_public_ex
  21896. */
  21897. static int test_wc_curve448_export_public_ex(void)
  21898. {
  21899. EXPECT_DECLS;
  21900. #if defined(HAVE_CURVE448)
  21901. WC_RNG rng;
  21902. curve448_key key;
  21903. byte out[CURVE448_KEY_SIZE];
  21904. word32 outLen = sizeof(out);
  21905. int endian = EC448_BIG_ENDIAN;
  21906. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21907. ExpectIntEQ(wc_curve448_init(&key), 0);
  21908. ExpectIntEQ(wc_InitRng(&rng), 0);
  21909. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21910. ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
  21911. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  21912. /* test bad cases*/
  21913. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  21914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21915. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  21916. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21917. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  21918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21919. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  21920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21921. outLen = outLen - 2;
  21922. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  21923. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21924. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21925. wc_curve448_free(&key);
  21926. #endif
  21927. return EXPECT_RESULT();
  21928. } /* END test_wc_curve448_export_public_ex*/
  21929. /*
  21930. * Testing test_wc_curve448_export_private_raw_ex
  21931. */
  21932. static int test_wc_curve448_export_private_raw_ex(void)
  21933. {
  21934. EXPECT_DECLS;
  21935. #if defined(HAVE_CURVE448)
  21936. curve448_key key;
  21937. byte out[CURVE448_KEY_SIZE];
  21938. word32 outLen = sizeof(out);
  21939. int endian = EC448_BIG_ENDIAN;
  21940. ExpectIntEQ(wc_curve448_init(&key), 0);
  21941. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  21942. 0);
  21943. /* test bad cases*/
  21944. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  21945. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21946. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  21947. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21948. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  21949. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21950. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  21951. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21952. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  21953. EC448_LITTLE_ENDIAN), 0);
  21954. outLen = outLen - 2;
  21955. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  21956. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21957. wc_curve448_free(&key);
  21958. #endif
  21959. return EXPECT_RESULT();
  21960. } /* END test_wc_curve448_export_private_raw_ex*/
  21961. /*
  21962. * Testing test_wc_curve448_import_private_raw_ex
  21963. */
  21964. static int test_wc_curve448_import_private_raw_ex(void)
  21965. {
  21966. EXPECT_DECLS;
  21967. #if defined(HAVE_CURVE448)
  21968. curve448_key key;
  21969. WC_RNG rng;
  21970. byte priv[CURVE448_KEY_SIZE];
  21971. byte pub[CURVE448_KEY_SIZE];
  21972. word32 privSz = sizeof(priv);
  21973. word32 pubSz = sizeof(pub);
  21974. int endian = EC448_BIG_ENDIAN;
  21975. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21976. ExpectIntEQ(wc_curve448_init(&key), 0);
  21977. ExpectIntEQ(wc_InitRng(&rng), 0);
  21978. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  21979. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  21980. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  21981. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21982. &key, endian), 0);
  21983. /* test bad cases */
  21984. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  21985. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21986. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21987. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21988. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21989. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21990. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21991. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21992. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  21993. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21994. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  21995. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21996. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  21997. &key, EC448_LITTLE_ENDIAN), 0);
  21998. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21999. wc_curve448_free(&key);
  22000. #endif
  22001. return EXPECT_RESULT();
  22002. } /* END test_wc_curve448_import_private_raw_ex*/
  22003. /*
  22004. * Testing test_curve448_export_key_raw
  22005. */
  22006. static int test_wc_curve448_export_key_raw(void)
  22007. {
  22008. EXPECT_DECLS;
  22009. #if defined(HAVE_CURVE448)
  22010. curve448_key key;
  22011. WC_RNG rng;
  22012. byte priv[CURVE448_KEY_SIZE];
  22013. byte pub[CURVE448_KEY_SIZE];
  22014. word32 privSz = sizeof(priv);
  22015. word32 pubSz = sizeof(pub);
  22016. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22017. ExpectIntEQ(wc_curve448_init(&key), 0);
  22018. ExpectIntEQ(wc_InitRng(&rng), 0);
  22019. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22020. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22021. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22022. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  22023. 0);
  22024. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22025. wc_curve448_free(&key);
  22026. #endif
  22027. return EXPECT_RESULT();
  22028. } /* END test_wc_curve448_import_private_raw_ex*/
  22029. /*
  22030. * Testing test_wc_curve448_import_private
  22031. */
  22032. static int test_wc_curve448_import_private(void)
  22033. {
  22034. EXPECT_DECLS;
  22035. #if defined(HAVE_CURVE448)
  22036. curve448_key key;
  22037. WC_RNG rng;
  22038. byte priv[CURVE448_KEY_SIZE];
  22039. word32 privSz = sizeof(priv);
  22040. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22041. ExpectIntEQ(wc_curve448_init(&key), 0);
  22042. ExpectIntEQ(wc_InitRng(&rng), 0);
  22043. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22044. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22045. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  22046. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22047. wc_curve448_free(&key);
  22048. #endif
  22049. return EXPECT_RESULT();
  22050. } /* END test_wc_curve448_import*/
  22051. /*
  22052. * Testing test_wc_curve448_size.
  22053. */
  22054. static int test_wc_curve448_size(void)
  22055. {
  22056. EXPECT_DECLS;
  22057. #if defined(HAVE_CURVE448)
  22058. curve448_key key;
  22059. ExpectIntEQ(wc_curve448_init(&key), 0);
  22060. /* Test good args for wc_curve448_size */
  22061. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22062. /* Test bad args for wc_curve448_size */
  22063. ExpectIntEQ(wc_curve448_size(NULL), 0);
  22064. wc_curve448_free(&key);
  22065. #endif
  22066. return EXPECT_RESULT();
  22067. } /* END test_wc_curve448_size*/
  22068. /*
  22069. * Testing wc_ecc_make_key.
  22070. */
  22071. static int test_wc_ecc_make_key(void)
  22072. {
  22073. EXPECT_DECLS;
  22074. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22075. ecc_key key;
  22076. WC_RNG rng;
  22077. int ret;
  22078. XMEMSET(&key, 0, sizeof(ecc_key));
  22079. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22080. ExpectIntEQ(wc_ecc_init(&key), 0);
  22081. ExpectIntEQ(wc_InitRng(&rng), 0);
  22082. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22083. #if defined(WOLFSSL_ASYNC_CRYPT)
  22084. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22085. #endif
  22086. ExpectIntEQ(ret, 0);
  22087. /* Pass in bad args. */
  22088. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22089. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22090. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22091. wc_ecc_free(&key);
  22092. #ifdef FP_ECC
  22093. wc_ecc_fp_free();
  22094. #endif
  22095. #endif
  22096. return EXPECT_RESULT();
  22097. } /* END test_wc_ecc_make_key */
  22098. /*
  22099. * Testing wc_ecc_init()
  22100. */
  22101. static int test_wc_ecc_init(void)
  22102. {
  22103. EXPECT_DECLS;
  22104. #ifdef HAVE_ECC
  22105. ecc_key key;
  22106. XMEMSET(&key, 0, sizeof(ecc_key));
  22107. ExpectIntEQ(wc_ecc_init(&key), 0);
  22108. /* Pass in bad args. */
  22109. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22110. wc_ecc_free(&key);
  22111. #endif
  22112. return EXPECT_RESULT();
  22113. } /* END test_wc_ecc_init */
  22114. /*
  22115. * Testing wc_ecc_check_key()
  22116. */
  22117. static int test_wc_ecc_check_key(void)
  22118. {
  22119. EXPECT_DECLS;
  22120. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22121. ecc_key key;
  22122. WC_RNG rng;
  22123. int ret;
  22124. XMEMSET(&rng, 0, sizeof(rng));
  22125. XMEMSET(&key, 0, sizeof(key));
  22126. ExpectIntEQ(wc_ecc_init(&key), 0);
  22127. ExpectIntEQ(wc_InitRng(&rng), 0);
  22128. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22129. #if defined(WOLFSSL_ASYNC_CRYPT)
  22130. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22131. #endif
  22132. ExpectIntEQ(ret, 0);
  22133. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  22134. /* Pass in bad args. */
  22135. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22136. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22137. wc_ecc_free(&key);
  22138. #ifdef FP_ECC
  22139. wc_ecc_fp_free();
  22140. #endif
  22141. #endif
  22142. return EXPECT_RESULT();
  22143. } /* END test_wc_ecc_check_key */
  22144. /*
  22145. * Testing wc_ecc_get_generator()
  22146. */
  22147. static int test_wc_ecc_get_generator(void)
  22148. {
  22149. EXPECT_DECLS;
  22150. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  22151. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  22152. ecc_point* pt = NULL;
  22153. ExpectNotNull(pt = wc_ecc_new_point());
  22154. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22155. MP_OKAY);
  22156. /* Test bad args. */
  22157. /* Returns Zero for bad arg. */
  22158. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  22159. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22160. MP_OKAY);
  22161. /* If we ever get to 1000 curves increase this number */
  22162. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  22163. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  22164. wc_ecc_del_point(pt);
  22165. #endif
  22166. return EXPECT_RESULT();
  22167. } /* END test_wc_ecc_get_generator */
  22168. /*
  22169. * Testing wc_ecc_size()
  22170. */
  22171. static int test_wc_ecc_size(void)
  22172. {
  22173. EXPECT_DECLS;
  22174. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22175. WC_RNG rng;
  22176. ecc_key key;
  22177. int ret;
  22178. XMEMSET(&key, 0, sizeof(ecc_key));
  22179. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22180. ExpectIntEQ(wc_ecc_init(&key), 0);
  22181. ExpectIntEQ(wc_InitRng(&rng), 0);
  22182. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22183. #if defined(WOLFSSL_ASYNC_CRYPT)
  22184. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22185. #endif
  22186. ExpectIntEQ(ret, 0);
  22187. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  22188. /* Test bad args. */
  22189. /* Returns Zero for bad arg. */
  22190. ExpectIntEQ(wc_ecc_size(NULL), 0);
  22191. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22192. wc_ecc_free(&key);
  22193. #endif
  22194. return EXPECT_RESULT();
  22195. } /* END test_wc_ecc_size */
  22196. static int test_wc_ecc_params(void)
  22197. {
  22198. EXPECT_DECLS;
  22199. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  22200. It was added after certifications */
  22201. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  22202. const ecc_set_type* ecc_set;
  22203. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  22204. /* Test for SECP256R1 curve */
  22205. int curve_id = ECC_SECP256R1;
  22206. int curve_idx;
  22207. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  22208. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  22209. ExpectIntEQ(ecc_set->id, curve_id);
  22210. #endif
  22211. /* Test case when SECP256R1 is not enabled */
  22212. /* Test that we get curve params for index 0 */
  22213. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  22214. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  22215. return EXPECT_RESULT();
  22216. }
  22217. /*
  22218. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22219. */
  22220. static int test_wc_ecc_signVerify_hash(void)
  22221. {
  22222. EXPECT_DECLS;
  22223. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22224. ecc_key key;
  22225. WC_RNG rng;
  22226. int ret;
  22227. #ifdef HAVE_ECC_VERIFY
  22228. int verify = 0;
  22229. #endif
  22230. word32 siglen = ECC_BUFSIZE;
  22231. byte sig[ECC_BUFSIZE];
  22232. byte adjustedSig[ECC_BUFSIZE+1];
  22233. byte digest[] = TEST_STRING;
  22234. word32 digestlen = (word32)TEST_STRING_SZ;
  22235. /* Init stack var */
  22236. XMEMSET(&key, 0, sizeof(ecc_key));
  22237. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22238. XMEMSET(sig, 0, siglen);
  22239. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22240. /* Init structs. */
  22241. ExpectIntEQ(wc_ecc_init(&key), 0);
  22242. ExpectIntEQ(wc_InitRng(&rng), 0);
  22243. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22244. #if defined(WOLFSSL_ASYNC_CRYPT)
  22245. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22246. #endif
  22247. ExpectIntEQ(ret, 0);
  22248. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22249. 0);
  22250. /* Check bad args. */
  22251. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22252. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22253. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22254. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22255. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22256. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22257. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22258. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22259. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22260. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22261. #ifdef HAVE_ECC_VERIFY
  22262. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22263. &key), 0);
  22264. ExpectIntEQ(verify, 1);
  22265. /* test check on length of signature passed in */
  22266. XMEMCPY(adjustedSig, sig, siglen);
  22267. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22268. #ifndef NO_STRICT_ECDSA_LEN
  22269. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22270. &verify, &key), 0);
  22271. #else
  22272. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22273. * is allowed */
  22274. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22275. &verify, &key), 0);
  22276. #endif
  22277. /* Test bad args. */
  22278. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22279. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22280. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22281. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22282. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22283. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22284. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22285. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22286. #endif /* HAVE_ECC_VERIFY */
  22287. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22288. wc_ecc_free(&key);
  22289. #ifdef FP_ECC
  22290. wc_ecc_fp_free();
  22291. #endif
  22292. #endif
  22293. return EXPECT_RESULT();
  22294. } /* END test_wc_ecc_sign_hash */
  22295. /*
  22296. * Testing wc_ecc_shared_secret()
  22297. */
  22298. static int test_wc_ecc_shared_secret(void)
  22299. {
  22300. EXPECT_DECLS;
  22301. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22302. ecc_key key;
  22303. ecc_key pubKey;
  22304. WC_RNG rng;
  22305. #if defined(NO_ECC256)
  22306. int ret;
  22307. #endif
  22308. byte out[KEY32];
  22309. int keySz = sizeof(out);
  22310. word32 outlen = (word32)sizeof(out);
  22311. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22312. const char* qx =
  22313. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22314. const char* qy =
  22315. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22316. const char* d =
  22317. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22318. const char* curveName = "SECP256R1";
  22319. const byte expected_shared_secret[] =
  22320. {
  22321. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22322. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22323. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22324. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22325. };
  22326. #endif
  22327. PRIVATE_KEY_UNLOCK();
  22328. /* Initialize variables. */
  22329. XMEMSET(&key, 0, sizeof(ecc_key));
  22330. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22331. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22332. XMEMSET(out, 0, keySz);
  22333. ExpectIntEQ(wc_ecc_init(&key), 0);
  22334. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22335. ExpectIntEQ(wc_InitRng(&rng), 0);
  22336. #if !defined(NO_ECC256)
  22337. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22338. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22339. #else
  22340. ret = wc_ecc_make_key(&rng, keySz, &key);
  22341. #if defined(WOLFSSL_ASYNC_CRYPT)
  22342. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22343. #endif
  22344. ExpectIntEQ(ret, 0);
  22345. ret = wc_ecc_make_key(&rng, keySz, &key);
  22346. #if defined(WOLFSSL_ASYNC_CRYPT)
  22347. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22348. #endif
  22349. ExpectIntEQ(ret, 0);
  22350. #endif
  22351. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22352. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22353. !defined(HAVE_SELFTEST)
  22354. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22355. #endif
  22356. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22357. #if !defined(NO_ECC256)
  22358. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22359. #endif
  22360. /* Test bad args. */
  22361. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22363. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22364. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22365. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22366. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22367. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22368. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22369. /* Invalid length */
  22370. outlen = 1;
  22371. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22372. WC_NO_ERR_TRACE(BUFFER_E));
  22373. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22374. wc_ecc_free(&pubKey);
  22375. wc_ecc_free(&key);
  22376. #ifdef FP_ECC
  22377. wc_ecc_fp_free();
  22378. #endif
  22379. PRIVATE_KEY_LOCK();
  22380. #endif
  22381. return EXPECT_RESULT();
  22382. } /* END tests_wc_ecc_shared_secret */
  22383. /*
  22384. * testint wc_ecc_export_x963()
  22385. */
  22386. static int test_wc_ecc_export_x963(void)
  22387. {
  22388. EXPECT_DECLS;
  22389. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22390. ecc_key key;
  22391. WC_RNG rng;
  22392. byte out[ECC_ASN963_MAX_BUF_SZ];
  22393. word32 outlen = sizeof(out);
  22394. int ret;
  22395. PRIVATE_KEY_UNLOCK();
  22396. /* Initialize variables. */
  22397. XMEMSET(&key, 0, sizeof(ecc_key));
  22398. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22399. XMEMSET(out, 0, outlen);
  22400. ExpectIntEQ(wc_ecc_init(&key), 0);
  22401. ExpectIntEQ(wc_InitRng(&rng), 0);
  22402. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22403. #if defined(WOLFSSL_ASYNC_CRYPT)
  22404. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22405. #endif
  22406. ExpectIntEQ(ret, 0);
  22407. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22408. /* Test bad args. */
  22409. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22410. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22411. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22412. key.idx = -4;
  22413. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22414. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22415. wc_ecc_free(&key);
  22416. #ifdef FP_ECC
  22417. wc_ecc_fp_free();
  22418. #endif
  22419. PRIVATE_KEY_LOCK();
  22420. #endif
  22421. return EXPECT_RESULT();
  22422. } /* END test_wc_ecc_export_x963 */
  22423. /*
  22424. * Testing wc_ecc_export_x963_ex()
  22425. * compile with --enable-compkey will use compression.
  22426. */
  22427. static int test_wc_ecc_export_x963_ex(void)
  22428. {
  22429. EXPECT_DECLS;
  22430. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22431. ecc_key key;
  22432. WC_RNG rng;
  22433. int ret;
  22434. byte out[ECC_ASN963_MAX_BUF_SZ];
  22435. word32 outlen = sizeof(out);
  22436. #ifdef HAVE_COMP_KEY
  22437. word32 badOutLen = 5;
  22438. #endif
  22439. /* Init stack variables. */
  22440. XMEMSET(&key, 0, sizeof(ecc_key));
  22441. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22442. XMEMSET(out, 0, outlen);
  22443. PRIVATE_KEY_UNLOCK();
  22444. ExpectIntEQ(wc_ecc_init(&key), 0);
  22445. ExpectIntEQ(wc_InitRng(&rng), 0);
  22446. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22447. #if defined(WOLFSSL_ASYNC_CRYPT)
  22448. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22449. #endif
  22450. ExpectIntEQ(ret, 0);
  22451. #ifdef HAVE_COMP_KEY
  22452. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22453. #else
  22454. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22455. #endif
  22456. /* Test bad args. */
  22457. #ifdef HAVE_COMP_KEY
  22458. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22459. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22460. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22461. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22462. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22463. #else
  22464. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22465. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22466. #endif
  22467. key.idx = -4;
  22468. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22469. #else
  22470. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22471. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22472. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22473. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22474. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22475. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22476. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22477. key.idx = -4;
  22478. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22479. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22480. #endif
  22481. PRIVATE_KEY_LOCK();
  22482. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22483. wc_ecc_free(&key);
  22484. #ifdef FP_ECC
  22485. wc_ecc_fp_free();
  22486. #endif
  22487. #endif
  22488. return EXPECT_RESULT();
  22489. } /* END test_wc_ecc_export_x963_ex */
  22490. /*
  22491. * testing wc_ecc_import_x963()
  22492. */
  22493. static int test_wc_ecc_import_x963(void)
  22494. {
  22495. EXPECT_DECLS;
  22496. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22497. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22498. ecc_key pubKey;
  22499. ecc_key key;
  22500. WC_RNG rng;
  22501. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22502. word32 x963Len = (word32)sizeof(x963);
  22503. int ret;
  22504. /* Init stack variables. */
  22505. XMEMSET(&key, 0, sizeof(ecc_key));
  22506. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22507. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22508. XMEMSET(x963, 0, x963Len);
  22509. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22510. ExpectIntEQ(wc_ecc_init(&key), 0);
  22511. ExpectIntEQ(wc_InitRng(&rng), 0);
  22512. #if FIPS_VERSION3_GE(6,0,0)
  22513. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22514. #else
  22515. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22516. #endif
  22517. #if defined(WOLFSSL_ASYNC_CRYPT)
  22518. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22519. #endif
  22520. ExpectIntEQ(ret, 0);
  22521. PRIVATE_KEY_UNLOCK();
  22522. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22523. PRIVATE_KEY_LOCK();
  22524. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22525. /* Test bad args. */
  22526. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22527. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22528. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22529. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22530. wc_ecc_free(&key);
  22531. wc_ecc_free(&pubKey);
  22532. #ifdef FP_ECC
  22533. wc_ecc_fp_free();
  22534. #endif
  22535. #endif
  22536. return EXPECT_RESULT();
  22537. } /* END wc_ecc_import_x963 */
  22538. /*
  22539. * testing wc_ecc_import_private_key()
  22540. */
  22541. static int test_wc_ecc_import_private_key(void)
  22542. {
  22543. EXPECT_DECLS;
  22544. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22545. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22546. ecc_key key;
  22547. ecc_key keyImp;
  22548. WC_RNG rng;
  22549. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22550. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22551. word32 privKeySz = (word32)sizeof(privKey);
  22552. word32 x963KeySz = (word32)sizeof(x963Key);
  22553. int ret;
  22554. /* Init stack variables. */
  22555. XMEMSET(&key, 0, sizeof(ecc_key));
  22556. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22557. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22558. XMEMSET(privKey, 0, privKeySz);
  22559. XMEMSET(x963Key, 0, x963KeySz);
  22560. PRIVATE_KEY_UNLOCK();
  22561. ExpectIntEQ(wc_ecc_init(&key), 0);
  22562. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22563. ExpectIntEQ(wc_InitRng(&rng), 0);
  22564. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22565. #if defined(WOLFSSL_ASYNC_CRYPT)
  22566. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22567. #endif
  22568. ExpectIntEQ(ret, 0);
  22569. PRIVATE_KEY_UNLOCK();
  22570. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22571. PRIVATE_KEY_LOCK();
  22572. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22573. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22574. x963KeySz, &keyImp), 0);
  22575. /* Pass in bad args. */
  22576. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22577. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22578. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22579. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22580. PRIVATE_KEY_LOCK();
  22581. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22582. wc_ecc_free(&keyImp);
  22583. wc_ecc_free(&key);
  22584. #ifdef FP_ECC
  22585. wc_ecc_fp_free();
  22586. #endif
  22587. #endif
  22588. return EXPECT_RESULT();
  22589. } /* END test_wc_ecc_import_private_key */
  22590. /*
  22591. * Testing wc_ecc_export_private_only()
  22592. */
  22593. static int test_wc_ecc_export_private_only(void)
  22594. {
  22595. EXPECT_DECLS;
  22596. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22597. ecc_key key;
  22598. WC_RNG rng;
  22599. byte out[ECC_PRIV_KEY_BUF];
  22600. word32 outlen = sizeof(out);
  22601. int ret;
  22602. /* Init stack variables. */
  22603. XMEMSET(&key, 0, sizeof(ecc_key));
  22604. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22605. XMEMSET(out, 0, outlen);
  22606. PRIVATE_KEY_UNLOCK();
  22607. ExpectIntEQ(wc_ecc_init(&key), 0);
  22608. ExpectIntEQ(wc_InitRng(&rng), 0);
  22609. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22610. #if defined(WOLFSSL_ASYNC_CRYPT)
  22611. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22612. #endif
  22613. ExpectIntEQ(ret, 0);
  22614. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22615. /* Pass in bad args. */
  22616. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22617. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22618. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22619. PRIVATE_KEY_LOCK();
  22620. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22621. wc_ecc_free(&key);
  22622. #ifdef FP_ECC
  22623. wc_ecc_fp_free();
  22624. #endif
  22625. #endif
  22626. return EXPECT_RESULT();
  22627. } /* END test_wc_ecc_export_private_only */
  22628. /*
  22629. * Testing wc_ecc_rs_to_sig()
  22630. */
  22631. static int test_wc_ecc_rs_to_sig(void)
  22632. {
  22633. EXPECT_DECLS;
  22634. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22635. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22636. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22637. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  22638. const char* zeroStr = "0";
  22639. byte sig[ECC_MAX_SIG_SIZE];
  22640. word32 siglen = (word32)sizeof(sig);
  22641. /* R and S max size is the order of curve. 2^192.*/
  22642. int keySz = KEY24;
  22643. byte r[KEY24];
  22644. byte s[KEY24];
  22645. word32 rlen = (word32)sizeof(r);
  22646. word32 slen = (word32)sizeof(s);
  22647. /* Init stack variables. */
  22648. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  22649. XMEMSET(r, 0, keySz);
  22650. XMEMSET(s, 0, keySz);
  22651. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  22652. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  22653. /* Test bad args. */
  22654. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22655. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22656. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22657. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22658. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22659. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22660. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  22661. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22662. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  22663. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22664. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  22665. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22666. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  22667. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22668. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  22669. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22670. #endif
  22671. return EXPECT_RESULT();
  22672. } /* END test_wc_ecc_rs_to_sig */
  22673. static int test_wc_ecc_import_raw(void)
  22674. {
  22675. EXPECT_DECLS;
  22676. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22677. ecc_key key;
  22678. const char* qx =
  22679. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22680. const char* qy =
  22681. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22682. const char* d =
  22683. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22684. const char* curveName = "SECP256R1";
  22685. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22686. const char* kNullStr = "";
  22687. int ret;
  22688. #endif
  22689. XMEMSET(&key, 0, sizeof(ecc_key));
  22690. ExpectIntEQ(wc_ecc_init(&key), 0);
  22691. /* Test good import */
  22692. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22693. /* Test bad args. */
  22694. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22695. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22696. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22697. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22698. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22699. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22700. wc_ecc_free(&key);
  22701. #endif
  22702. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  22703. curveName), 0);
  22704. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22705. #endif
  22706. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  22707. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22708. wc_ecc_free(&key);
  22709. #endif
  22710. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22711. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22712. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22713. #else
  22714. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22715. #endif
  22716. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22717. wc_ecc_free(&key);
  22718. #endif
  22719. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22720. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22721. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22722. #else
  22723. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22724. #endif
  22725. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22726. wc_ecc_free(&key);
  22727. #endif
  22728. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  22729. #endif
  22730. wc_ecc_free(&key);
  22731. #endif
  22732. return EXPECT_RESULT();
  22733. } /* END test_wc_ecc_import_raw */
  22734. static int test_wc_ecc_import_unsigned(void)
  22735. {
  22736. EXPECT_DECLS;
  22737. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  22738. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  22739. HAVE_FIPS_VERSION >= 2))
  22740. ecc_key key;
  22741. const byte qx[] = {
  22742. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  22743. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  22744. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  22745. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  22746. };
  22747. const byte qy[] = {
  22748. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  22749. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  22750. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  22751. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  22752. };
  22753. const byte d[] = {
  22754. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  22755. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  22756. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  22757. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  22758. };
  22759. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22760. const byte nullBytes[32] = {0};
  22761. int ret;
  22762. #endif
  22763. int curveId = ECC_SECP256R1;
  22764. XMEMSET(&key, 0, sizeof(ecc_key));
  22765. ExpectIntEQ(wc_ecc_init(&key), 0);
  22766. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22767. curveId), 0);
  22768. /* Test bad args. */
  22769. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  22770. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22771. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  22772. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22773. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  22774. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22775. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22776. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22777. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22778. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  22779. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  22780. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22781. #endif
  22782. wc_ecc_free(&key);
  22783. #endif
  22784. return EXPECT_RESULT();
  22785. } /* END test_wc_ecc_import_unsigned */
  22786. /*
  22787. * Testing wc_ecc_sig_size()
  22788. */
  22789. static int test_wc_ecc_sig_size(void)
  22790. {
  22791. EXPECT_DECLS;
  22792. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22793. ecc_key key;
  22794. WC_RNG rng;
  22795. int keySz = KEY16;
  22796. int ret;
  22797. XMEMSET(&rng, 0, sizeof(rng));
  22798. XMEMSET(&key, 0, sizeof(key));
  22799. ExpectIntEQ(wc_ecc_init(&key), 0);
  22800. ExpectIntEQ(wc_InitRng(&rng), 0);
  22801. ret = wc_ecc_make_key(&rng, keySz, &key);
  22802. #if defined(WOLFSSL_ASYNC_CRYPT)
  22803. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22804. #endif
  22805. ExpectIntEQ(ret, 0);
  22806. ExpectIntLE(wc_ecc_sig_size(&key),
  22807. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  22808. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22809. wc_ecc_free(&key);
  22810. #endif
  22811. return EXPECT_RESULT();
  22812. } /* END test_wc_ecc_sig_size */
  22813. /*
  22814. * Testing wc_ecc_ctx_new()
  22815. */
  22816. static int test_wc_ecc_ctx_new(void)
  22817. {
  22818. EXPECT_DECLS;
  22819. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22820. WC_RNG rng;
  22821. ecEncCtx* cli = NULL;
  22822. ecEncCtx* srv = NULL;
  22823. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22824. ExpectIntEQ(wc_InitRng(&rng), 0);
  22825. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22826. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  22827. wc_ecc_ctx_free(cli);
  22828. cli = NULL;
  22829. wc_ecc_ctx_free(srv);
  22830. /* Test bad args. */
  22831. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  22832. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  22833. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  22834. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22835. wc_ecc_ctx_free(cli);
  22836. #endif
  22837. return EXPECT_RESULT();
  22838. } /* END test_wc_ecc_ctx_new */
  22839. /*
  22840. * Tesing wc_ecc_reset()
  22841. */
  22842. static int test_wc_ecc_ctx_reset(void)
  22843. {
  22844. EXPECT_DECLS;
  22845. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22846. ecEncCtx* ctx = NULL;
  22847. WC_RNG rng;
  22848. XMEMSET(&rng, 0, sizeof(rng));
  22849. ExpectIntEQ(wc_InitRng(&rng), 0);
  22850. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22851. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  22852. /* Pass in bad args. */
  22853. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22854. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22855. wc_ecc_ctx_free(ctx);
  22856. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22857. #endif
  22858. return EXPECT_RESULT();
  22859. } /* END test_wc_ecc_ctx_reset */
  22860. /*
  22861. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  22862. */
  22863. static int test_wc_ecc_ctx_set_peer_salt(void)
  22864. {
  22865. EXPECT_DECLS;
  22866. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22867. WC_RNG rng;
  22868. ecEncCtx* cliCtx = NULL;
  22869. ecEncCtx* servCtx = NULL;
  22870. const byte* cliSalt = NULL;
  22871. const byte* servSalt = NULL;
  22872. XMEMSET(&rng, 0, sizeof(rng));
  22873. ExpectIntEQ(wc_InitRng(&rng), 0);
  22874. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22875. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  22876. /* Test bad args. */
  22877. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  22878. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  22879. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  22880. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  22881. /* Test bad args. */
  22882. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22883. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22884. wc_ecc_ctx_free(cliCtx);
  22885. wc_ecc_ctx_free(servCtx);
  22886. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22887. #endif
  22888. return EXPECT_RESULT();
  22889. } /* END test_wc_ecc_ctx_set_peer_salt */
  22890. /*
  22891. * Testing wc_ecc_ctx_set_info()
  22892. */
  22893. static int test_wc_ecc_ctx_set_info(void)
  22894. {
  22895. EXPECT_DECLS;
  22896. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  22897. ecEncCtx* ctx = NULL;
  22898. WC_RNG rng;
  22899. const char* optInfo = "Optional Test Info.";
  22900. int optInfoSz = (int)XSTRLEN(optInfo);
  22901. const char* badOptInfo = NULL;
  22902. XMEMSET(&rng, 0, sizeof(rng));
  22903. ExpectIntEQ(wc_InitRng(&rng), 0);
  22904. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  22905. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  22906. /* Test bad args. */
  22907. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  22908. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22909. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  22910. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22911. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22912. wc_ecc_ctx_free(ctx);
  22913. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22914. #endif
  22915. return EXPECT_RESULT();
  22916. } /* END test_wc_ecc_ctx_set_info */
  22917. /*
  22918. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  22919. */
  22920. static int test_wc_ecc_encryptDecrypt(void)
  22921. {
  22922. EXPECT_DECLS;
  22923. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  22924. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22925. ecc_key srvKey;
  22926. ecc_key cliKey;
  22927. ecc_key tmpKey;
  22928. WC_RNG rng;
  22929. int ret;
  22930. const char* msg = "EccBlock Size 16";
  22931. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  22932. #ifdef WOLFSSL_ECIES_OLD
  22933. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  22934. #elif defined(WOLFSSL_ECIES_GEN_IV)
  22935. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  22936. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  22937. #else
  22938. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  22939. WC_SHA256_DIGEST_SIZE];
  22940. #endif
  22941. word32 outSz = (word32)sizeof(out);
  22942. byte plain[sizeof("EccBlock Size 16")];
  22943. word32 plainSz = (word32)sizeof(plain);
  22944. int keySz = KEY20;
  22945. /* Init stack variables. */
  22946. XMEMSET(out, 0, outSz);
  22947. XMEMSET(plain, 0, plainSz);
  22948. XMEMSET(&rng, 0, sizeof(rng));
  22949. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  22950. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  22951. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  22952. ExpectIntEQ(wc_InitRng(&rng), 0);
  22953. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  22954. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  22955. #if defined(WOLFSSL_ASYNC_CRYPT)
  22956. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  22957. #endif
  22958. ExpectIntEQ(ret, 0);
  22959. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  22960. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  22961. #if defined(WOLFSSL_ASYNC_CRYPT)
  22962. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  22963. #endif
  22964. ExpectIntEQ(ret, 0);
  22965. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  22966. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22967. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22968. !defined(HAVE_SELFTEST)
  22969. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  22970. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  22971. #endif
  22972. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  22973. &outSz, NULL), 0);
  22974. /* Test bad args. */
  22975. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  22976. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22977. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  22978. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22979. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  22980. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22981. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  22982. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22983. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  22984. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22985. #ifdef WOLFSSL_ECIES_OLD
  22986. tmpKey.dp = cliKey.dp;
  22987. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  22988. #endif
  22989. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  22990. NULL), 0);
  22991. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  22992. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22993. #ifdef WOLFSSL_ECIES_OLD
  22994. /* NULL parameter allowed in new implementations - public key comes from
  22995. * the message. */
  22996. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  22997. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22998. #endif
  22999. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  23000. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23001. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  23002. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23003. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  23004. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23005. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  23006. wc_ecc_free(&tmpKey);
  23007. wc_ecc_free(&srvKey);
  23008. wc_ecc_free(&cliKey);
  23009. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23010. #endif
  23011. return EXPECT_RESULT();
  23012. } /* END test_wc_ecc_encryptDecrypt */
  23013. /*
  23014. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  23015. */
  23016. static int test_wc_ecc_del_point(void)
  23017. {
  23018. EXPECT_DECLS;
  23019. #if defined(HAVE_ECC)
  23020. ecc_point* pt = NULL;
  23021. ExpectNotNull(pt = wc_ecc_new_point());
  23022. wc_ecc_del_point(pt);
  23023. #endif
  23024. return EXPECT_RESULT();
  23025. } /* END test_wc_ecc_del_point */
  23026. /*
  23027. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  23028. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  23029. * and wc_ecc_cmp_point()
  23030. */
  23031. static int test_wc_ecc_pointFns(void)
  23032. {
  23033. EXPECT_DECLS;
  23034. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  23035. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23036. !defined(WOLFSSL_ATECC608A)
  23037. ecc_key key;
  23038. WC_RNG rng;
  23039. int ret;
  23040. ecc_point* point = NULL;
  23041. ecc_point* cpypt = NULL;
  23042. int idx = 0;
  23043. int keySz = KEY32;
  23044. byte der[DER_SZ(KEY32)];
  23045. word32 derlenChk = 0;
  23046. word32 derSz = DER_SZ(KEY32);
  23047. /* Init stack variables. */
  23048. XMEMSET(der, 0, derSz);
  23049. XMEMSET(&key, 0, sizeof(ecc_key));
  23050. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23051. ExpectIntEQ(wc_InitRng(&rng), 0);
  23052. ExpectIntEQ(wc_ecc_init(&key), 0);
  23053. ret = wc_ecc_make_key(&rng, keySz, &key);
  23054. #if defined(WOLFSSL_ASYNC_CRYPT)
  23055. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23056. #endif
  23057. ExpectIntEQ(ret, 0);
  23058. ExpectNotNull(point = wc_ecc_new_point());
  23059. ExpectNotNull(cpypt = wc_ecc_new_point());
  23060. /* Export */
  23061. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  23062. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23063. /* Check length value. */
  23064. ExpectIntEQ(derSz, derlenChk);
  23065. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23066. &derSz), 0);
  23067. /* Test bad args. */
  23068. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  23069. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23070. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  23071. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23072. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23073. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23074. /* Import */
  23075. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  23076. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  23077. /* Test bad args. */
  23078. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  23079. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23080. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23081. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23082. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  23083. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23084. /* Copy */
  23085. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  23086. /* Test bad args. */
  23087. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23088. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23089. /* Compare point */
  23090. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  23091. /* Test bad args. */
  23092. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23093. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23094. /* At infinity if return == 1, otherwise return == 0. */
  23095. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  23096. /* Test bad args. */
  23097. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23098. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  23099. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  23100. #ifdef USE_ECC_B_PARAM
  23101. /* On curve if ret == 0 */
  23102. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  23103. /* Test bad args. */
  23104. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23105. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23106. #endif /* USE_ECC_B_PARAM */
  23107. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  23108. /* Free */
  23109. wc_ecc_del_point(point);
  23110. wc_ecc_del_point(cpypt);
  23111. wc_ecc_free(&key);
  23112. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23113. #endif
  23114. return EXPECT_RESULT();
  23115. } /* END test_wc_ecc_pointFns */
  23116. /*
  23117. * Testing wc_ecc_shared_secret_ssh()
  23118. */
  23119. static int test_wc_ecc_shared_secret_ssh(void)
  23120. {
  23121. EXPECT_DECLS;
  23122. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  23123. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23124. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  23125. !defined(WOLFSSL_CRYPTOCELL)
  23126. ecc_key key;
  23127. ecc_key key2;
  23128. WC_RNG rng;
  23129. int ret;
  23130. int keySz = KEY32;
  23131. #if FIPS_VERSION3_GE(6,0,0)
  23132. int key2Sz = KEY28;
  23133. #else
  23134. int key2Sz = KEY24;
  23135. #endif
  23136. byte secret[KEY32];
  23137. word32 secretLen = (word32)keySz;
  23138. /* Init stack variables. */
  23139. XMEMSET(&key, 0, sizeof(ecc_key));
  23140. XMEMSET(&key2, 0, sizeof(ecc_key));
  23141. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23142. XMEMSET(secret, 0, secretLen);
  23143. PRIVATE_KEY_UNLOCK();
  23144. /* Make keys */
  23145. ExpectIntEQ(wc_ecc_init(&key), 0);
  23146. ExpectIntEQ(wc_InitRng(&rng), 0);
  23147. ret = wc_ecc_make_key(&rng, keySz, &key);
  23148. #if defined(WOLFSSL_ASYNC_CRYPT)
  23149. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23150. #endif
  23151. ExpectIntEQ(ret, 0);
  23152. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23153. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23154. ExpectIntEQ(wc_InitRng(&rng), 0);
  23155. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  23156. #if defined(WOLFSSL_ASYNC_CRYPT)
  23157. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  23158. #endif
  23159. ExpectIntEQ(ret, 0);
  23160. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23161. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23162. !defined(HAVE_SELFTEST)
  23163. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  23164. #endif
  23165. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23166. &secretLen), 0);
  23167. /* Pass in bad args. */
  23168. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  23169. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23170. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  23171. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23172. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  23173. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23174. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  23175. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23176. key.type = ECC_PUBLICKEY;
  23177. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23178. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23179. PRIVATE_KEY_LOCK();
  23180. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23181. wc_ecc_free(&key);
  23182. wc_ecc_free(&key2);
  23183. #ifdef FP_ECC
  23184. wc_ecc_fp_free();
  23185. #endif
  23186. #endif
  23187. return EXPECT_RESULT();
  23188. } /* END test_wc_ecc_shared_secret_ssh */
  23189. /*
  23190. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  23191. */
  23192. static int test_wc_ecc_verify_hash_ex(void)
  23193. {
  23194. EXPECT_DECLS;
  23195. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  23196. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23197. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  23198. ecc_key key;
  23199. WC_RNG rng;
  23200. int ret;
  23201. mp_int r;
  23202. mp_int s;
  23203. mp_int z;
  23204. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  23205. unsigned char iHash[] = "Everyone gets Friday off.......";
  23206. unsigned char shortHash[] = TEST_STRING;
  23207. word32 hashlen = sizeof(hash);
  23208. word32 iHashLen = sizeof(iHash);
  23209. word32 shortHashLen = sizeof(shortHash);
  23210. int keySz = KEY32;
  23211. int verify_ok = 0;
  23212. XMEMSET(&key, 0, sizeof(ecc_key));
  23213. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23214. XMEMSET(&r, 0, sizeof(mp_int));
  23215. XMEMSET(&s, 0, sizeof(mp_int));
  23216. XMEMSET(&z, 0, sizeof(mp_int));
  23217. /* Initialize r, s and z. */
  23218. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23219. ExpectIntEQ(wc_ecc_init(&key), 0);
  23220. ExpectIntEQ(wc_InitRng(&rng), 0);
  23221. ret = wc_ecc_make_key(&rng, keySz, &key);
  23222. #if defined(WOLFSSL_ASYNC_CRYPT)
  23223. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23224. #endif
  23225. ExpectIntEQ(ret, 0);
  23226. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23227. /* verify_ok should be 1. */
  23228. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23229. 0);
  23230. ExpectIntEQ(verify_ok, 1);
  23231. /* verify_ok should be 0 */
  23232. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23233. &key), 0);
  23234. ExpectIntEQ(verify_ok, 0);
  23235. /* verify_ok should be 0. */
  23236. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23237. &verify_ok, &key), 0);
  23238. ExpectIntEQ(verify_ok, 0);
  23239. /* Test bad args. */
  23240. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23241. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23242. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23243. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23244. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23245. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23246. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23247. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23248. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23249. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23250. /* Test bad args. */
  23251. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23252. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23253. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23254. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23255. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23256. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23257. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23258. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23259. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23260. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23261. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23262. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23263. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23264. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23265. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23266. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23267. wc_ecc_free(&key);
  23268. mp_free(&r);
  23269. mp_free(&s);
  23270. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23271. #endif
  23272. return EXPECT_RESULT();
  23273. } /* END test_wc_ecc_verify_hash_ex */
  23274. /*
  23275. * Testing wc_ecc_mulmod()
  23276. */
  23277. static int test_wc_ecc_mulmod(void)
  23278. {
  23279. EXPECT_DECLS;
  23280. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23281. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23282. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23283. ecc_key key1;
  23284. ecc_key key2;
  23285. ecc_key key3;
  23286. WC_RNG rng;
  23287. int ret;
  23288. XMEMSET(&key1, 0, sizeof(ecc_key));
  23289. XMEMSET(&key2, 0, sizeof(ecc_key));
  23290. XMEMSET(&key3, 0, sizeof(ecc_key));
  23291. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23292. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23293. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23294. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23295. ExpectIntEQ(wc_InitRng(&rng), 0);
  23296. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23297. #if defined(WOLFSSL_ASYNC_CRYPT)
  23298. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23299. #endif
  23300. ExpectIntEQ(ret, 0);
  23301. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23302. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23303. key1.dp->Af, ECC_SECP256R1), 0);
  23304. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23305. key1.dp->prime, ECC_SECP256R1), 0);
  23306. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23307. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23308. 1), 0);
  23309. /* Test bad args. */
  23310. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23311. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23312. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23313. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23314. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23315. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23316. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23317. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23318. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23319. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23320. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23321. wc_ecc_free(&key1);
  23322. wc_ecc_free(&key2);
  23323. wc_ecc_free(&key3);
  23324. #ifdef FP_ECC
  23325. wc_ecc_fp_free();
  23326. #endif
  23327. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23328. return EXPECT_RESULT();
  23329. } /* END test_wc_ecc_mulmod */
  23330. /*
  23331. * Testing wc_ecc_is_valid_idx()
  23332. */
  23333. static int test_wc_ecc_is_valid_idx(void)
  23334. {
  23335. EXPECT_DECLS;
  23336. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23337. ecc_key key;
  23338. WC_RNG rng;
  23339. int ret;
  23340. int iVal = -2;
  23341. int iVal2 = 3000;
  23342. XMEMSET(&key, 0, sizeof(ecc_key));
  23343. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23344. ExpectIntEQ(wc_ecc_init(&key), 0);
  23345. ExpectIntEQ(wc_InitRng(&rng), 0);
  23346. ret = wc_ecc_make_key(&rng, 32, &key);
  23347. #if defined(WOLFSSL_ASYNC_CRYPT)
  23348. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23349. #endif
  23350. ExpectIntEQ(ret, 0);
  23351. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23352. /* Test bad args. */
  23353. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23354. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23355. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23356. wc_ecc_free(&key);
  23357. #ifdef FP_ECC
  23358. wc_ecc_fp_free();
  23359. #endif
  23360. #endif
  23361. return EXPECT_RESULT();
  23362. } /* END test_wc_ecc_is_valid_idx */
  23363. /*
  23364. * Testing wc_ecc_get_curve_id_from_oid()
  23365. */
  23366. static int test_wc_ecc_get_curve_id_from_oid(void)
  23367. {
  23368. EXPECT_DECLS;
  23369. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23370. !defined(HAVE_FIPS)
  23371. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23372. word32 len = sizeof(oid);
  23373. /* Bad Cases */
  23374. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23375. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23376. /* Good Case */
  23377. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23378. #endif
  23379. return EXPECT_RESULT();
  23380. } /* END test_wc_ecc_get_curve_id_from_oid */
  23381. /*
  23382. * Testing wc_ecc_sig_size_calc()
  23383. */
  23384. static int test_wc_ecc_sig_size_calc(void)
  23385. {
  23386. EXPECT_DECLS;
  23387. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23388. ecc_key key;
  23389. WC_RNG rng;
  23390. int sz = 0;
  23391. int ret;
  23392. XMEMSET(&key, 0, sizeof(ecc_key));
  23393. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23394. ExpectIntEQ(wc_ecc_init(&key), 0);
  23395. ExpectIntEQ(wc_InitRng(&rng), 0);
  23396. ret = wc_ecc_make_key(&rng, 16, &key);
  23397. #if defined(WOLFSSL_ASYNC_CRYPT)
  23398. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23399. #endif
  23400. #if FIPS_VERSION3_GE(6,0,0)
  23401. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23402. #else
  23403. ExpectIntEQ(ret, 0);
  23404. #endif
  23405. #if FIPS_VERSION3_LT(6,0,0)
  23406. sz = key.dp->size;
  23407. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23408. #else
  23409. (void) sz;
  23410. #endif
  23411. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23412. wc_ecc_free(&key);
  23413. #endif
  23414. return EXPECT_RESULT();
  23415. } /* END test_wc_ecc_sig_size_calc */
  23416. /*
  23417. * Testing wc_ecc_sm2_make_key()
  23418. */
  23419. static int test_wc_ecc_sm2_make_key(void)
  23420. {
  23421. int res = TEST_SKIPPED;
  23422. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23423. EXPECT_DECLS;
  23424. WC_RNG rng[1];
  23425. ecc_key key[1];
  23426. XMEMSET(rng, 0, sizeof(*rng));
  23427. XMEMSET(key, 0, sizeof(*key));
  23428. ExpectIntEQ(wc_InitRng(rng), 0);
  23429. ExpectIntEQ(wc_ecc_init(key), 0);
  23430. /* Test invalid parameters. */
  23431. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23432. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23433. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23434. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23435. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23436. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23437. /* Test valid parameters. */
  23438. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23439. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23440. wc_ecc_free(key);
  23441. wc_FreeRng(rng);
  23442. #ifdef FP_ECC
  23443. wc_ecc_fp_free();
  23444. #endif
  23445. res = EXPECT_RESULT();
  23446. #endif
  23447. return res;
  23448. }
  23449. /*
  23450. * Testing wc_ecc_sm2_shared_secret()
  23451. */
  23452. static int test_wc_ecc_sm2_shared_secret(void)
  23453. {
  23454. int res = TEST_SKIPPED;
  23455. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23456. EXPECT_DECLS;
  23457. WC_RNG rng[1];
  23458. ecc_key keyA[1];
  23459. ecc_key keyB[1];
  23460. byte outA[32];
  23461. byte outB[32];
  23462. word32 outALen = 32;
  23463. word32 outBLen = 32;
  23464. XMEMSET(rng, 0, sizeof(*rng));
  23465. XMEMSET(keyA, 0, sizeof(*keyA));
  23466. XMEMSET(keyB, 0, sizeof(*keyB));
  23467. ExpectIntEQ(wc_InitRng(rng), 0);
  23468. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23469. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23470. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23471. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23472. #ifdef ECC_TIMING_RESISTANT
  23473. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23474. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23475. #endif
  23476. /* Test invalid parameters. */
  23477. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23478. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23479. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23480. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23481. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23482. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23483. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23484. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23485. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23486. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23487. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23488. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23489. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23490. /* Test valid parameters. */
  23491. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23492. ExpectIntLE(outALen, 32);
  23493. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23494. ExpectIntLE(outBLen, 32);
  23495. ExpectIntEQ(outALen, outBLen);
  23496. ExpectBufEQ(outA, outB, outALen);
  23497. wc_ecc_free(keyB);
  23498. wc_ecc_free(keyA);
  23499. wc_FreeRng(rng);
  23500. #ifdef FP_ECC
  23501. wc_ecc_fp_free();
  23502. #endif
  23503. res = EXPECT_RESULT();
  23504. #endif
  23505. return res;
  23506. }
  23507. /*
  23508. * Testing wc_ecc_sm2_create_digest()
  23509. */
  23510. static int test_wc_ecc_sm2_create_digest(void)
  23511. {
  23512. int res = TEST_SKIPPED;
  23513. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23514. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23515. EXPECT_DECLS;
  23516. ecc_key key[1];
  23517. enum wc_HashType hashType;
  23518. unsigned char pub[] = {
  23519. 0x04,
  23520. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23521. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23522. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23523. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23524. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23525. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23526. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23527. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23528. };
  23529. unsigned char id[] = {
  23530. 0x01, 0x02, 0x03,
  23531. };
  23532. unsigned char msg[] = {
  23533. 0x01, 0x02, 0x03,
  23534. };
  23535. unsigned char hash[32];
  23536. #ifdef WOLFSSL_SM3
  23537. unsigned char expHash[32] = {
  23538. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23539. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23540. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23541. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23542. };
  23543. #else
  23544. unsigned char expHash[32] = {
  23545. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23546. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23547. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23548. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23549. };
  23550. #endif
  23551. #ifdef WOLFSSL_SM3
  23552. hashType = WC_HASH_TYPE_SM3;
  23553. #else
  23554. hashType = WC_HASH_TYPE_SHA256;
  23555. #endif
  23556. XMEMSET(key, 0, sizeof(*key));
  23557. ExpectIntEQ(wc_ecc_init(key), 0);
  23558. /* Test with no curve set. */
  23559. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23560. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23561. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23562. /* Test invalid parameters. */
  23563. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23564. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23565. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23566. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23567. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23568. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23569. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23570. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23571. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23572. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23573. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23574. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23575. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23576. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23577. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23578. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23579. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23580. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23581. /* Bad hash type. */
  23582. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23583. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23584. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23585. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23586. /* Bad hash size. */
  23587. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23588. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23589. /* Test valid parameters. */
  23590. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23591. hashType, hash, sizeof(hash), key), 0);
  23592. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23593. wc_ecc_free(key);
  23594. res = EXPECT_RESULT();
  23595. #endif
  23596. return res;
  23597. }
  23598. /*
  23599. * Testing wc_ecc_sm2_verify_hash_ex()
  23600. */
  23601. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23602. {
  23603. int res = TEST_SKIPPED;
  23604. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23605. defined(WOLFSSL_PUBLIC_MP)
  23606. EXPECT_DECLS;
  23607. ecc_key key[1];
  23608. mp_int r[1];
  23609. mp_int s[1];
  23610. int verified;
  23611. unsigned char pub[] = {
  23612. 0x04,
  23613. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23614. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23615. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23616. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23617. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23618. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23619. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23620. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23621. };
  23622. unsigned char hash[] = {
  23623. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23624. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23625. 0x50, 0x69, 0x5B, 0x20
  23626. };
  23627. unsigned char rData[] = {
  23628. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23629. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23630. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23631. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23632. };
  23633. unsigned char sData[] = {
  23634. 0x1D,
  23635. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23636. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23637. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23638. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23639. };
  23640. unsigned char rBadData[] = {
  23641. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23642. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23643. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23644. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  23645. };
  23646. XMEMSET(key, 0, sizeof(*key));
  23647. XMEMSET(r, 0, sizeof(*r));
  23648. XMEMSET(s, 0, sizeof(*s));
  23649. ExpectIntEQ(mp_init(r), 0);
  23650. ExpectIntEQ(mp_init(s), 0);
  23651. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  23652. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  23653. ExpectIntEQ(wc_ecc_init(key), 0);
  23654. /* Test with no curve set. */
  23655. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23656. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23657. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23658. /* Test invalid parameters. */
  23659. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23660. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23661. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  23662. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23663. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  23664. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23665. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  23666. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23667. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23668. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23669. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23670. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23671. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  23672. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23673. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  23674. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23675. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  23676. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23677. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23678. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23679. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23680. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23681. /* Make key not on the SM2 curve. */
  23682. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23683. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23684. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23685. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23686. /* Test valid parameters. */
  23687. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23688. &verified, key), 0);
  23689. ExpectIntEQ(verified, 1);
  23690. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  23691. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23692. &verified, key), 0);
  23693. ExpectIntEQ(verified, 0);
  23694. mp_free(s);
  23695. mp_free(r);
  23696. wc_ecc_free(key);
  23697. #ifdef FP_ECC
  23698. wc_ecc_fp_free();
  23699. #endif
  23700. res = EXPECT_RESULT();
  23701. #endif
  23702. return res;
  23703. }
  23704. /*
  23705. * Testing wc_ecc_sm2_verify_hash()
  23706. */
  23707. static int test_wc_ecc_sm2_verify_hash(void)
  23708. {
  23709. int res = TEST_SKIPPED;
  23710. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  23711. EXPECT_DECLS;
  23712. ecc_key key[1];
  23713. int verified;
  23714. unsigned char pub[] = {
  23715. 0x04,
  23716. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23717. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23718. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23719. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23720. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23721. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23722. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23723. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23724. };
  23725. unsigned char hash[] = {
  23726. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23727. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23728. 0x50, 0x69, 0x5B, 0x20
  23729. };
  23730. unsigned char sig[] = {
  23731. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23732. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23733. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23734. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23735. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23736. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23737. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23738. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23739. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23740. };
  23741. unsigned char sigBad[] = {
  23742. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23743. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23744. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23745. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23746. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23747. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23748. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23749. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23750. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  23751. };
  23752. XMEMSET(key, 0, sizeof(*key));
  23753. ExpectIntEQ(wc_ecc_init(key), 0);
  23754. /* Test with no curve set. */
  23755. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23756. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23757. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23758. /* Test invalid parameters. */
  23759. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23760. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23761. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23762. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23763. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23764. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23765. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23766. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23767. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23768. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23769. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23770. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23771. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23772. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23773. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23774. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23775. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23776. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23777. /* Make key not on the SM2 curve. */
  23778. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23779. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23780. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23781. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23782. /* Test valid parameters. */
  23783. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23784. &verified, key), 0);
  23785. ExpectIntEQ(verified, 1);
  23786. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  23787. sizeof(hash), &verified, key), 0);
  23788. ExpectIntEQ(verified, 0);
  23789. wc_ecc_free(key);
  23790. #ifdef FP_ECC
  23791. wc_ecc_fp_free();
  23792. #endif
  23793. res = EXPECT_RESULT();
  23794. #endif
  23795. return res;
  23796. }
  23797. /*
  23798. * Testing wc_ecc_sm2_verify_hash_ex()
  23799. */
  23800. static int test_wc_ecc_sm2_sign_hash_ex(void)
  23801. {
  23802. int res = TEST_SKIPPED;
  23803. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  23804. defined(WOLFSSL_PUBLIC_MP)
  23805. EXPECT_DECLS;
  23806. WC_RNG rng[1];
  23807. ecc_key key[1];
  23808. mp_int r[1];
  23809. mp_int s[1];
  23810. unsigned char hash[32];
  23811. #ifdef HAVE_ECC_VERIFY
  23812. int verified;
  23813. #endif
  23814. XMEMSET(rng, 0, sizeof(*rng));
  23815. XMEMSET(key, 0, sizeof(*key));
  23816. XMEMSET(r, 0, sizeof(*r));
  23817. XMEMSET(s, 0, sizeof(*s));
  23818. ExpectIntEQ(wc_InitRng(rng), 0);
  23819. ExpectIntEQ(mp_init(r), 0);
  23820. ExpectIntEQ(mp_init(s), 0);
  23821. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  23822. ExpectIntEQ(wc_ecc_init(key), 0);
  23823. /* Test with no curve set. */
  23824. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23825. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23826. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23827. /* Test invalid parameters. */
  23828. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  23829. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23830. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  23831. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23832. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  23833. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23834. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  23835. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23836. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  23837. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23838. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  23839. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23840. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  23841. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23842. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  23843. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23844. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  23845. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23846. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  23847. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23848. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  23849. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23850. /* Make key not on the SM2 curve. */
  23851. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23852. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23853. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23854. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23855. #ifdef WOLFSSL_SP_MATH_ALL
  23856. {
  23857. mp_int smallR[1];
  23858. sp_init_size(smallR, 1);
  23859. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  23860. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  23861. smallR, s), 0);
  23862. }
  23863. #endif
  23864. /* Test valid parameters. */
  23865. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  23866. 0);
  23867. #ifdef HAVE_ECC_VERIFY
  23868. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  23869. key), 0);
  23870. ExpectIntEQ(verified, 1);
  23871. #endif
  23872. mp_free(s);
  23873. mp_free(r);
  23874. wc_ecc_free(key);
  23875. wc_FreeRng(rng);
  23876. #ifdef FP_ECC
  23877. wc_ecc_fp_free();
  23878. #endif
  23879. res = EXPECT_RESULT();
  23880. #endif
  23881. return res;
  23882. }
  23883. /*
  23884. * Testing wc_ecc_sm2_verify_hash()
  23885. */
  23886. static int test_wc_ecc_sm2_sign_hash(void)
  23887. {
  23888. int res = TEST_SKIPPED;
  23889. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  23890. EXPECT_DECLS;
  23891. WC_RNG rng[1];
  23892. ecc_key key[1];
  23893. unsigned char hash[32];
  23894. unsigned char sig[72];
  23895. word32 sigSz = sizeof(sig);
  23896. #ifdef HAVE_ECC_VERIFY
  23897. int verified;
  23898. #endif
  23899. XMEMSET(rng, 0, sizeof(*rng));
  23900. XMEMSET(key, 0, sizeof(*key));
  23901. ExpectIntEQ(wc_InitRng(rng), 0);
  23902. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  23903. ExpectIntEQ(wc_ecc_init(key), 0);
  23904. /* Test with no curve set. */
  23905. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23907. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23908. /* Test invalid parameters. */
  23909. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  23910. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23911. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  23912. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23913. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  23914. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23915. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  23916. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23917. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  23918. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23919. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  23920. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23921. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  23922. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23923. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  23924. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23925. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  23926. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23927. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  23928. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23929. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  23930. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23931. /* Make key not on the SM2 curve. */
  23932. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23933. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23934. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23935. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23936. /* Test valid parameters. */
  23937. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  23938. 0);
  23939. #ifdef HAVE_ECC_VERIFY
  23940. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  23941. &verified, key), 0);
  23942. ExpectIntEQ(verified, 1);
  23943. #endif
  23944. wc_ecc_free(key);
  23945. wc_FreeRng(rng);
  23946. #ifdef FP_ECC
  23947. wc_ecc_fp_free();
  23948. #endif
  23949. res = EXPECT_RESULT();
  23950. #endif
  23951. return res;
  23952. }
  23953. /*
  23954. * Testing ToTraditional
  23955. */
  23956. static int test_ToTraditional(void)
  23957. {
  23958. EXPECT_DECLS;
  23959. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  23960. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  23961. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  23962. XFILE f = XBADFILE;
  23963. byte input[TWOK_BUF];
  23964. word32 sz = 0;
  23965. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  23966. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  23967. if (f != XBADFILE)
  23968. XFCLOSE(f);
  23969. /* Good case */
  23970. ExpectIntGT(ToTraditional(input, sz), 0);
  23971. /* Bad cases */
  23972. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23973. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23974. #ifdef WOLFSSL_ASN_TEMPLATE
  23975. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  23976. #else
  23977. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  23978. #endif
  23979. #endif
  23980. return EXPECT_RESULT();
  23981. } /* End test_ToTraditional*/
  23982. /*
  23983. * Testing wc_EccPrivateKeyToDer
  23984. */
  23985. static int test_wc_EccPrivateKeyToDer(void)
  23986. {
  23987. EXPECT_DECLS;
  23988. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  23989. byte output[ONEK_BUF];
  23990. ecc_key eccKey;
  23991. WC_RNG rng;
  23992. word32 inLen;
  23993. word32 outLen = 0;
  23994. int ret;
  23995. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  23996. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23997. PRIVATE_KEY_UNLOCK();
  23998. ExpectIntEQ(wc_InitRng(&rng), 0);
  23999. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  24000. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  24001. #if defined(WOLFSSL_ASYNC_CRYPT)
  24002. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  24003. #endif
  24004. ExpectIntEQ(ret, 0);
  24005. inLen = (word32)sizeof(output);
  24006. /* Bad Cases */
  24007. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24008. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24009. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, NULL, inLen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  24010. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24011. /* Good Case */
  24012. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  24013. wc_ecc_free(&eccKey);
  24014. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24015. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  24016. {
  24017. /* test importing private only into a PKEY struct */
  24018. EC_KEY* ec = NULL;
  24019. EVP_PKEY* pkey = NULL;
  24020. const unsigned char* der;
  24021. der = output;
  24022. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  24023. der = output;
  24024. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  24025. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  24026. if (EXPECT_FAIL()) {
  24027. EC_KEY_free(ec);
  24028. }
  24029. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  24030. }
  24031. #endif
  24032. PRIVATE_KEY_LOCK();
  24033. #endif
  24034. return EXPECT_RESULT();
  24035. } /* End test_wc_EccPrivateKeyToDer*/
  24036. /*
  24037. * Testing wc_DhPublicKeyDecode
  24038. */
  24039. static int test_wc_DhPublicKeyDecode(void)
  24040. {
  24041. EXPECT_DECLS;
  24042. #ifndef NO_DH
  24043. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  24044. DhKey key;
  24045. word32 inOutIdx;
  24046. XMEMSET(&key, 0, sizeof(DhKey));
  24047. ExpectIntEQ(wc_InitDhKey(&key), 0);
  24048. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24049. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24051. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24053. inOutIdx = 0;
  24054. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  24055. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24056. inOutIdx = 0;
  24057. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  24058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24059. inOutIdx = 0;
  24060. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  24061. sizeof_dh_pub_key_der_2048), 0);
  24062. ExpectIntNE(key.p.used, 0);
  24063. ExpectIntNE(key.g.used, 0);
  24064. ExpectIntEQ(key.q.used, 0);
  24065. ExpectIntNE(key.pub.used, 0);
  24066. ExpectIntEQ(key.priv.used, 0);
  24067. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  24068. #endif
  24069. #endif /* !NO_DH */
  24070. return EXPECT_RESULT();
  24071. }
  24072. /*
  24073. * Testing wc_Ed25519KeyToDer
  24074. */
  24075. static int test_wc_Ed25519KeyToDer(void)
  24076. {
  24077. EXPECT_DECLS;
  24078. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24079. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24080. byte output[ONEK_BUF];
  24081. ed25519_key ed25519Key;
  24082. WC_RNG rng;
  24083. word32 inLen;
  24084. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  24085. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24086. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  24087. ExpectIntEQ(wc_InitRng(&rng), 0);
  24088. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  24089. inLen = (word32)sizeof(output);
  24090. /* Bad Cases */
  24091. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24092. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24093. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24094. /* Good Cases */
  24095. /* length only */
  24096. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  24097. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  24098. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  24099. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24100. wc_ed25519_free(&ed25519Key);
  24101. #endif
  24102. return EXPECT_RESULT();
  24103. } /* End test_wc_Ed25519KeyToDer*/
  24104. /*
  24105. * Testing wc_Ed25519PrivateKeyToDer
  24106. */
  24107. static int test_wc_Ed25519PrivateKeyToDer(void)
  24108. {
  24109. EXPECT_DECLS;
  24110. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24111. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24112. byte output[ONEK_BUF];
  24113. ed25519_key ed25519PrivKey;
  24114. WC_RNG rng;
  24115. word32 inLen;
  24116. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  24117. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24118. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  24119. ExpectIntEQ(wc_InitRng(&rng), 0);
  24120. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  24121. 0);
  24122. inLen = (word32)sizeof(output);
  24123. /* Bad Cases */
  24124. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24125. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24126. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  24127. WC_NO_ERR_TRACE(BUFFER_E));
  24128. /* Good Cases */
  24129. /* length only */
  24130. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  24131. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  24132. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24133. wc_ed25519_free(&ed25519PrivKey);
  24134. #endif
  24135. return EXPECT_RESULT();
  24136. } /* End test_wc_Ed25519PrivateKeyToDer*/
  24137. /*
  24138. * Testing wc_Ed448KeyToDer
  24139. */
  24140. static int test_wc_Ed448KeyToDer(void)
  24141. {
  24142. EXPECT_DECLS;
  24143. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24144. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24145. byte output[ONEK_BUF];
  24146. ed448_key ed448Key;
  24147. WC_RNG rng;
  24148. word32 inLen;
  24149. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  24150. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24151. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  24152. ExpectIntEQ(wc_InitRng(&rng), 0);
  24153. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  24154. inLen = (word32)sizeof(output);
  24155. /* Bad Cases */
  24156. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24157. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24158. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24159. /* Good Cases */
  24160. /* length only */
  24161. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  24162. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  24163. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24164. wc_ed448_free(&ed448Key);
  24165. #endif
  24166. return EXPECT_RESULT();
  24167. } /* End test_wc_Ed448KeyToDer*/
  24168. /*
  24169. * Testing wc_Ed448PrivateKeyToDer
  24170. */
  24171. static int test_wc_Ed448PrivateKeyToDer(void)
  24172. {
  24173. EXPECT_DECLS;
  24174. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24175. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24176. byte output[ONEK_BUF];
  24177. ed448_key ed448PrivKey;
  24178. WC_RNG rng;
  24179. word32 inLen;
  24180. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  24181. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24182. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  24183. ExpectIntEQ(wc_InitRng(&rng), 0);
  24184. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  24185. 0);
  24186. inLen = (word32)sizeof(output);
  24187. /* Bad Cases */
  24188. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24189. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24190. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  24191. WC_NO_ERR_TRACE(BUFFER_E));
  24192. /* Good cases */
  24193. /* length only */
  24194. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  24195. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  24196. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24197. wc_ed448_free(&ed448PrivKey);
  24198. #endif
  24199. return EXPECT_RESULT();
  24200. } /* End test_wc_Ed448PrivateKeyToDer*/
  24201. /*
  24202. * Testing wc_Curve448PrivateKeyToDer
  24203. */
  24204. static int test_wc_Curve448PrivateKeyToDer(void)
  24205. {
  24206. EXPECT_DECLS;
  24207. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  24208. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24209. byte output[ONEK_BUF];
  24210. curve448_key curve448PrivKey;
  24211. WC_RNG rng;
  24212. word32 inLen;
  24213. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  24214. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24215. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  24216. ExpectIntEQ(wc_InitRng(&rng), 0);
  24217. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24218. 0);
  24219. inLen = (word32)sizeof(output);
  24220. /* Bad Cases */
  24221. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24222. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24223. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24224. WC_NO_ERR_TRACE(BUFFER_E));
  24225. /* Good cases */
  24226. /* length only */
  24227. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24228. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24229. /* Bad Cases */
  24230. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24231. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24232. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24233. WC_NO_ERR_TRACE(BUFFER_E));
  24234. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24235. WC_NO_ERR_TRACE(BUFFER_E));
  24236. /* Good cases */
  24237. /* length only */
  24238. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24239. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24240. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24241. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24242. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24243. wc_curve448_free(&curve448PrivKey);
  24244. #endif
  24245. return EXPECT_RESULT();
  24246. } /* End wc_Curve448PrivateKeyToDer*/
  24247. static int test_wc_kyber_make_key_kats(void)
  24248. {
  24249. EXPECT_DECLS;
  24250. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24251. !defined(WOLFSSL_KYBER_ORIGINAL)
  24252. KyberKey* key;
  24253. #ifndef WOLFSSL_NO_KYBER512
  24254. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24255. /* d */
  24256. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24257. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24258. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24259. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24260. /* z */
  24261. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24262. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24263. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24264. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24265. };
  24266. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24267. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24268. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24269. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24270. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24271. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24272. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24273. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24274. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24275. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24276. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24277. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24278. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24279. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24280. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24281. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24282. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24283. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24284. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24285. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24286. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24287. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24288. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24289. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24290. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24291. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24292. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24293. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24294. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24295. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24296. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24297. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24298. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24299. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24300. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24301. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24302. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24303. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24304. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24305. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24306. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24307. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24308. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24309. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24310. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24311. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24312. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24313. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24314. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24315. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24316. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24317. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24318. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24319. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24320. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24321. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24322. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24323. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24324. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24325. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24326. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24327. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24328. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24329. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24330. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24331. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24332. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24333. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24334. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24335. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24336. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24337. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24338. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24339. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24340. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24341. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24342. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24343. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24344. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24345. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24346. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24347. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24348. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24349. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24350. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24351. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24352. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24353. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24354. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24355. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24356. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24357. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24358. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24359. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24360. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24361. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24362. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24363. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24364. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24365. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24366. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24367. };
  24368. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24369. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24370. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24371. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24372. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24373. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24374. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24375. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24376. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24377. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24378. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24379. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24380. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24381. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24382. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24383. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24384. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24385. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24386. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24387. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24388. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24389. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24390. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24391. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24392. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24393. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24394. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24395. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24396. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24397. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24398. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24399. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24400. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24401. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24402. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24403. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24404. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24405. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24406. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24407. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24408. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24409. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24410. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24411. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24412. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24413. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24414. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24415. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24416. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24417. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24418. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24419. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24420. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24421. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24422. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24423. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24424. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24425. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24426. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24427. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24428. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24429. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24430. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24431. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24432. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24433. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24434. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24435. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24436. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24437. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24438. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24439. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24440. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24441. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24442. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24443. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24444. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24445. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24446. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24447. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24448. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24449. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24450. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24451. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24452. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24453. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24454. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24455. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24456. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24457. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24458. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24459. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24460. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24461. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24462. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24463. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24464. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24465. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24466. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24467. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24468. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24469. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24470. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24471. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24472. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24473. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24474. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24475. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24476. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24477. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24478. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24479. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24480. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24481. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24482. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24483. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24484. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24485. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24486. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24487. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24488. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24489. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24490. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24491. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24492. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24493. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24494. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24495. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24496. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24497. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24498. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24499. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24500. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24501. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24502. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24503. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24504. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24505. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24506. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24507. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24508. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24509. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24510. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24511. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24512. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24513. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24514. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24515. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24516. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24517. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24518. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24519. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24520. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24521. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24522. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24523. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24524. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24525. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24526. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24527. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24528. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24529. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24530. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24531. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24532. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24533. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24534. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24535. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24536. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24537. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24538. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24539. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24540. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24541. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24542. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24543. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24544. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24545. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24546. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24547. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24548. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24549. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24550. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24551. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24552. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24553. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24554. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24555. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24556. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24557. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24558. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24559. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24560. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24561. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24562. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24563. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24564. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24565. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24566. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24567. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24568. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24569. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24570. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24571. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24572. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24573. };
  24574. #endif
  24575. #ifndef WOLFSSL_NO_KYBER768
  24576. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24577. /* d */
  24578. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24579. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24580. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24581. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24582. /* z */
  24583. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24584. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24585. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24586. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24587. };
  24588. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24589. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24590. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24591. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24592. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24593. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24594. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24595. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24596. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24597. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24598. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24599. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24600. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24601. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24602. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24603. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24604. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24605. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24606. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24607. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24608. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24609. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24610. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24611. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24612. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24613. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24614. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24615. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24616. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24617. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24618. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24619. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24620. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24621. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24622. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24623. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24624. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24625. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24626. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24627. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24628. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24629. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24630. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24631. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24632. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24633. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24634. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24635. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24636. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24637. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24638. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24639. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24640. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24641. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24642. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24643. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24644. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24645. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24646. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24647. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24648. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24649. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24650. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24651. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24652. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24653. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24654. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24655. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24656. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24657. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24658. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24659. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24660. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24661. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24662. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24663. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24664. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24665. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24666. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24667. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24668. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24669. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24670. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24671. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24672. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24673. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24674. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24675. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24676. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24677. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24678. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24679. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24680. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24681. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24682. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24683. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24684. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24685. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24686. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24687. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24688. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24689. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24690. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24691. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24692. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24693. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24694. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24695. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24696. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24697. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24698. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24699. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24700. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24701. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24702. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24703. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24704. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24705. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24706. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24707. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24708. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24709. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24710. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24711. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24712. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24713. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24714. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24715. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24716. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24717. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24718. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24719. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24720. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24721. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24722. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24723. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24724. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24725. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24726. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24727. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24728. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24729. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24730. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24731. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24732. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24733. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24734. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24735. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24736. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  24737. };
  24738. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  24739. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  24740. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  24741. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  24742. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  24743. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  24744. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  24745. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  24746. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  24747. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  24748. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  24749. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  24750. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  24751. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  24752. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  24753. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  24754. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  24755. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  24756. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  24757. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  24758. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  24759. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  24760. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  24761. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  24762. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  24763. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  24764. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  24765. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  24766. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  24767. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  24768. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  24769. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  24770. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  24771. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  24772. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  24773. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  24774. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  24775. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  24776. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  24777. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  24778. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  24779. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  24780. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  24781. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  24782. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  24783. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  24784. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  24785. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  24786. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  24787. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  24788. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  24789. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  24790. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  24791. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  24792. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  24793. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  24794. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  24795. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  24796. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  24797. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  24798. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  24799. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  24800. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  24801. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  24802. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  24803. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  24804. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  24805. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  24806. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  24807. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  24808. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  24809. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  24810. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  24811. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  24812. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  24813. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  24814. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  24815. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  24816. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  24817. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  24818. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  24819. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  24820. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  24821. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  24822. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  24823. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  24824. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  24825. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  24826. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  24827. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  24828. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  24829. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  24830. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  24831. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  24832. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  24833. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  24834. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  24835. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  24836. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  24837. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  24838. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  24839. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  24840. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  24841. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  24842. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  24843. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  24844. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  24845. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  24846. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  24847. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  24848. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  24849. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  24850. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  24851. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  24852. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  24853. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  24854. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  24855. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  24856. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  24857. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  24858. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  24859. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  24860. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  24861. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  24862. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  24863. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  24864. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  24865. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  24866. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  24867. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  24868. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  24869. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  24870. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  24871. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  24872. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  24873. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  24874. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  24875. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  24876. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  24877. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  24878. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  24879. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  24880. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  24881. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  24882. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  24883. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24884. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24885. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24886. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24887. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24888. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24889. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24890. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24891. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24892. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24893. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24894. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24895. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24896. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24897. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24898. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24899. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24900. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24901. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24902. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24903. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24904. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24905. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24906. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24907. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24908. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24909. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24910. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24911. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24912. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24913. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24914. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24915. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24916. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24917. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24918. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24919. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24920. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24921. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24922. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24923. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24924. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24925. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24926. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24927. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24928. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24929. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24930. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24931. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24932. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24933. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24934. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24935. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24936. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24937. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24938. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24939. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24940. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24941. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24942. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24943. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24944. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24945. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24946. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24947. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24948. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24949. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24950. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24951. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24952. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24953. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24954. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24955. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24956. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24957. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24958. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24959. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24960. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24961. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24962. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24963. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24964. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24965. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24966. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24967. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24968. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24969. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24970. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24971. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24972. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24973. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24974. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24975. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24976. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24977. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24978. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24979. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24980. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24981. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24982. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24983. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24984. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24985. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24986. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24987. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24988. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24989. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24990. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24991. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24992. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24993. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24994. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24995. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24996. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24997. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24998. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24999. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25000. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25001. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25002. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25003. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25004. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25005. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25006. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25007. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25008. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25009. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25010. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25011. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25012. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25013. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25014. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25015. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25016. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25017. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25018. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25019. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25020. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25021. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25022. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25023. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25024. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25025. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25026. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25027. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25028. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25029. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25030. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  25031. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  25032. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  25033. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  25034. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  25035. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  25036. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  25037. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  25038. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  25039. };
  25040. #endif
  25041. #ifndef WOLFSSL_NO_KYBER1024
  25042. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  25043. /* d */
  25044. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  25045. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  25046. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  25047. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  25048. /* z */
  25049. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25050. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25051. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25052. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25053. };
  25054. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  25055. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25056. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25057. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25058. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25059. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25060. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25061. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25062. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25063. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25064. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25065. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25066. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25067. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25068. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25069. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25070. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25071. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25072. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25073. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25074. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25075. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25076. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25077. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25078. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25079. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25080. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25081. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25082. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25083. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25084. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25085. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25086. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25087. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25088. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25089. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25090. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25091. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25092. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25093. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25094. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25095. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25096. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25097. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25098. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25099. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25100. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25101. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25102. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25103. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25104. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25105. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25106. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25107. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25108. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25109. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25110. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25111. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25112. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25113. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25114. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25115. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25116. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25117. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25118. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25119. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25120. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25121. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25122. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25123. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25124. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25125. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25126. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25127. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25128. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25129. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25130. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25131. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25132. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25133. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25134. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25135. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25136. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25137. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25138. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25139. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25140. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25141. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25142. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25143. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25144. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25145. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25146. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25147. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25148. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25149. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25150. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25151. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25152. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25153. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25154. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25155. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25156. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25157. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25158. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25159. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25160. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25161. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25162. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25163. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25164. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25165. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25166. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25167. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25168. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25169. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25170. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25171. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25172. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25173. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25174. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25175. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25176. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25177. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25178. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25179. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25180. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25181. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25182. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25183. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25184. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25185. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25186. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25187. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25188. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25189. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25190. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25191. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25192. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25193. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25194. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25195. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25196. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25197. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25198. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25199. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25200. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25201. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25202. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25203. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25204. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25205. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25206. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25207. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25208. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25209. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25210. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25211. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25212. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25213. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25214. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25215. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25216. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25217. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25218. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25219. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25220. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25221. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25222. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25223. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25224. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25225. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25226. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25227. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25228. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25229. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25230. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25231. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25232. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25233. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25234. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25235. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25236. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25237. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25238. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25239. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25240. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25241. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25242. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25243. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25244. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25245. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25246. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25247. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25248. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25249. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25250. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25251. };
  25252. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25253. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25254. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25255. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25256. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25257. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25258. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25259. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25260. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25261. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25262. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25263. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25264. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25265. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25266. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25267. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25268. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25269. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25270. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25271. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25272. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25273. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25274. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25275. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25276. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25277. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25278. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25279. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25280. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25281. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25282. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25283. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25284. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25285. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25286. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25287. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25288. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25289. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25290. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25291. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25292. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25293. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25294. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25295. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25296. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25297. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25298. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25299. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25300. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25301. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25302. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25303. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25304. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25305. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25306. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25307. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25308. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25309. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25310. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25311. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25312. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25313. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25314. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25315. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25316. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25317. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25318. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25319. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25320. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25321. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25322. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25323. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25324. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25325. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25326. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25327. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25328. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25329. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25330. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25331. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25332. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25333. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25334. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25335. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25336. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25337. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25338. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25339. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25340. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25341. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25342. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25343. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25344. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25345. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25346. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25347. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25348. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25349. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25350. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25351. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25352. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25353. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25354. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25355. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25356. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25357. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25358. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25359. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25360. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25361. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25362. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25363. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25364. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25365. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25366. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25367. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25368. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25369. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25370. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25371. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25372. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25373. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25374. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25375. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25376. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25377. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25378. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25379. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25380. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25381. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25382. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25383. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25384. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25385. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25386. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25387. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25388. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25389. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25390. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25391. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25392. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25393. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25394. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25395. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25396. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25397. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25398. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25399. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25400. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25401. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25402. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25403. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25404. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25405. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25406. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25407. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25408. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25409. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25410. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25411. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25412. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25413. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25414. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25415. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25416. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25417. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25418. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25419. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25420. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25421. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25422. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25423. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25424. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25425. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25426. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25427. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25428. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25429. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25430. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25431. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25432. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25433. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25434. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25435. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25436. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25437. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25438. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25439. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25440. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25441. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25442. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25443. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25444. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25445. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25446. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25447. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25448. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25449. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25450. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25451. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25452. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25453. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25454. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25455. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25456. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25457. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25458. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25459. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25460. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25461. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25462. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25463. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25464. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25465. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25466. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25467. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25468. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25469. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25470. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25471. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25472. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25473. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25474. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25475. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25476. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25477. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25478. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25479. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25480. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25481. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25482. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25483. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25484. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25485. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25486. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25487. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25488. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25489. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25490. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25491. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25492. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25493. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25494. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25495. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25496. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25497. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25498. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25499. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25500. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25501. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25502. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25503. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25504. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25505. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25506. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25507. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25508. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25509. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25510. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25511. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25512. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25513. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25514. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25515. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25516. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25517. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25518. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25519. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25520. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25521. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25522. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25523. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25524. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25525. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25526. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25527. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25528. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25529. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25530. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25531. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25532. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25533. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25534. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25535. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25536. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25537. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25538. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25539. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25540. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25541. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25542. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25543. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25544. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25545. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25546. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25547. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25548. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25549. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25550. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25551. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25552. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25553. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25554. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25555. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25556. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25557. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25558. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25559. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25560. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25561. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25562. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25563. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25564. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25565. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25566. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25567. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25568. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25569. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25570. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25571. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25572. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25573. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25574. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25575. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25576. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25577. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25578. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25579. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25580. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25581. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25582. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25583. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25584. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25585. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25586. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25587. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25588. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25589. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25590. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25591. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25592. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25593. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25594. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25595. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25596. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25597. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25598. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25599. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25600. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25601. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25602. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25603. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25604. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25605. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25606. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25607. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25608. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25609. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25610. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25611. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25612. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25613. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25614. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25615. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25616. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25617. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25618. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25619. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25620. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25621. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25622. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25623. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25624. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25625. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25626. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25627. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25628. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25629. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25630. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25631. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25632. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25633. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25634. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25635. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25636. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25637. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25638. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25639. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25640. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  25641. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  25642. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  25643. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  25644. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  25645. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25646. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25647. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25648. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25649. };
  25650. #endif
  25651. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  25652. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  25653. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25654. ExpectNotNull(key);
  25655. if (key != NULL) {
  25656. XMEMSET(key, 0, sizeof(KyberKey));
  25657. }
  25658. #ifndef WOLFSSL_NO_KYBER512
  25659. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  25660. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  25661. 0);
  25662. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25663. KYBER512_PUBLIC_KEY_SIZE), 0);
  25664. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25665. KYBER512_PRIVATE_KEY_SIZE), 0);
  25666. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  25667. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  25668. wc_KyberKey_Free(key);
  25669. #endif
  25670. #ifndef WOLFSSL_NO_KYBER768
  25671. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  25672. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  25673. 0);
  25674. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25675. KYBER768_PUBLIC_KEY_SIZE), 0);
  25676. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25677. KYBER768_PRIVATE_KEY_SIZE), 0);
  25678. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  25679. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  25680. wc_KyberKey_Free(key);
  25681. #endif
  25682. #ifndef WOLFSSL_NO_KYBER1024
  25683. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  25684. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  25685. sizeof(seed_1024)), 0);
  25686. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25687. KYBER1024_PUBLIC_KEY_SIZE), 0);
  25688. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25689. KYBER1024_PRIVATE_KEY_SIZE), 0);
  25690. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  25691. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  25692. wc_KyberKey_Free(key);
  25693. #endif
  25694. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25695. #endif
  25696. return EXPECT_RESULT();
  25697. }
  25698. static int test_wc_kyber_encapsulate_kats(void)
  25699. {
  25700. EXPECT_DECLS;
  25701. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  25702. !defined(WOLFSSL_KYBER_ORIGINAL)
  25703. KyberKey* key;
  25704. #ifndef WOLFSSL_NO_KYBER512
  25705. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  25706. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  25707. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  25708. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  25709. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  25710. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  25711. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  25712. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  25713. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  25714. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  25715. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  25716. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  25717. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  25718. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  25719. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  25720. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  25721. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  25722. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  25723. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  25724. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  25725. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  25726. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  25727. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  25728. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  25729. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  25730. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  25731. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  25732. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  25733. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  25734. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  25735. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  25736. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  25737. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  25738. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  25739. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  25740. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  25741. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  25742. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  25743. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  25744. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  25745. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  25746. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  25747. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  25748. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  25749. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  25750. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  25751. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  25752. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  25753. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  25754. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  25755. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  25756. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  25757. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  25758. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  25759. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  25760. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  25761. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  25762. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  25763. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  25764. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  25765. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  25766. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  25767. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  25768. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  25769. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  25770. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  25771. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  25772. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  25773. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  25774. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  25775. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  25776. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  25777. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  25778. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  25779. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  25780. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  25781. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  25782. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  25783. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  25784. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  25785. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  25786. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  25787. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  25788. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  25789. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  25790. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  25791. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  25792. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  25793. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  25794. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  25795. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  25796. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  25797. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  25798. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  25799. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  25800. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  25801. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  25802. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  25803. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  25804. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  25805. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  25806. };
  25807. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  25808. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  25809. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  25810. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  25811. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  25812. };
  25813. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  25814. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  25815. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  25816. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  25817. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  25818. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  25819. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  25820. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  25821. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  25822. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  25823. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  25824. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  25825. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  25826. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  25827. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  25828. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  25829. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  25830. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  25831. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  25832. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  25833. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  25834. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  25835. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  25836. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  25837. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  25838. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  25839. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  25840. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  25841. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  25842. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  25843. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  25844. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  25845. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  25846. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  25847. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  25848. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  25849. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  25850. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  25851. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  25852. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  25853. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  25854. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  25855. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  25856. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  25857. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  25858. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  25859. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  25860. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  25861. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  25862. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  25863. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  25864. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  25865. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  25866. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  25867. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  25868. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  25869. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  25870. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  25871. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  25872. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  25873. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  25874. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  25875. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  25876. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  25877. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  25878. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  25879. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  25880. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  25881. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  25882. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  25883. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  25884. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  25885. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  25886. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  25887. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  25888. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  25889. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  25890. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  25891. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  25892. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  25893. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  25894. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  25895. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  25896. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  25897. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  25898. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  25899. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  25900. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  25901. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  25902. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  25903. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  25904. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  25905. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  25906. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  25907. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  25908. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  25909. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  25910. };
  25911. static const byte k_512[KYBER_SS_SZ] = {
  25912. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  25913. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  25914. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  25915. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  25916. };
  25917. #endif
  25918. #ifndef WOLFSSL_NO_KYBER768
  25919. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  25920. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  25921. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  25922. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  25923. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  25924. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  25925. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  25926. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  25927. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  25928. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  25929. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  25930. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  25931. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  25932. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  25933. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  25934. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  25935. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  25936. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  25937. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  25938. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  25939. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  25940. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  25941. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  25942. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  25943. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  25944. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  25945. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  25946. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  25947. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  25948. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  25949. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  25950. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  25951. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  25952. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  25953. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  25954. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  25955. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  25956. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  25957. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  25958. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  25959. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  25960. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  25961. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  25962. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  25963. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  25964. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  25965. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  25966. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  25967. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  25968. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  25969. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  25970. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  25971. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  25972. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  25973. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  25974. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  25975. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  25976. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  25977. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  25978. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  25979. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  25980. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  25981. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  25982. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  25983. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  25984. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  25985. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  25986. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  25987. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  25988. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  25989. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  25990. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  25991. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  25992. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  25993. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  25994. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  25995. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  25996. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  25997. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  25998. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  25999. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  26000. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  26001. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  26002. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  26003. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  26004. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  26005. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  26006. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  26007. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  26008. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  26009. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  26010. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  26011. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  26012. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  26013. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  26014. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  26015. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  26016. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  26017. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  26018. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  26019. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  26020. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  26021. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  26022. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  26023. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  26024. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  26025. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  26026. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  26027. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  26028. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  26029. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  26030. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  26031. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  26032. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  26033. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  26034. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  26035. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  26036. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  26037. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  26038. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  26039. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  26040. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  26041. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  26042. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  26043. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  26044. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  26045. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  26046. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  26047. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  26048. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  26049. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  26050. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  26051. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  26052. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  26053. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  26054. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  26055. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  26056. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  26057. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  26058. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  26059. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  26060. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  26061. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  26062. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  26063. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  26064. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  26065. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  26066. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  26067. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  26068. };
  26069. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  26070. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  26071. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  26072. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  26073. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  26074. };
  26075. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  26076. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  26077. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  26078. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  26079. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  26080. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  26081. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  26082. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  26083. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  26084. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  26085. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  26086. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  26087. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  26088. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  26089. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  26090. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  26091. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  26092. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  26093. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  26094. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  26095. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  26096. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  26097. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  26098. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  26099. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  26100. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  26101. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  26102. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  26103. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  26104. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  26105. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  26106. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  26107. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  26108. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  26109. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  26110. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  26111. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  26112. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  26113. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  26114. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  26115. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  26116. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  26117. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  26118. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  26119. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  26120. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  26121. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  26122. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  26123. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  26124. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  26125. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  26126. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  26127. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  26128. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  26129. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  26130. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  26131. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  26132. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  26133. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  26134. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  26135. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  26136. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  26137. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  26138. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  26139. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  26140. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  26141. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  26142. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  26143. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  26144. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  26145. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  26146. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  26147. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  26148. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  26149. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  26150. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  26151. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  26152. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  26153. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  26154. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  26155. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  26156. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  26157. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  26158. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  26159. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  26160. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  26161. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  26162. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  26163. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  26164. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  26165. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  26166. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  26167. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  26168. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  26169. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  26170. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  26171. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  26172. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  26173. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  26174. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  26175. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  26176. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  26177. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  26178. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  26179. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  26180. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  26181. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  26182. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  26183. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  26184. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  26185. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  26186. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  26187. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  26188. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  26189. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  26190. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  26191. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  26192. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  26193. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  26194. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  26195. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  26196. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  26197. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  26198. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  26199. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  26200. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  26201. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  26202. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  26203. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  26204. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  26205. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  26206. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  26207. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  26208. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  26209. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  26210. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  26211. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  26212. };
  26213. static const byte k_768[KYBER_SS_SZ] = {
  26214. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  26215. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  26216. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  26217. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26218. };
  26219. #endif
  26220. #ifndef WOLFSSL_NO_KYBER1024
  26221. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26222. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26223. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26224. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26225. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26226. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26227. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26228. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26229. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26230. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26231. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26232. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26233. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26234. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26235. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26236. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26237. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26238. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26239. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26240. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26241. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26242. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26243. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26244. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26245. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26246. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26247. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26248. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26249. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26250. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26251. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26252. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26253. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26254. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26255. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26256. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26257. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26258. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26259. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26260. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26261. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26262. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26263. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26264. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26265. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26266. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26267. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26268. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26269. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26270. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26271. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26272. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26273. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26274. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26275. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26276. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26277. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26278. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26279. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26280. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26281. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26282. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26283. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26284. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26285. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26286. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26287. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26288. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26289. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26290. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26291. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26292. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26293. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26294. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26295. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26296. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26297. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26298. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26299. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26300. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26301. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26302. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26303. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26304. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26305. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26306. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26307. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26308. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26309. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26310. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26311. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26312. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26313. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26314. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26315. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26316. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26317. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26318. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26319. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26320. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26321. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26322. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26323. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26324. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26325. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26326. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26327. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26328. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26329. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26330. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26331. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26332. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26333. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26334. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26335. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26336. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26337. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26338. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26339. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26340. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26341. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26342. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26343. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26344. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26345. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26346. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26347. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26348. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26349. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26350. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26351. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26352. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26353. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26354. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26355. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26356. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26357. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26358. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26359. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26360. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26361. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26362. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26363. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26364. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26365. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26366. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26367. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26368. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26369. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26370. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26371. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26372. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26373. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26374. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26375. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26376. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26377. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26378. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26379. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26380. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26381. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26382. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26383. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26384. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26385. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26386. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26387. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26388. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26389. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26390. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26391. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26392. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26393. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26394. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26395. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26396. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26397. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26398. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26399. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26400. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26401. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26402. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26403. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26404. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26405. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26406. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26407. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26408. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26409. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26410. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26411. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26412. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26413. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26414. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26415. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26416. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26417. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26418. };
  26419. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26420. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26421. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26422. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26423. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26424. };
  26425. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26426. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26427. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26428. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26429. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26430. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26431. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26432. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26433. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26434. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26435. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26436. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26437. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26438. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26439. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26440. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26441. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26442. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26443. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26444. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26445. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26446. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26447. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26448. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26449. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26450. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26451. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26452. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26453. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26454. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26455. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26456. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26457. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26458. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26459. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26460. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26461. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26462. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26463. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26464. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26465. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26466. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26467. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26468. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26469. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26470. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26471. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26472. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26473. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26474. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26475. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26476. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26477. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26478. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26479. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26480. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26481. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26482. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26483. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26484. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26485. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26486. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26487. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26488. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26489. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26490. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26491. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26492. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26493. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26494. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26495. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26496. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26497. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26498. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26499. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26500. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26501. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26502. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26503. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26504. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26505. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26506. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26507. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26508. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26509. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26510. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26511. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26512. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26513. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26514. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26515. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26516. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26517. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26518. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26519. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26520. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26521. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26522. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26523. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26524. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26525. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26526. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26527. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26528. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26529. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26530. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26531. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26532. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26533. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26534. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26535. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26536. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26537. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26538. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26539. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26540. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26541. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26542. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26543. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26544. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26545. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26546. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26547. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26548. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26549. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26550. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26551. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26552. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26553. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26554. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26555. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26556. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26557. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26558. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26559. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26560. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26561. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26562. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26563. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26564. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26565. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26566. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26567. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26568. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26569. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26570. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26571. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26572. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26573. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26574. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26575. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26576. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26577. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26578. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26579. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26580. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26581. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26582. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26583. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26584. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26585. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26586. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26587. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26588. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26589. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26590. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26591. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26592. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26593. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26594. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26595. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26596. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26597. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26598. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26599. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26600. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26601. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26602. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26603. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26604. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26605. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26606. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26607. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26608. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26609. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26610. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26611. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26612. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26613. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26614. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26615. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26616. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26617. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26618. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26619. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26620. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26621. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26622. };
  26623. static const byte k_1024[KYBER_SS_SZ] = {
  26624. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26625. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26626. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26627. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26628. };
  26629. #endif
  26630. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26631. static byte ss[KYBER_SS_SZ];
  26632. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26633. ExpectNotNull(key);
  26634. if (key != NULL) {
  26635. XMEMSET(key, 0, sizeof(KyberKey));
  26636. }
  26637. #ifndef WOLFSSL_NO_KYBER512
  26638. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26639. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  26640. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  26641. sizeof(seed_512)), 0);
  26642. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  26643. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  26644. wc_KyberKey_Free(key);
  26645. #endif
  26646. #ifndef WOLFSSL_NO_KYBER768
  26647. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26648. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  26649. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  26650. sizeof(seed_768)), 0);
  26651. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  26652. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  26653. wc_KyberKey_Free(key);
  26654. #endif
  26655. #ifndef WOLFSSL_NO_KYBER1024
  26656. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26657. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  26658. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  26659. sizeof(seed_1024)), 0);
  26660. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  26661. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  26662. wc_KyberKey_Free(key);
  26663. #endif
  26664. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26665. #endif
  26666. return EXPECT_RESULT();
  26667. }
  26668. static int test_wc_kyber_decapsulate_kats(void)
  26669. {
  26670. EXPECT_DECLS;
  26671. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26672. !defined(WOLFSSL_KYBER_ORIGINAL)
  26673. KyberKey* key;
  26674. #ifndef WOLFSSL_NO_KYBER512
  26675. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  26676. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  26677. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  26678. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  26679. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  26680. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  26681. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  26682. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  26683. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  26684. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  26685. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  26686. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  26687. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  26688. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  26689. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  26690. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  26691. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  26692. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  26693. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  26694. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  26695. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  26696. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  26697. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  26698. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  26699. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  26700. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  26701. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  26702. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  26703. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  26704. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  26705. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  26706. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  26707. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  26708. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  26709. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  26710. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  26711. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  26712. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  26713. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  26714. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  26715. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  26716. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  26717. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  26718. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  26719. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  26720. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  26721. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  26722. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  26723. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  26724. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  26725. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  26726. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  26727. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  26728. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  26729. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  26730. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  26731. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  26732. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  26733. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  26734. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  26735. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  26736. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  26737. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  26738. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  26739. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  26740. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  26741. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  26742. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  26743. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  26744. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  26745. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  26746. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  26747. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  26748. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  26749. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  26750. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  26751. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  26752. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  26753. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  26754. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  26755. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  26756. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  26757. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  26758. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  26759. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  26760. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  26761. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  26762. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  26763. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  26764. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  26765. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  26766. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  26767. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  26768. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  26769. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  26770. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  26771. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  26772. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  26773. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  26774. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  26775. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  26776. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  26777. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  26778. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  26779. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  26780. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  26781. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  26782. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  26783. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  26784. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  26785. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  26786. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  26787. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  26788. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  26789. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  26790. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  26791. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  26792. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  26793. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  26794. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  26795. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  26796. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  26797. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  26798. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  26799. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  26800. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  26801. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  26802. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  26803. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  26804. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  26805. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  26806. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  26807. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  26808. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  26809. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  26810. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  26811. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  26812. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  26813. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  26814. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  26815. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  26816. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  26817. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  26818. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  26819. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  26820. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  26821. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  26822. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  26823. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  26824. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  26825. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  26826. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  26827. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  26828. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  26829. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  26830. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  26831. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  26832. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  26833. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  26834. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  26835. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  26836. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  26837. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  26838. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  26839. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  26840. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  26841. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  26842. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  26843. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  26844. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  26845. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  26846. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  26847. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  26848. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  26849. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  26850. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  26851. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  26852. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  26853. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  26854. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  26855. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  26856. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  26857. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  26858. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  26859. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  26860. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  26861. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  26862. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  26863. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  26864. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  26865. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  26866. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  26867. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  26868. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  26869. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  26870. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  26871. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  26872. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  26873. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  26874. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  26875. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  26876. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  26877. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  26878. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  26879. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  26880. };
  26881. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26882. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  26883. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  26884. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  26885. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  26886. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  26887. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  26888. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  26889. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  26890. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  26891. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  26892. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  26893. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  26894. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  26895. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  26896. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  26897. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  26898. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  26899. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  26900. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  26901. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  26902. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  26903. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  26904. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  26905. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  26906. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  26907. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  26908. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  26909. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  26910. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  26911. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  26912. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  26913. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  26914. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  26915. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  26916. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  26917. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  26918. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  26919. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  26920. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  26921. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  26922. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  26923. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  26924. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  26925. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  26926. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  26927. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  26928. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  26929. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  26930. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  26931. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  26932. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  26933. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  26934. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  26935. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  26936. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  26937. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  26938. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  26939. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  26940. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  26941. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  26942. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  26943. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  26944. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  26945. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  26946. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  26947. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  26948. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  26949. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  26950. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  26951. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  26952. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  26953. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  26954. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  26955. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  26956. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  26957. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  26958. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  26959. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  26960. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  26961. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  26962. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  26963. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  26964. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  26965. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  26966. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  26967. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  26968. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  26969. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  26970. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  26971. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  26972. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  26973. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  26974. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  26975. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  26976. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  26977. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  26978. };
  26979. static const byte kprime_512[KYBER_SS_SZ] = {
  26980. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  26981. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  26982. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  26983. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  26984. };
  26985. #endif
  26986. #ifndef WOLFSSL_NO_KYBER768
  26987. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  26988. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  26989. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  26990. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  26991. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  26992. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  26993. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  26994. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  26995. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  26996. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  26997. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  26998. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  26999. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  27000. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  27001. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  27002. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  27003. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  27004. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  27005. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  27006. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  27007. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  27008. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  27009. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  27010. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  27011. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  27012. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  27013. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  27014. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  27015. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  27016. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  27017. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  27018. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  27019. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  27020. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  27021. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  27022. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  27023. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  27024. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  27025. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  27026. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  27027. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  27028. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  27029. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  27030. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  27031. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  27032. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  27033. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  27034. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  27035. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  27036. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  27037. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  27038. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  27039. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  27040. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  27041. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  27042. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  27043. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  27044. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  27045. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  27046. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  27047. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  27048. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  27049. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  27050. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  27051. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  27052. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  27053. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  27054. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  27055. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  27056. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  27057. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  27058. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  27059. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  27060. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  27061. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  27062. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  27063. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  27064. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  27065. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  27066. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  27067. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  27068. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  27069. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  27070. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  27071. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  27072. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  27073. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  27074. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  27075. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  27076. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  27077. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  27078. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  27079. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  27080. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  27081. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  27082. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  27083. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  27084. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  27085. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  27086. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  27087. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  27088. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  27089. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  27090. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  27091. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  27092. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  27093. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  27094. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  27095. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  27096. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  27097. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  27098. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  27099. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  27100. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  27101. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  27102. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  27103. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  27104. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  27105. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  27106. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  27107. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  27108. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  27109. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  27110. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  27111. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  27112. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  27113. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  27114. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  27115. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  27116. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  27117. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  27118. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  27119. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  27120. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  27121. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  27122. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  27123. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  27124. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  27125. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  27126. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  27127. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  27128. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  27129. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  27130. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  27131. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  27132. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  27133. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  27134. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  27135. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  27136. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  27137. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  27138. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  27139. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  27140. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  27141. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  27142. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  27143. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  27144. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  27145. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  27146. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  27147. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  27148. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  27149. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  27150. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  27151. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  27152. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  27153. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  27154. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  27155. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  27156. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  27157. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  27158. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  27159. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  27160. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  27161. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  27162. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  27163. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  27164. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  27165. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  27166. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  27167. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  27168. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  27169. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  27170. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  27171. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  27172. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  27173. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  27174. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  27175. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  27176. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  27177. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  27178. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  27179. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  27180. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  27181. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  27182. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  27183. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  27184. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  27185. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  27186. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  27187. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  27188. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  27189. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  27190. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  27191. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  27192. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  27193. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  27194. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  27195. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  27196. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  27197. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  27198. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  27199. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  27200. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  27201. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  27202. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  27203. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  27204. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  27205. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  27206. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  27207. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  27208. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  27209. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  27210. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  27211. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  27212. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  27213. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  27214. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  27215. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  27216. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  27217. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27218. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27219. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27220. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27221. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27222. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27223. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27224. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27225. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27226. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27227. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27228. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27229. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27230. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27231. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27232. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27233. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27234. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27235. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27236. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27237. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27238. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27239. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27240. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27241. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27242. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27243. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27244. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27245. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27246. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27247. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27248. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27249. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27250. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27251. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27252. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27253. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27254. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27255. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27256. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27257. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27258. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27259. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27260. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27261. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27262. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27263. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27264. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27265. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27266. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27267. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27268. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27269. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27270. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27271. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27272. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27273. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27274. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27275. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27276. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27277. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27278. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27279. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27280. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27281. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27282. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27283. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27284. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27285. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27286. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27287. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27288. };
  27289. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27290. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27291. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27292. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27293. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27294. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27295. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27296. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27297. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27298. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27299. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27300. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27301. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27302. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27303. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27304. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27305. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27306. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27307. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27308. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27309. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27310. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27311. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27312. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27313. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27314. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27315. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27316. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27317. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27318. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27319. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27320. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27321. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27322. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27323. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27324. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27325. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27326. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27327. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27328. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27329. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27330. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27331. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27332. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27333. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27334. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27335. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27336. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27337. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27338. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27339. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27340. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27341. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27342. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27343. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27344. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27345. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27346. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27347. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27348. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27349. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27350. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27351. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27352. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27353. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27354. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27355. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27356. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27357. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27358. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27359. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27360. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27361. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27362. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27363. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27364. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27365. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27366. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27367. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27368. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27369. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27370. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27371. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27372. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27373. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27374. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27375. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27376. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27377. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27378. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27379. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27380. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27381. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27382. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27383. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27384. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27385. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27386. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27387. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27388. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27389. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27390. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27391. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27392. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27393. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27394. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27395. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27396. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27397. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27398. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27399. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27400. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27401. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27402. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27403. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27404. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27405. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27406. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27407. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27408. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27409. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27410. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27411. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27412. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27413. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27414. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27415. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27416. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27417. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27418. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27419. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27420. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27421. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27422. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27423. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27424. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27425. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27426. };
  27427. static const byte kprime_768[KYBER_SS_SZ] = {
  27428. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27429. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27430. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27431. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27432. };
  27433. #endif
  27434. #ifndef WOLFSSL_NO_KYBER1024
  27435. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27436. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27437. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27438. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27439. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27440. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27441. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27442. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27443. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27444. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27445. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27446. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27447. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27448. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27449. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27450. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27451. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27452. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27453. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27454. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27455. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27456. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27457. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27458. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27459. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27460. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27461. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27462. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27463. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27464. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27465. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27466. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27467. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27468. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27469. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27470. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27471. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27472. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27473. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27474. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27475. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27476. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27477. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27478. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27479. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27480. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27481. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27482. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27483. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27484. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27485. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27486. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27487. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27488. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27489. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27490. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27491. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27492. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27493. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27494. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27495. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27496. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27497. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27498. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27499. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27500. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27501. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27502. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27503. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27504. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27505. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27506. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27507. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27508. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27509. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27510. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27511. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27512. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27513. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27514. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27515. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27516. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27517. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27518. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27519. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27520. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27521. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27522. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27523. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27524. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27525. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27526. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27527. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27528. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27529. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27530. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27531. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27532. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27533. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27534. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27535. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27536. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27537. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27538. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27539. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27540. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27541. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27542. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27543. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27544. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27545. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27546. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27547. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27548. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27549. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27550. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27551. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27552. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27553. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27554. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27555. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27556. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27557. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27558. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27559. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27560. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27561. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27562. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27563. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27564. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27565. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27566. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27567. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27568. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27569. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27570. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27571. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27572. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27573. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27574. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27575. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27576. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27577. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27578. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27579. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27580. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27581. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27582. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27583. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27584. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27585. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27586. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27587. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27588. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27589. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27590. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27591. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27592. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27593. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27594. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27595. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27596. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27597. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27598. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27599. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27600. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27601. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27602. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27603. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27604. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27605. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27606. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27607. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27608. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27609. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27610. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27611. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27612. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27613. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27614. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27615. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27616. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27617. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27618. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27619. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27620. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27621. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27622. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27623. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27624. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27625. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27626. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27627. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27628. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27629. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27630. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27631. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27632. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27633. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27634. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27635. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27636. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27637. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  27638. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  27639. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  27640. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  27641. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  27642. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  27643. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  27644. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  27645. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  27646. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  27647. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  27648. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  27649. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  27650. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  27651. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  27652. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  27653. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  27654. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  27655. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  27656. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  27657. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  27658. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  27659. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  27660. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  27661. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  27662. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  27663. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  27664. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  27665. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  27666. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  27667. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  27668. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  27669. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  27670. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  27671. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  27672. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  27673. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  27674. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  27675. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  27676. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  27677. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  27678. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  27679. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  27680. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  27681. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  27682. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  27683. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  27684. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  27685. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  27686. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  27687. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  27688. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  27689. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  27690. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  27691. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  27692. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  27693. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  27694. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  27695. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  27696. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  27697. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  27698. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  27699. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  27700. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  27701. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  27702. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  27703. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  27704. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  27705. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  27706. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  27707. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  27708. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  27709. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  27710. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  27711. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  27712. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  27713. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  27714. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  27715. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  27716. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  27717. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  27718. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  27719. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  27720. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  27721. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  27722. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  27723. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  27724. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  27725. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  27726. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  27727. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  27728. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  27729. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  27730. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  27731. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  27732. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  27733. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  27734. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  27735. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  27736. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  27737. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  27738. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  27739. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  27740. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  27741. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  27742. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  27743. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  27744. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  27745. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  27746. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  27747. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  27748. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  27749. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  27750. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  27751. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  27752. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  27753. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  27754. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  27755. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  27756. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  27757. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  27758. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  27759. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  27760. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  27761. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  27762. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  27763. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  27764. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  27765. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  27766. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  27767. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  27768. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  27769. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  27770. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  27771. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  27772. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  27773. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  27774. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  27775. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  27776. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  27777. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  27778. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  27779. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  27780. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  27781. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  27782. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  27783. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  27784. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  27785. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  27786. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  27787. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  27788. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  27789. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  27790. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  27791. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  27792. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  27793. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  27794. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  27795. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  27796. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  27797. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  27798. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  27799. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  27800. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  27801. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  27802. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  27803. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  27804. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  27805. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  27806. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  27807. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  27808. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  27809. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  27810. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  27811. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  27812. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  27813. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  27814. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  27815. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  27816. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  27817. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  27818. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  27819. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  27820. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  27821. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  27822. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  27823. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  27824. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  27825. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  27826. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  27827. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  27828. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  27829. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  27830. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  27831. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  27832. };
  27833. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  27834. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  27835. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  27836. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  27837. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  27838. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  27839. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  27840. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  27841. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  27842. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  27843. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  27844. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  27845. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  27846. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  27847. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  27848. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  27849. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  27850. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  27851. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  27852. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  27853. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  27854. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  27855. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  27856. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  27857. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  27858. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  27859. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  27860. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  27861. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  27862. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  27863. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  27864. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  27865. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  27866. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  27867. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  27868. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  27869. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  27870. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  27871. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  27872. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  27873. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  27874. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  27875. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  27876. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  27877. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  27878. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  27879. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  27880. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  27881. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  27882. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  27883. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  27884. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  27885. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  27886. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  27887. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  27888. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  27889. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  27890. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  27891. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  27892. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  27893. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  27894. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  27895. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  27896. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  27897. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  27898. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  27899. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  27900. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  27901. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  27902. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  27903. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  27904. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  27905. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  27906. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  27907. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  27908. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  27909. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  27910. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  27911. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  27912. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  27913. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  27914. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  27915. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  27916. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  27917. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  27918. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  27919. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  27920. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  27921. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  27922. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  27923. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  27924. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  27925. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  27926. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  27927. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  27928. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  27929. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  27930. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  27931. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  27932. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  27933. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  27934. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  27935. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  27936. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  27937. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  27938. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  27939. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  27940. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  27941. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  27942. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  27943. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  27944. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  27945. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  27946. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  27947. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  27948. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  27949. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  27950. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  27951. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  27952. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  27953. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  27954. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  27955. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  27956. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  27957. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  27958. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  27959. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  27960. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  27961. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  27962. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  27963. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  27964. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  27965. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  27966. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  27967. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  27968. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  27969. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  27970. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  27971. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  27972. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  27973. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  27974. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  27975. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  27976. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  27977. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  27978. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  27979. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  27980. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  27981. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  27982. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  27983. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  27984. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  27985. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  27986. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  27987. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  27988. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  27989. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  27990. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  27991. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  27992. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  27993. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  27994. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  27995. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  27996. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  27997. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  27998. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  27999. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  28000. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  28001. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  28002. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  28003. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  28004. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  28005. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  28006. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  28007. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  28008. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  28009. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  28010. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  28011. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  28012. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  28013. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  28014. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  28015. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  28016. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  28017. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  28018. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  28019. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  28020. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  28021. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  28022. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  28023. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  28024. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  28025. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  28026. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  28027. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  28028. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  28029. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  28030. };
  28031. static const byte kprime_1024[KYBER_SS_SZ] = {
  28032. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  28033. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  28034. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  28035. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  28036. };
  28037. #endif
  28038. static byte ss[KYBER_SS_SZ];
  28039. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28040. ExpectNotNull(key);
  28041. if (key != NULL) {
  28042. XMEMSET(key, 0, sizeof(KyberKey));
  28043. }
  28044. #ifndef WOLFSSL_NO_KYBER512
  28045. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  28046. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  28047. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  28048. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  28049. wc_KyberKey_Free(key);
  28050. #endif
  28051. #ifndef WOLFSSL_NO_KYBER768
  28052. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  28053. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  28054. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  28055. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  28056. wc_KyberKey_Free(key);
  28057. #endif
  28058. #ifndef WOLFSSL_NO_KYBER1024
  28059. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  28060. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  28061. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  28062. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  28063. wc_KyberKey_Free(key);
  28064. #endif
  28065. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28066. #endif
  28067. return EXPECT_RESULT();
  28068. }
  28069. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28070. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  28071. static const byte ml_dsa_44_pub_key[] = {
  28072. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  28073. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  28074. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  28075. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  28076. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  28077. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  28078. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  28079. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  28080. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  28081. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  28082. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  28083. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  28084. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  28085. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  28086. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  28087. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  28088. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  28089. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  28090. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  28091. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  28092. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  28093. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  28094. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  28095. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  28096. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  28097. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  28098. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  28099. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  28100. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  28101. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  28102. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  28103. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  28104. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  28105. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  28106. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  28107. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  28108. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  28109. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  28110. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  28111. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  28112. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  28113. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  28114. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  28115. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  28116. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  28117. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  28118. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  28119. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  28120. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  28121. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  28122. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  28123. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  28124. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  28125. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  28126. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  28127. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  28128. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  28129. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  28130. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  28131. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  28132. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  28133. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  28134. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  28135. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  28136. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  28137. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  28138. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  28139. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  28140. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  28141. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  28142. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  28143. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  28144. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  28145. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  28146. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  28147. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  28148. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  28149. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  28150. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  28151. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  28152. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  28153. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  28154. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  28155. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  28156. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  28157. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  28158. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  28159. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  28160. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  28161. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  28162. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  28163. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  28164. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  28165. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  28166. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  28167. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  28168. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  28169. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  28170. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  28171. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  28172. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  28173. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  28174. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  28175. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  28176. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  28177. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  28178. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  28179. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  28180. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  28181. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  28182. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  28183. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  28184. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  28185. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  28186. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  28187. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  28188. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  28189. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  28190. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  28191. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  28192. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  28193. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  28194. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  28195. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  28196. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  28197. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  28198. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  28199. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  28200. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  28201. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  28202. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  28203. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  28204. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  28205. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  28206. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  28207. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  28208. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  28209. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  28210. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  28211. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  28212. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  28213. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  28214. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  28215. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  28216. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  28217. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28218. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28219. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28220. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28221. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28222. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28223. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28224. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28225. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28226. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28227. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28228. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28229. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28230. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28231. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28232. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28233. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28234. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28235. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28236. };
  28237. static const byte ml_dsa_44_good_sig[] = {
  28238. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28239. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28240. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28241. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28242. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28243. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28244. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28245. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28246. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28247. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28248. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28249. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28250. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28251. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28252. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28253. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28254. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28255. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28256. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28257. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28258. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28259. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28260. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28261. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28262. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28263. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28264. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28265. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28266. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28267. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28268. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28269. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28270. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28271. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28272. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28273. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28274. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28275. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28276. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28277. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28278. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28279. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28280. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28281. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28282. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28283. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28284. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28285. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28286. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28287. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28288. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28289. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28290. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28291. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28292. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28293. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28294. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28295. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28296. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28297. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28298. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28299. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28300. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28301. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28302. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28303. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28304. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28305. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28306. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28307. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28308. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28309. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28310. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28311. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28312. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28313. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28314. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28315. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28316. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28317. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28318. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28319. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28320. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28321. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28322. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28323. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28324. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28325. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28326. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28327. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28328. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28329. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28330. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28331. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28332. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28333. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28334. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28335. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28336. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28337. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28338. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28339. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28340. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28341. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28342. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28343. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28344. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28345. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28346. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28347. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28348. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28349. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28350. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28351. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28352. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28353. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28354. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28355. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28356. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28357. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28358. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28359. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28360. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28361. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28362. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28363. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28364. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28365. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28366. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28367. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28368. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28369. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28370. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28371. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28372. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28373. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28374. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28375. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28376. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28377. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28378. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28379. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28380. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28381. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28382. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28383. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28384. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28385. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28386. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28387. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28388. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28389. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28390. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28391. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28392. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28393. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28394. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28395. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28396. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28397. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28398. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28399. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28400. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28401. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28402. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28403. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28404. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28405. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28406. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28407. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28408. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28409. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28410. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28411. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28412. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28413. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28414. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28415. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28416. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28417. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28418. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28419. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28420. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28421. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28422. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28423. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28424. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28425. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28426. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28427. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28428. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28429. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28430. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28431. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28432. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28433. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28434. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28435. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28436. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28437. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28438. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28439. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28440. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28441. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28442. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28443. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28444. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28445. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28446. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28447. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28448. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28449. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28450. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28451. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28452. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28453. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28454. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28455. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28456. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28457. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28458. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28459. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28460. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28461. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28462. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28463. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28464. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28465. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28466. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28467. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28468. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28469. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28470. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28471. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28472. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28473. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28474. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28475. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28476. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28477. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28478. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28479. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28480. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28481. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28482. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28483. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28484. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28485. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28486. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28487. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28488. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28489. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28490. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28491. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28492. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28493. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28494. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28495. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28496. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28497. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28498. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28499. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28500. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28501. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28502. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28503. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28504. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28505. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28506. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28507. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28508. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28509. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28510. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28511. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28512. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28513. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28514. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28515. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28516. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28517. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28518. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28519. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28520. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28521. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28522. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28523. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28524. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28525. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28526. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28527. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28528. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28529. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28530. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28531. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28532. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28533. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28534. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28535. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28536. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28537. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28538. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28539. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28540. 0x0f, 0x20, 0x30, 0x3e
  28541. };
  28542. #endif
  28543. static int test_wc_dilithium(void)
  28544. {
  28545. EXPECT_DECLS;
  28546. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28547. dilithium_key* key;
  28548. byte level;
  28549. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28550. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28551. WC_RNG rng;
  28552. #endif
  28553. byte* privKey = NULL;
  28554. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28555. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28556. #endif
  28557. byte* pubKey = NULL;
  28558. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28559. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28560. #endif
  28561. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28562. ExpectNotNull(key);
  28563. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28564. DYNAMIC_TYPE_TMP_BUFFER);
  28565. ExpectNotNull(privKey);
  28566. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28567. DYNAMIC_TYPE_TMP_BUFFER);
  28568. ExpectNotNull(pubKey);
  28569. if (key != NULL) {
  28570. XMEMSET(key, 0, sizeof(*key));
  28571. }
  28572. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28573. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28574. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28575. #endif
  28576. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28577. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28578. ExpectIntEQ(wc_InitRng(&rng), 0);
  28579. #endif
  28580. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28581. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28582. wc_dilithium_free(NULL);
  28583. ExpectIntEQ(wc_dilithium_init(key), 0);
  28584. wc_dilithium_free(key);
  28585. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28586. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28587. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28588. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28589. #endif
  28590. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28591. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28592. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28593. #endif
  28594. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28595. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28596. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28597. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28598. #endif
  28599. #endif
  28600. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28601. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28602. #endif
  28603. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28604. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28605. #endif
  28606. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28607. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28608. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28609. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28610. #endif
  28611. #endif
  28612. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28613. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28614. #endif
  28615. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28616. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28617. #endif
  28618. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28619. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28620. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28621. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28622. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28623. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28624. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28625. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28626. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28627. #ifndef WOLFSSL_NO_ML_DSA_87
  28628. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28629. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28630. ExpectIntEQ(level, WC_ML_DSA_87);
  28631. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28632. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28633. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28634. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28635. #endif
  28636. #endif
  28637. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28638. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28639. #endif
  28640. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28641. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  28642. #endif
  28643. #else
  28644. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28645. #endif
  28646. #ifndef WOLFSSL_NO_ML_DSA_65
  28647. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28648. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28649. ExpectIntEQ(level, WC_ML_DSA_65);
  28650. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28651. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  28652. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28653. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  28654. #endif
  28655. #endif
  28656. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28657. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28658. #endif
  28659. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28660. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  28661. #endif
  28662. #else
  28663. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28664. #endif
  28665. #ifndef WOLFSSL_NO_ML_DSA_44
  28666. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28667. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28668. ExpectIntEQ(level, WC_ML_DSA_44);
  28669. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28670. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  28671. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28672. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  28673. #endif
  28674. #endif
  28675. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28676. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28677. #endif
  28678. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28679. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  28680. #endif
  28681. #else
  28682. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28683. #endif
  28684. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28685. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28687. #endif
  28688. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28689. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28690. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28691. #endif
  28692. wc_dilithium_free(key);
  28693. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28694. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28695. wc_FreeRng(&rng);
  28696. #endif
  28697. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28698. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28699. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28700. #endif
  28701. return EXPECT_RESULT();
  28702. }
  28703. static int test_wc_dilithium_make_key(void)
  28704. {
  28705. EXPECT_DECLS;
  28706. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28707. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28708. dilithium_key* key;
  28709. WC_RNG rng;
  28710. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28711. ExpectNotNull(key);
  28712. if (key != NULL) {
  28713. XMEMSET(key, 0, sizeof(*key));
  28714. }
  28715. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28716. ExpectIntEQ(wc_InitRng(&rng), 0);
  28717. ExpectIntEQ(wc_dilithium_init(key), 0);
  28718. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  28719. #ifndef WOLFSSL_NO_ML_DSA_44
  28720. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28721. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28722. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28723. #else
  28724. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28725. #endif
  28726. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28727. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28728. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28729. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28730. wc_dilithium_free(key);
  28731. wc_FreeRng(&rng);
  28732. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28733. #endif
  28734. return EXPECT_RESULT();
  28735. }
  28736. static int test_wc_dilithium_sign(void)
  28737. {
  28738. EXPECT_DECLS;
  28739. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28740. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28741. dilithium_key* key;
  28742. dilithium_key* importKey = NULL;
  28743. WC_RNG rng;
  28744. byte* privKey = NULL;
  28745. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28746. word32 badKeyLen;
  28747. byte msg[32];
  28748. byte* sig = NULL;
  28749. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28750. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28751. ExpectNotNull(key);
  28752. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28753. DYNAMIC_TYPE_TMP_BUFFER);
  28754. ExpectNotNull(importKey);
  28755. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28756. DYNAMIC_TYPE_TMP_BUFFER);
  28757. ExpectNotNull(privKey);
  28758. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  28759. DYNAMIC_TYPE_TMP_BUFFER);
  28760. ExpectNotNull(sig);
  28761. if (key != NULL) {
  28762. XMEMSET(key, 0, sizeof(*key));
  28763. }
  28764. if (importKey != NULL) {
  28765. XMEMSET(importKey, 0, sizeof(*importKey));
  28766. }
  28767. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28768. XMEMSET(msg, 0x55, sizeof(msg));
  28769. ExpectIntEQ(wc_InitRng(&rng), 0);
  28770. ExpectIntEQ(wc_dilithium_init(key), 0);
  28771. #ifndef WOLFSSL_NO_ML_DSA_44
  28772. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28773. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28774. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28775. #else
  28776. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28777. #endif
  28778. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  28779. #ifndef WOLFSSL_NO_ML_DSA_44
  28780. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  28781. sizeof_bench_dilithium_level2_key, key), 0);
  28782. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28783. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  28784. sizeof_bench_dilithium_level3_key, key), 0);
  28785. #else
  28786. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  28787. sizeof_bench_dilithium_level5_key, key), 0);
  28788. #endif
  28789. #else
  28790. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28791. #endif
  28792. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  28793. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28794. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  28795. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28796. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  28797. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28798. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  28799. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28800. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  28801. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28802. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  28803. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28804. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  28805. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28806. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  28807. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28808. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  28809. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28810. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  28811. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28812. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  28813. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28814. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28815. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  28816. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28817. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  28818. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28819. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  28820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28821. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  28822. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28823. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  28824. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28825. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  28826. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28827. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  28828. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28829. badKeyLen = 0;
  28830. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  28831. WC_NO_ERR_TRACE(BUFFER_E));
  28832. #ifndef WOLFSSL_NO_ML_DSA_44
  28833. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  28834. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28835. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  28836. #else
  28837. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  28838. #endif
  28839. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28840. 0);
  28841. #ifndef WOLFSSL_NO_ML_DSA_44
  28842. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  28843. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28844. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  28845. #else
  28846. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  28847. #endif
  28848. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  28849. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  28850. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28851. #ifndef WOLFSSL_NO_ML_DSA_44
  28852. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  28853. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28854. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  28855. #else
  28856. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  28857. #endif
  28858. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  28859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28860. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  28861. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28862. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  28863. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28864. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  28865. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28866. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  28867. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28868. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  28869. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28870. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  28871. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28872. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  28873. 0);
  28874. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28875. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  28876. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  28877. #endif
  28878. wc_dilithium_free(importKey);
  28879. wc_dilithium_free(key);
  28880. wc_FreeRng(&rng);
  28881. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28882. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28883. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28884. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28885. #endif
  28886. return EXPECT_RESULT();
  28887. }
  28888. static int test_wc_dilithium_verify(void)
  28889. {
  28890. EXPECT_DECLS;
  28891. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28892. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  28893. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  28894. dilithium_key* key;
  28895. dilithium_key* importKey = NULL;
  28896. WC_RNG rng;
  28897. byte* pubKey = NULL;
  28898. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28899. word32 badKeyLen;
  28900. byte msg[32];
  28901. byte* sig = NULL;
  28902. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28903. int res;
  28904. #ifndef WOLFSSL_NO_ML_DSA_44
  28905. byte b;
  28906. #endif
  28907. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28908. ExpectNotNull(key);
  28909. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28910. DYNAMIC_TYPE_TMP_BUFFER);
  28911. ExpectNotNull(importKey);
  28912. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28913. DYNAMIC_TYPE_TMP_BUFFER);
  28914. ExpectNotNull(pubKey);
  28915. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28916. ExpectNotNull(sig);
  28917. if (key != NULL) {
  28918. XMEMSET(key, 0, sizeof(*key));
  28919. }
  28920. if (importKey != NULL) {
  28921. XMEMSET(importKey, 0, sizeof(*importKey));
  28922. }
  28923. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28924. XMEMSET(msg, 0x55, sizeof(msg));
  28925. ExpectIntEQ(wc_InitRng(&rng), 0);
  28926. ExpectIntEQ(wc_dilithium_init(key), 0);
  28927. #ifndef WOLFSSL_NO_ML_DSA_44
  28928. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28929. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28930. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28931. #else
  28932. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28933. #endif
  28934. #if !defined(WOLFSSL_NO_ML_DSA_44)
  28935. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  28936. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  28937. if (sig != NULL) {
  28938. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  28939. }
  28940. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  28941. #else
  28942. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  28943. #ifndef WOLFSSL_NO_ML_DSA_65
  28944. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  28945. sizeof_bench_dilithium_level3_pub_key, key), 0);
  28946. #else
  28947. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  28948. sizeof_bench_dilithium_level5_pub_key, key), 0);
  28949. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  28950. #else
  28951. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28952. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  28953. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  28954. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  28955. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  28956. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28957. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  28958. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28959. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  28960. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28961. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  28962. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28963. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  28964. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28965. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  28966. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28967. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  28968. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28969. badKeyLen = 0;
  28970. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  28971. WC_NO_ERR_TRACE(BUFFER_E));
  28972. #ifndef WOLFSSL_NO_ML_DSA_44
  28973. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28974. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28975. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28976. #else
  28977. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28978. #endif
  28979. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  28980. #ifndef WOLFSSL_NO_ML_DSA_44
  28981. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28982. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28983. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28984. #else
  28985. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28986. #endif
  28987. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  28988. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28989. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  28990. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28991. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  28992. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28993. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  28994. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28995. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  28996. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28997. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  28998. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28999. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  29000. WC_NO_ERR_TRACE(BUFFER_E));
  29001. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  29002. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29003. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  29004. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29005. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  29006. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29007. res = 0;
  29008. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  29009. ExpectIntEQ(res, 1);
  29010. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29011. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  29012. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29013. #ifndef WOLFSSL_NO_ML_DSA_44
  29014. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29015. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29016. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29017. #else
  29018. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29019. #endif
  29020. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  29021. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29022. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  29023. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29024. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  29025. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29026. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  29027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29028. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  29029. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29030. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  29031. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29032. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  29033. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29034. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  29035. res = 0;
  29036. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  29037. 0);
  29038. ExpectIntEQ(res, 1);
  29039. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29040. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29041. #endif
  29042. wc_dilithium_free(importKey);
  29043. #ifndef WOLFSSL_NO_ML_DSA_44
  29044. if (sig != NULL) {
  29045. if (sig[sigLen - 5] == 0) {
  29046. /* Unused hints meant to be 0. */
  29047. sig[sigLen - 5] = 0xff;
  29048. res = 1;
  29049. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29050. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29051. ExpectIntEQ(res, 0);
  29052. sig[sigLen - 5] = 0x00;
  29053. }
  29054. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  29055. b = sig[sigLen - 1];
  29056. sig[sigLen - 1] = 0xff;
  29057. res = 1;
  29058. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29059. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29060. ExpectIntEQ(res, 0);
  29061. sig[sigLen - 1] = b;
  29062. if (sig[sigLen - 4] > 1) {
  29063. /* Index must be less than previous. */
  29064. b = sig[sigLen - 84];
  29065. sig[sigLen - 84] = 0xff;
  29066. res = 1;
  29067. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29068. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29069. ExpectIntEQ(res, 0);
  29070. sig[sigLen - 84] = b;
  29071. }
  29072. /* Mess up commit hash. */
  29073. sig[0] ^= 0x80;
  29074. res = 1;
  29075. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29076. 0);
  29077. ExpectIntEQ(res, 0);
  29078. sig[0] ^= 0x80;
  29079. /* Mess up z. */
  29080. sig[100] ^= 0x80;
  29081. res = 1;
  29082. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29083. 0);
  29084. ExpectIntEQ(res, 0);
  29085. sig[100] ^= 0x80;
  29086. /* Set all indeces to 0. */
  29087. XMEMSET(sig + sigLen - 4, 0, 4);
  29088. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29089. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29090. ExpectIntEQ(res, 0);
  29091. }
  29092. #endif
  29093. wc_dilithium_free(key);
  29094. wc_FreeRng(&rng);
  29095. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29096. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29097. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29098. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29099. #endif
  29100. return EXPECT_RESULT();
  29101. }
  29102. static int test_wc_dilithium_sign_vfy(void)
  29103. {
  29104. EXPECT_DECLS;
  29105. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29106. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT) && \
  29107. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  29108. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29109. dilithium_key* key;
  29110. WC_RNG rng;
  29111. byte msg[64];
  29112. byte* sig = NULL;
  29113. word32 sigLen;
  29114. byte ctx[10];
  29115. int res;
  29116. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29117. ExpectNotNull(key);
  29118. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29119. ExpectNotNull(sig);
  29120. if (key != NULL) {
  29121. XMEMSET(key, 0, sizeof(*key));
  29122. }
  29123. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29124. XMEMSET(msg, 0xAA, sizeof(msg));
  29125. XMEMSET(ctx, 0x01, sizeof(ctx));
  29126. ExpectIntEQ(wc_InitRng(&rng), 0);
  29127. #ifndef WOLFSSL_NO_ML_DSA_44
  29128. ExpectIntEQ(wc_dilithium_init(key), 0);
  29129. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29130. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29131. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29132. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29133. sig, &sigLen, key, &rng), 0);
  29134. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29135. sizeof(msg), &res, key), 0);
  29136. ExpectIntEQ(res, 1);
  29137. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29138. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29139. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29140. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29141. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29142. ExpectIntEQ(res, 1);
  29143. wc_dilithium_free(key);
  29144. #endif
  29145. #ifndef WOLFSSL_NO_ML_DSA_65
  29146. ExpectIntEQ(wc_dilithium_init(key), 0);
  29147. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29148. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29149. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29150. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29151. sig, &sigLen, key, &rng), 0);
  29152. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29153. sizeof(msg), &res, key), 0);
  29154. ExpectIntEQ(res, 1);
  29155. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29156. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29157. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29158. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29159. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29160. ExpectIntEQ(res, 1);
  29161. wc_dilithium_free(key);
  29162. #endif
  29163. #ifndef WOLFSSL_NO_ML_DSA_87
  29164. ExpectIntEQ(wc_dilithium_init(key), 0);
  29165. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29166. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29167. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29168. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29169. sig, &sigLen, key, &rng), 0);
  29170. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29171. sizeof(msg), &res, key), 0);
  29172. ExpectIntEQ(res, 1);
  29173. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29174. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29175. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29176. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29177. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29178. ExpectIntEQ(res, 1);
  29179. wc_dilithium_free(key);
  29180. #endif
  29181. wc_FreeRng(&rng);
  29182. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29183. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29184. #endif
  29185. return EXPECT_RESULT();
  29186. }
  29187. static int test_wc_dilithium_check_key(void)
  29188. {
  29189. EXPECT_DECLS;
  29190. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29191. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  29192. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29193. dilithium_key* checkKey;
  29194. WC_RNG rng;
  29195. byte* privCheckKey = NULL;
  29196. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29197. byte* pubCheckKey = NULL;
  29198. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29199. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  29200. DYNAMIC_TYPE_TMP_BUFFER);
  29201. ExpectNotNull(checkKey);
  29202. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29203. DYNAMIC_TYPE_TMP_BUFFER);
  29204. ExpectNotNull(privCheckKey);
  29205. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29206. DYNAMIC_TYPE_TMP_BUFFER);
  29207. ExpectNotNull(pubCheckKey);
  29208. if (checkKey != NULL) {
  29209. XMEMSET(checkKey, 0, sizeof(*checkKey));
  29210. }
  29211. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29212. ExpectIntEQ(wc_InitRng(&rng), 0);
  29213. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29214. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  29215. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  29216. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29217. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29218. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29219. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29220. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29221. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29222. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29223. #ifndef WOLFSSL_NO_ML_DSA_44
  29224. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29225. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29226. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29227. #else
  29228. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29229. #endif
  29230. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29231. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29233. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29235. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29237. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29238. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29239. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29241. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29242. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29243. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29244. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29245. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29246. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29247. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29248. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29249. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29250. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29251. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29252. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29253. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29254. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29255. /* Modify hash. */
  29256. if (pubCheckKey != NULL) {
  29257. pubCheckKey[0] ^= 0x80;
  29258. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29260. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29262. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29263. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29264. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29265. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29266. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29267. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29268. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29269. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29270. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29271. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29272. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29273. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29274. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29275. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29276. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29277. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29278. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29279. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29280. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29281. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29282. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29283. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29284. pubCheckKey[0] ^= 0x80;
  29285. /* Modify encoded t1. */
  29286. pubCheckKey[48] ^= 0x80;
  29287. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29288. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29289. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29290. pubCheckKey[48] ^= 0x80;
  29291. }
  29292. wc_dilithium_free(checkKey);
  29293. wc_FreeRng(&rng);
  29294. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29295. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29296. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29297. #endif
  29298. return EXPECT_RESULT();
  29299. }
  29300. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29301. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29302. static const unsigned char dilithium_public_der[] = {
  29303. #ifndef WOLFSSL_NO_ML_DSA_44
  29304. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29305. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29306. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  29307. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  29308. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  29309. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  29310. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  29311. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  29312. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  29313. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  29314. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  29315. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  29316. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  29317. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  29318. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  29319. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  29320. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  29321. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  29322. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  29323. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  29324. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  29325. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  29326. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  29327. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  29328. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  29329. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  29330. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  29331. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  29332. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  29333. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  29334. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  29335. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  29336. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  29337. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  29338. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  29339. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  29340. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  29341. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  29342. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  29343. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  29344. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  29345. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  29346. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  29347. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  29348. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  29349. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  29350. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  29351. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  29352. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  29353. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  29354. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  29355. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  29356. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  29357. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  29358. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  29359. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  29360. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  29361. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  29362. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  29363. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  29364. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  29365. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  29366. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  29367. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  29368. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  29369. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  29370. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  29371. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  29372. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  29373. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  29374. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  29375. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  29376. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  29377. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  29378. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  29379. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  29380. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  29381. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  29382. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  29383. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  29384. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  29385. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  29386. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  29387. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  29388. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  29389. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  29390. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  29391. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  29392. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  29393. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  29394. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  29395. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  29396. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  29397. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  29398. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  29399. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  29400. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  29401. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  29402. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  29403. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  29404. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  29405. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  29406. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  29407. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  29408. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  29409. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  29410. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  29411. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  29412. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  29413. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  29414. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  29415. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  29416. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  29417. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  29418. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  29419. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  29420. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  29421. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  29422. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  29423. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  29424. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  29425. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  29426. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  29427. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  29428. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  29429. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  29430. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  29431. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  29432. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  29433. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  29434. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  29435. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  29436. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  29437. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  29438. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  29439. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  29440. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  29441. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  29442. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  29443. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  29444. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  29445. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  29446. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  29447. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  29448. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  29449. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  29450. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  29451. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  29452. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  29453. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  29454. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  29455. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  29456. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  29457. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  29458. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  29459. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  29460. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  29461. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  29462. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  29463. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  29464. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  29465. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  29466. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  29467. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  29468. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  29469. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  29470. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  29471. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29472. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  29473. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29474. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29475. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  29476. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  29477. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  29478. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  29479. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  29480. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  29481. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  29482. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  29483. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  29484. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  29485. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  29486. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  29487. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  29488. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  29489. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  29490. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  29491. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  29492. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  29493. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  29494. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  29495. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  29496. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  29497. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  29498. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  29499. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  29500. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  29501. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  29502. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  29503. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  29504. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  29505. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  29506. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  29507. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  29508. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  29509. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  29510. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  29511. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  29512. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  29513. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  29514. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  29515. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  29516. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  29517. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  29518. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  29519. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  29520. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  29521. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  29522. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  29523. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  29524. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  29525. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  29526. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  29527. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  29528. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  29529. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  29530. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  29531. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  29532. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  29533. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  29534. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  29535. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  29536. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  29537. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  29538. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  29539. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  29540. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  29541. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  29542. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  29543. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  29544. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  29545. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  29546. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  29547. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  29548. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  29549. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  29550. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  29551. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  29552. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  29553. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  29554. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  29555. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  29556. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  29557. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  29558. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  29559. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  29560. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  29561. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  29562. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  29563. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  29564. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  29565. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  29566. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  29567. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  29568. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  29569. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  29570. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  29571. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  29572. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  29573. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  29574. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  29575. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  29576. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  29577. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  29578. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  29579. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  29580. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  29581. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  29582. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  29583. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  29584. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  29585. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  29586. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  29587. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  29588. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  29589. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  29590. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  29591. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  29592. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  29593. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  29594. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  29595. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  29596. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  29597. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  29598. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  29599. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  29600. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  29601. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  29602. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  29603. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  29604. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  29605. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  29606. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  29607. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  29608. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  29609. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  29610. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  29611. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  29612. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  29613. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  29614. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  29615. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  29616. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  29617. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  29618. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  29619. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  29620. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  29621. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  29622. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  29623. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  29624. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  29625. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  29626. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  29627. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  29628. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  29629. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  29630. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  29631. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  29632. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  29633. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  29634. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  29635. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  29636. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  29637. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  29638. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  29639. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  29640. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  29641. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  29642. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  29643. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  29644. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  29645. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  29646. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  29647. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  29648. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  29649. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  29650. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  29651. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  29652. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  29653. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  29654. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  29655. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  29656. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  29657. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  29658. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  29659. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  29660. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  29661. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  29662. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  29663. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  29664. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  29665. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  29666. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  29667. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  29668. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  29669. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  29670. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  29671. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  29672. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  29673. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  29674. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  29675. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  29676. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  29677. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  29678. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  29679. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  29680. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  29681. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  29682. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  29683. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  29684. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  29685. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  29686. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  29687. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  29688. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  29689. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  29690. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  29691. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  29692. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  29693. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  29694. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  29695. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  29696. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  29697. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  29698. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  29699. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  29700. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  29701. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  29702. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  29703. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  29704. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  29705. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  29706. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  29707. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  29708. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  29709. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  29710. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  29711. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  29712. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  29713. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  29714. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  29715. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  29716. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  29717. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  29718. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  29719. #else
  29720. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29721. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29722. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  29723. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  29724. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  29725. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  29726. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  29727. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  29728. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  29729. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  29730. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  29731. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  29732. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  29733. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  29734. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  29735. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  29736. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  29737. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  29738. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  29739. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  29740. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  29741. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  29742. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  29743. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  29744. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  29745. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  29746. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  29747. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  29748. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  29749. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  29750. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  29751. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  29752. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  29753. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  29754. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  29755. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  29756. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  29757. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  29758. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  29759. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  29760. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  29761. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  29762. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  29763. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  29764. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  29765. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  29766. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  29767. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  29768. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  29769. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  29770. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  29771. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  29772. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  29773. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  29774. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  29775. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  29776. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  29777. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  29778. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  29779. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  29780. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  29781. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  29782. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  29783. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  29784. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  29785. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  29786. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  29787. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  29788. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  29789. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  29790. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  29791. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  29792. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  29793. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  29794. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  29795. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  29796. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  29797. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  29798. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  29799. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  29800. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  29801. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  29802. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  29803. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  29804. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  29805. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  29806. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  29807. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  29808. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  29809. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  29810. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  29811. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  29812. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  29813. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  29814. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  29815. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  29816. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  29817. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  29818. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  29819. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  29820. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  29821. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  29822. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  29823. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  29824. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  29825. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  29826. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  29827. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  29828. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  29829. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  29830. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  29831. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  29832. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  29833. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  29834. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  29835. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  29836. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  29837. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  29838. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  29839. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  29840. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  29841. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  29842. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  29843. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  29844. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  29845. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  29846. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  29847. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  29848. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  29849. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  29850. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  29851. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  29852. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  29853. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  29854. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  29855. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  29856. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  29857. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  29858. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  29859. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  29860. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  29861. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  29862. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  29863. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  29864. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  29865. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  29866. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  29867. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  29868. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  29869. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  29870. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  29871. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  29872. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  29873. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  29874. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  29875. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  29876. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  29877. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  29878. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  29879. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  29880. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  29881. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  29882. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  29883. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  29884. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  29885. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  29886. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  29887. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  29888. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  29889. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  29890. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  29891. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  29892. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  29893. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  29894. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  29895. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  29896. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  29897. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  29898. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  29899. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  29900. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  29901. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  29902. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  29903. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  29904. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  29905. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  29906. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  29907. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  29908. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  29909. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  29910. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  29911. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  29912. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  29913. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  29914. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  29915. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  29916. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  29917. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  29918. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  29919. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  29920. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  29921. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  29922. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  29923. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  29924. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  29925. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  29926. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  29927. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  29928. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  29929. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  29930. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  29931. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  29932. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  29933. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  29934. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  29935. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  29936. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  29937. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  29938. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  29939. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  29940. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  29941. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  29942. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  29943. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  29944. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  29945. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  29946. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  29947. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  29948. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  29949. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  29950. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  29951. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  29952. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  29953. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  29954. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  29955. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  29956. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  29957. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  29958. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  29959. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  29960. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  29961. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  29962. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  29963. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  29964. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  29965. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  29966. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  29967. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  29968. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  29969. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  29970. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  29971. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  29972. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  29973. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  29974. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  29975. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  29976. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  29977. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  29978. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  29979. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  29980. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  29981. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  29982. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  29983. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  29984. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  29985. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  29986. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  29987. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  29988. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  29989. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  29990. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  29991. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  29992. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  29993. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  29994. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  29995. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  29996. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  29997. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  29998. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  29999. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  30000. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  30001. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  30002. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  30003. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  30004. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  30005. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  30006. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  30007. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  30008. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  30009. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  30010. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  30011. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  30012. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  30013. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  30014. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  30015. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  30016. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  30017. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  30018. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  30019. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  30020. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  30021. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  30022. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  30023. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  30024. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  30025. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  30026. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  30027. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  30028. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  30029. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  30030. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  30031. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  30032. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  30033. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  30034. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  30035. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  30036. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  30037. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  30038. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  30039. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  30040. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  30041. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  30042. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  30043. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  30044. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  30045. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  30046. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  30047. #endif
  30048. };
  30049. #endif
  30050. static int test_wc_dilithium_public_der_decode(void)
  30051. {
  30052. EXPECT_DECLS;
  30053. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30054. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  30055. dilithium_key* key;
  30056. word32 idx = 0;
  30057. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30058. ExpectNotNull(key);
  30059. if (key != NULL) {
  30060. XMEMSET(key, 0, sizeof(*key));
  30061. }
  30062. ExpectIntEQ(wc_dilithium_init(key), 0);
  30063. #ifndef WOLFSSL_NO_ML_DSA_44
  30064. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30065. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30066. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30067. #else
  30068. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30069. #endif
  30070. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  30071. (word32)sizeof(dilithium_public_der)), 0);
  30072. wc_dilithium_free(key);
  30073. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30074. #endif
  30075. return EXPECT_RESULT();
  30076. }
  30077. static int test_wc_dilithium_der(void)
  30078. {
  30079. EXPECT_DECLS;
  30080. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30081. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  30082. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30083. #define DILITHIUM_MAX_DER_SIZE 8192
  30084. dilithium_key* key;
  30085. WC_RNG rng;
  30086. byte* der = NULL;
  30087. int len;
  30088. int pubLen;
  30089. int pubDerLen;
  30090. int privDerLen;
  30091. int keyDerLen;
  30092. word32 idx;
  30093. #ifndef WOLFSSL_NO_ML_DSA_44
  30094. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  30095. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 24;
  30096. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 30;
  30097. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 34;
  30098. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30099. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  30100. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 24;
  30101. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 30;
  30102. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 34;
  30103. #else
  30104. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  30105. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 24;
  30106. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 30;
  30107. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 34;
  30108. #endif
  30109. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30110. ExpectNotNull(key);
  30111. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30112. ExpectNotNull(der);
  30113. if (key != NULL) {
  30114. XMEMSET(key, 0, sizeof(*key));
  30115. }
  30116. XMEMSET(&rng, 0, sizeof(WC_RNG));
  30117. ExpectIntEQ(wc_InitRng(&rng), 0);
  30118. ExpectIntEQ(wc_dilithium_init(key), 0);
  30119. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30120. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30121. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30122. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30123. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30124. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30125. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  30126. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30127. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  30128. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30129. #ifndef WOLFSSL_NO_ML_DSA_44
  30130. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30131. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30132. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30133. #else
  30134. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30135. #endif
  30136. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30137. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30138. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30139. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30140. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30141. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30142. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  30143. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  30144. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30145. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  30146. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30147. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  30148. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30149. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  30150. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30151. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  30152. 0), WC_NO_ERR_TRACE(BUFFER_E));
  30153. /* Get length only. */
  30154. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30155. 0), pubLen);
  30156. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30157. 0), pubLen);
  30158. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30159. 1), pubDerLen);
  30160. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30161. 1), pubDerLen);
  30162. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30163. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30164. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30165. 0 ), 0);
  30166. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30167. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30168. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30169. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30170. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30171. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30172. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  30173. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  30174. /* Get length only. */
  30175. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30176. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30177. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  30178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30179. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  30180. 0 );
  30181. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  30182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30183. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  30184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30185. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  30186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30187. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  30188. WC_NO_ERR_TRACE(BUFFER_E));
  30189. /* Get length only. */
  30190. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  30191. keyDerLen);
  30192. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  30193. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30194. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  30195. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30196. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  30197. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30198. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  30199. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30200. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  30201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30202. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  30203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30204. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  30205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30206. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  30207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30208. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  30209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30210. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  30211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30212. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  30213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30214. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  30215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30216. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  30217. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30218. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  30219. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30220. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  30221. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30222. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  30223. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30224. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  30225. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30226. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  30227. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30228. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30229. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  30230. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  30231. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30232. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  30233. idx = 0;
  30234. {
  30235. fprintf(stderr, "\n");
  30236. for (int ii = 0; ii < pubDerLen; ii++) {
  30237. if ((ii % 8) == 0) fprintf(stderr, " ");
  30238. fprintf(stderr, "0x%02x,", der[ii]);
  30239. if ((ii % 8) == 7) fprintf(stderr, "\n");
  30240. else fprintf(stderr, " ");
  30241. }
  30242. }
  30243. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  30244. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  30245. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30246. idx = 0;
  30247. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30248. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30249. keyDerLen);
  30250. idx = 0;
  30251. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30252. wc_dilithium_free(key);
  30253. wc_FreeRng(&rng);
  30254. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30255. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30256. #endif
  30257. return EXPECT_RESULT();
  30258. }
  30259. static int test_wc_dilithium_make_key_from_seed(void)
  30260. {
  30261. EXPECT_DECLS;
  30262. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30263. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30264. dilithium_key* key;
  30265. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30266. #ifndef WOLFSSL_NO_ML_DSA_44
  30267. static const byte seed_44[] = {
  30268. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  30269. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  30270. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  30271. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  30272. };
  30273. static const byte pk_44[] = {
  30274. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30275. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30276. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30277. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30278. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  30279. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  30280. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  30281. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  30282. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  30283. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  30284. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  30285. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  30286. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  30287. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  30288. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  30289. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  30290. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  30291. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  30292. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  30293. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  30294. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  30295. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  30296. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  30297. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  30298. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  30299. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  30300. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  30301. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  30302. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  30303. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  30304. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  30305. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  30306. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  30307. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  30308. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  30309. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  30310. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  30311. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  30312. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  30313. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  30314. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  30315. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  30316. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  30317. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  30318. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  30319. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  30320. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  30321. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  30322. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  30323. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  30324. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  30325. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  30326. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  30327. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  30328. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  30329. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  30330. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  30331. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  30332. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  30333. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  30334. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  30335. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  30336. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  30337. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  30338. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  30339. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  30340. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  30341. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  30342. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  30343. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  30344. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  30345. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  30346. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  30347. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  30348. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  30349. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  30350. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  30351. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  30352. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  30353. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  30354. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  30355. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  30356. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  30357. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  30358. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  30359. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  30360. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  30361. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  30362. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  30363. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  30364. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  30365. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  30366. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  30367. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  30368. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  30369. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  30370. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  30371. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  30372. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  30373. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  30374. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  30375. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  30376. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  30377. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  30378. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  30379. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  30380. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  30381. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  30382. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  30383. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  30384. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  30385. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  30386. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  30387. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  30388. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  30389. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  30390. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  30391. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  30392. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  30393. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  30394. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  30395. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  30396. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  30397. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  30398. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  30399. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  30400. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  30401. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  30402. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  30403. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  30404. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  30405. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  30406. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  30407. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  30408. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  30409. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  30410. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  30411. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  30412. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  30413. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  30414. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  30415. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  30416. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  30417. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  30418. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  30419. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  30420. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  30421. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  30422. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  30423. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  30424. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  30425. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  30426. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  30427. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  30428. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  30429. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  30430. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  30431. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  30432. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  30433. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  30434. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  30435. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  30436. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  30437. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  30438. };
  30439. static const byte sk_44[] = {
  30440. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30441. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30442. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30443. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30444. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  30445. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  30446. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  30447. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  30448. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  30449. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  30450. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  30451. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  30452. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  30453. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  30454. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  30455. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  30456. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  30457. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  30458. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  30459. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  30460. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  30461. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  30462. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  30463. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  30464. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  30465. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  30466. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  30467. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  30468. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  30469. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  30470. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  30471. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  30472. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  30473. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  30474. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  30475. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  30476. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  30477. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  30478. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  30479. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  30480. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  30481. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  30482. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  30483. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  30484. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  30485. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  30486. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  30487. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  30488. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  30489. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  30490. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  30491. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  30492. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  30493. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  30494. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  30495. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  30496. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  30497. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  30498. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  30499. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  30500. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  30501. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  30502. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  30503. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  30504. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  30505. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  30506. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  30507. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  30508. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  30509. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  30510. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  30511. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  30512. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  30513. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  30514. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  30515. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  30516. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  30517. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  30518. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  30519. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  30520. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  30521. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  30522. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  30523. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  30524. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  30525. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  30526. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  30527. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  30528. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  30529. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  30530. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  30531. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  30532. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  30533. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  30534. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  30535. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  30536. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  30537. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  30538. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  30539. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  30540. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  30541. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  30542. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  30543. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  30544. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  30545. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  30546. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  30547. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  30548. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  30549. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  30550. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  30551. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  30552. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  30553. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  30554. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  30555. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  30556. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  30557. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  30558. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  30559. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  30560. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  30561. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  30562. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  30563. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  30564. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  30565. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  30566. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  30567. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  30568. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  30569. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  30570. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  30571. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  30572. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  30573. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  30574. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  30575. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  30576. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  30577. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  30578. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  30579. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  30580. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  30581. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  30582. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  30583. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  30584. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  30585. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  30586. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  30587. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  30588. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  30589. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  30590. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  30591. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  30592. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  30593. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  30594. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  30595. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  30596. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  30597. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  30598. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  30599. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  30600. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  30601. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  30602. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  30603. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  30604. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  30605. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  30606. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  30607. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  30608. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  30609. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  30610. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  30611. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  30612. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  30613. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  30614. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  30615. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  30616. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  30617. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  30618. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  30619. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  30620. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  30621. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  30622. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  30623. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  30624. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  30625. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  30626. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  30627. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  30628. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  30629. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  30630. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  30631. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  30632. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  30633. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  30634. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  30635. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  30636. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  30637. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  30638. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  30639. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  30640. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  30641. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  30642. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  30643. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  30644. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  30645. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  30646. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  30647. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  30648. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  30649. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  30650. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  30651. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  30652. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  30653. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  30654. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  30655. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  30656. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  30657. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  30658. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  30659. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  30660. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  30661. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  30662. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  30663. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  30664. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  30665. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  30666. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  30667. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  30668. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  30669. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  30670. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  30671. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  30672. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  30673. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  30674. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  30675. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  30676. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  30677. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  30678. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  30679. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  30680. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  30681. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  30682. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  30683. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  30684. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  30685. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  30686. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  30687. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  30688. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  30689. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  30690. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  30691. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  30692. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  30693. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  30694. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  30695. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  30696. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  30697. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  30698. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  30699. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  30700. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  30701. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  30702. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  30703. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  30704. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  30705. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  30706. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  30707. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  30708. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  30709. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  30710. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  30711. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  30712. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  30713. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  30714. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  30715. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  30716. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  30717. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  30718. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  30719. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  30720. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  30721. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  30722. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  30723. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  30724. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  30725. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  30726. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  30727. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  30728. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  30729. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  30730. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  30731. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  30732. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  30733. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  30734. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  30735. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  30736. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  30737. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  30738. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  30739. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  30740. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  30741. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  30742. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  30743. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  30744. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  30745. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  30746. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  30747. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  30748. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  30749. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  30750. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  30751. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  30752. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  30753. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  30754. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  30755. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  30756. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  30757. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  30758. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  30759. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  30760. };
  30761. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  30762. #ifndef WOLFSSL_NO_ML_DSA_65
  30763. static const byte seed_65[] = {
  30764. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  30765. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  30766. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  30767. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  30768. };
  30769. static const byte pk_65[] = {
  30770. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  30771. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  30772. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  30773. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  30774. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  30775. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  30776. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  30777. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  30778. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  30779. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  30780. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  30781. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  30782. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  30783. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  30784. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  30785. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  30786. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  30787. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  30788. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  30789. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  30790. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  30791. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  30792. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  30793. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  30794. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  30795. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  30796. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  30797. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  30798. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  30799. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  30800. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  30801. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  30802. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  30803. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  30804. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  30805. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  30806. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  30807. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  30808. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  30809. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  30810. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  30811. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  30812. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  30813. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  30814. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  30815. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  30816. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  30817. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  30818. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  30819. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  30820. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  30821. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  30822. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  30823. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  30824. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  30825. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  30826. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  30827. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  30828. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  30829. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  30830. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  30831. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  30832. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  30833. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  30834. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  30835. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  30836. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  30837. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  30838. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  30839. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  30840. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  30841. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  30842. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  30843. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  30844. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  30845. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  30846. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  30847. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  30848. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  30849. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  30850. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  30851. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  30852. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  30853. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  30854. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  30855. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  30856. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  30857. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  30858. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  30859. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  30860. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  30861. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  30862. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  30863. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  30864. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  30865. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  30866. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  30867. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  30868. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  30869. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  30870. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  30871. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  30872. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  30873. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  30874. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  30875. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  30876. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  30877. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  30878. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  30879. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  30880. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  30881. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  30882. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  30883. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  30884. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  30885. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  30886. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  30887. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  30888. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  30889. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  30890. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  30891. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  30892. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  30893. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  30894. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  30895. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  30896. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  30897. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  30898. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  30899. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  30900. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  30901. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  30902. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  30903. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  30904. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  30905. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  30906. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  30907. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  30908. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  30909. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  30910. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  30911. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  30912. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  30913. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  30914. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  30915. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  30916. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  30917. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  30918. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  30919. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  30920. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  30921. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  30922. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  30923. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  30924. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  30925. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  30926. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  30927. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  30928. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  30929. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  30930. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  30931. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  30932. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  30933. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  30934. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  30935. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  30936. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  30937. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  30938. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  30939. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  30940. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  30941. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  30942. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  30943. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  30944. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  30945. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  30946. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  30947. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  30948. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  30949. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  30950. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  30951. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  30952. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  30953. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  30954. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  30955. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  30956. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  30957. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  30958. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  30959. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  30960. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  30961. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  30962. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  30963. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  30964. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  30965. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  30966. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  30967. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  30968. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  30969. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  30970. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  30971. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  30972. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  30973. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  30974. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  30975. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  30976. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  30977. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  30978. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  30979. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  30980. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  30981. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  30982. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  30983. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  30984. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  30985. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  30986. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  30987. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  30988. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  30989. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  30990. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  30991. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  30992. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  30993. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  30994. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  30995. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  30996. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  30997. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  30998. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  30999. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  31000. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  31001. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  31002. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  31003. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  31004. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  31005. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  31006. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  31007. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  31008. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  31009. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  31010. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  31011. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  31012. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  31013. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  31014. };
  31015. static const byte sk_65[] = {
  31016. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31017. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31018. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31019. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31020. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  31021. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  31022. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  31023. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  31024. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  31025. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  31026. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  31027. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  31028. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  31029. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  31030. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  31031. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  31032. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  31033. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  31034. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  31035. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  31036. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  31037. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  31038. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  31039. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  31040. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  31041. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  31042. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  31043. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  31044. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  31045. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  31046. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  31047. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  31048. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  31049. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  31050. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  31051. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  31052. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  31053. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  31054. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  31055. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  31056. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  31057. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  31058. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  31059. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  31060. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  31061. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  31062. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  31063. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  31064. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  31065. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  31066. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  31067. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  31068. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  31069. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  31070. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  31071. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  31072. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  31073. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  31074. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  31075. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  31076. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  31077. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  31078. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  31079. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  31080. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  31081. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  31082. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  31083. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  31084. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  31085. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  31086. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  31087. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  31088. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  31089. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  31090. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  31091. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  31092. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  31093. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  31094. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  31095. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  31096. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  31097. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  31098. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  31099. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  31100. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  31101. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  31102. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  31103. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  31104. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  31105. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  31106. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  31107. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  31108. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  31109. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  31110. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  31111. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  31112. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  31113. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  31114. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  31115. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  31116. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  31117. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  31118. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  31119. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  31120. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  31121. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  31122. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  31123. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  31124. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  31125. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  31126. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  31127. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  31128. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  31129. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  31130. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  31131. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  31132. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  31133. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  31134. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  31135. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  31136. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  31137. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  31138. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  31139. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  31140. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  31141. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  31142. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  31143. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  31144. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  31145. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  31146. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  31147. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  31148. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  31149. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  31150. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  31151. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  31152. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  31153. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  31154. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  31155. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  31156. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  31157. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  31158. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  31159. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  31160. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  31161. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  31162. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  31163. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  31164. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  31165. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  31166. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  31167. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  31168. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  31169. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  31170. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  31171. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  31172. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  31173. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  31174. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  31175. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  31176. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  31177. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  31178. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  31179. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  31180. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  31181. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  31182. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  31183. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  31184. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  31185. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  31186. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  31187. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  31188. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  31189. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  31190. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  31191. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  31192. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  31193. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  31194. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  31195. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  31196. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  31197. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  31198. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  31199. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  31200. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  31201. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  31202. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  31203. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  31204. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  31205. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  31206. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  31207. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  31208. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  31209. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  31210. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  31211. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  31212. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  31213. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  31214. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  31215. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  31216. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  31217. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  31218. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  31219. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  31220. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  31221. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  31222. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  31223. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  31224. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  31225. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  31226. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  31227. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  31228. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  31229. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  31230. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  31231. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  31232. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  31233. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  31234. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  31235. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  31236. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  31237. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  31238. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  31239. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  31240. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  31241. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  31242. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  31243. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  31244. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  31245. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  31246. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  31247. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  31248. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  31249. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  31250. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  31251. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  31252. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  31253. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  31254. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  31255. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  31256. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  31257. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  31258. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  31259. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  31260. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  31261. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  31262. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  31263. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  31264. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  31265. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  31266. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  31267. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  31268. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  31269. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  31270. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  31271. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  31272. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  31273. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  31274. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  31275. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  31276. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  31277. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  31278. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  31279. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  31280. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  31281. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  31282. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  31283. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  31284. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  31285. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  31286. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  31287. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  31288. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  31289. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  31290. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  31291. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  31292. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  31293. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  31294. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  31295. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  31296. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  31297. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  31298. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  31299. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  31300. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  31301. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  31302. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  31303. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  31304. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  31305. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  31306. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  31307. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  31308. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  31309. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  31310. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  31311. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  31312. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  31313. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  31314. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  31315. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  31316. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  31317. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  31318. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  31319. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  31320. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  31321. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  31322. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  31323. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  31324. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  31325. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  31326. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  31327. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  31328. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  31329. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  31330. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  31331. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  31332. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  31333. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  31334. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  31335. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  31336. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  31337. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  31338. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  31339. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  31340. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  31341. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  31342. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  31343. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  31344. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  31345. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  31346. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  31347. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  31348. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  31349. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  31350. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  31351. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  31352. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  31353. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  31354. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  31355. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  31356. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  31357. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  31358. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  31359. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  31360. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  31361. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  31362. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  31363. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  31364. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  31365. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  31366. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  31367. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  31368. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  31369. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  31370. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  31371. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  31372. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  31373. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  31374. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  31375. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  31376. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  31377. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  31378. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  31379. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  31380. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  31381. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  31382. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  31383. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  31384. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  31385. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  31386. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  31387. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  31388. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  31389. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  31390. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  31391. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  31392. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  31393. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  31394. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  31395. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  31396. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  31397. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  31398. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  31399. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  31400. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  31401. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  31402. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  31403. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  31404. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  31405. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  31406. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  31407. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  31408. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  31409. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  31410. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  31411. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  31412. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  31413. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  31414. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  31415. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  31416. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  31417. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  31418. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  31419. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  31420. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  31421. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  31422. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  31423. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  31424. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  31425. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  31426. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  31427. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  31428. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  31429. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  31430. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  31431. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  31432. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  31433. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  31434. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  31435. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  31436. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  31437. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  31438. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  31439. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  31440. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  31441. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  31442. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  31443. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  31444. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  31445. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  31446. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  31447. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  31448. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  31449. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  31450. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  31451. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  31452. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  31453. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  31454. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  31455. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  31456. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  31457. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  31458. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  31459. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  31460. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  31461. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  31462. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  31463. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  31464. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  31465. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  31466. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  31467. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  31468. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  31469. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  31470. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  31471. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  31472. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  31473. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  31474. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  31475. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  31476. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  31477. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  31478. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  31479. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  31480. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  31481. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  31482. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  31483. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  31484. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  31485. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  31486. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  31487. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  31488. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  31489. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  31490. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  31491. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  31492. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  31493. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  31494. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  31495. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  31496. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  31497. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  31498. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  31499. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  31500. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  31501. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  31502. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  31503. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  31504. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  31505. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  31506. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  31507. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  31508. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  31509. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  31510. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  31511. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  31512. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  31513. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  31514. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  31515. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  31516. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  31517. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  31518. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  31519. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  31520. };
  31521. #endif /* WOLFSSL_NO_ML_DSA_65 */
  31522. #ifndef WOLFSSL_NO_ML_DSA_87
  31523. static const byte seed_87[] = {
  31524. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  31525. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  31526. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  31527. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  31528. };
  31529. static const byte pk_87[] = {
  31530. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31531. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31532. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31533. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31534. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  31535. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  31536. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  31537. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  31538. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  31539. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  31540. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  31541. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  31542. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  31543. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  31544. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  31545. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  31546. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  31547. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  31548. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  31549. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  31550. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  31551. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  31552. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  31553. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  31554. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  31555. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  31556. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  31557. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  31558. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  31559. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  31560. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  31561. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  31562. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  31563. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  31564. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  31565. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  31566. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  31567. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  31568. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  31569. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  31570. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  31571. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  31572. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  31573. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  31574. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  31575. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  31576. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  31577. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  31578. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  31579. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  31580. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  31581. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  31582. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  31583. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  31584. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  31585. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  31586. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  31587. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  31588. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  31589. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  31590. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  31591. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  31592. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  31593. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  31594. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  31595. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  31596. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  31597. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  31598. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  31599. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  31600. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  31601. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  31602. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  31603. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  31604. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  31605. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  31606. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  31607. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  31608. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  31609. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  31610. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  31611. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  31612. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  31613. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  31614. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  31615. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  31616. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  31617. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  31618. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  31619. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  31620. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  31621. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  31622. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  31623. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  31624. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  31625. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  31626. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  31627. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  31628. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  31629. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  31630. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  31631. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  31632. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  31633. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  31634. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  31635. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  31636. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  31637. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  31638. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  31639. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  31640. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  31641. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  31642. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  31643. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  31644. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  31645. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  31646. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  31647. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  31648. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  31649. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  31650. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  31651. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  31652. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  31653. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  31654. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  31655. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  31656. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  31657. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  31658. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  31659. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  31660. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  31661. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  31662. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  31663. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  31664. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  31665. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  31666. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  31667. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  31668. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  31669. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  31670. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  31671. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  31672. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  31673. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  31674. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  31675. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  31676. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  31677. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  31678. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  31679. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  31680. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  31681. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  31682. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  31683. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  31684. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  31685. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  31686. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  31687. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  31688. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  31689. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  31690. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  31691. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  31692. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  31693. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  31694. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  31695. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  31696. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  31697. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  31698. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  31699. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  31700. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  31701. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  31702. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  31703. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  31704. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  31705. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  31706. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  31707. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  31708. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  31709. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  31710. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  31711. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  31712. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  31713. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  31714. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  31715. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  31716. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  31717. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  31718. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  31719. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  31720. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  31721. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  31722. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  31723. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  31724. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  31725. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  31726. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  31727. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  31728. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  31729. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  31730. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  31731. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  31732. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  31733. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  31734. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  31735. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  31736. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  31737. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  31738. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  31739. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  31740. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  31741. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  31742. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  31743. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  31744. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  31745. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  31746. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  31747. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  31748. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  31749. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  31750. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  31751. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  31752. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  31753. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  31754. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  31755. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  31756. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  31757. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  31758. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  31759. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  31760. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  31761. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  31762. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  31763. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  31764. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  31765. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  31766. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  31767. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  31768. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  31769. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  31770. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  31771. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  31772. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  31773. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  31774. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  31775. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  31776. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  31777. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  31778. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  31779. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  31780. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  31781. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  31782. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  31783. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  31784. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  31785. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  31786. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  31787. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  31788. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  31789. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  31790. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  31791. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  31792. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  31793. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  31794. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  31795. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  31796. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  31797. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  31798. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  31799. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  31800. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  31801. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  31802. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  31803. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  31804. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  31805. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  31806. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  31807. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  31808. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  31809. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  31810. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  31811. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  31812. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  31813. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  31814. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  31815. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  31816. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  31817. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  31818. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  31819. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  31820. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  31821. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  31822. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  31823. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  31824. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  31825. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  31826. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  31827. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  31828. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  31829. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  31830. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  31831. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  31832. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  31833. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  31834. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  31835. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  31836. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  31837. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  31838. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  31839. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  31840. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  31841. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  31842. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  31843. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  31844. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  31845. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  31846. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  31847. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  31848. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  31849. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  31850. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  31851. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  31852. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  31853. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  31854. };
  31855. static const byte sk_87[] = {
  31856. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31857. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31858. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31859. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31860. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  31861. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  31862. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  31863. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  31864. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  31865. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  31866. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  31867. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  31868. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  31869. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  31870. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  31871. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  31872. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  31873. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  31874. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  31875. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  31876. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  31877. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  31878. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  31879. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  31880. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  31881. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  31882. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  31883. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  31884. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  31885. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  31886. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  31887. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  31888. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  31889. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  31890. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  31891. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  31892. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  31893. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  31894. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  31895. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  31896. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  31897. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  31898. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  31899. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  31900. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  31901. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  31902. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  31903. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  31904. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  31905. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  31906. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  31907. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  31908. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  31909. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  31910. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  31911. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  31912. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  31913. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  31914. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  31915. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  31916. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  31917. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  31918. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  31919. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  31920. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  31921. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  31922. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  31923. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  31924. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  31925. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  31926. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  31927. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  31928. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  31929. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  31930. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  31931. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  31932. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  31933. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  31934. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  31935. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  31936. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  31937. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  31938. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  31939. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  31940. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  31941. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  31942. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  31943. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  31944. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  31945. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  31946. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  31947. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  31948. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  31949. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  31950. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  31951. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  31952. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  31953. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  31954. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  31955. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  31956. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  31957. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  31958. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  31959. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  31960. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  31961. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  31962. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  31963. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  31964. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  31965. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  31966. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  31967. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  31968. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  31969. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  31970. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  31971. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  31972. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  31973. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  31974. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  31975. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  31976. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  31977. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  31978. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  31979. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  31980. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  31981. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  31982. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  31983. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  31984. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  31985. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  31986. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  31987. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  31988. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  31989. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  31990. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  31991. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  31992. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  31993. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  31994. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  31995. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  31996. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  31997. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  31998. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  31999. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  32000. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  32001. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  32002. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  32003. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  32004. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  32005. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  32006. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  32007. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  32008. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  32009. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  32010. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  32011. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  32012. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  32013. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  32014. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  32015. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  32016. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  32017. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  32018. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  32019. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  32020. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  32021. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  32022. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  32023. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  32024. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  32025. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  32026. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  32027. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  32028. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  32029. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  32030. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  32031. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  32032. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  32033. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  32034. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  32035. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  32036. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  32037. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  32038. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  32039. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  32040. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  32041. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  32042. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  32043. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  32044. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  32045. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  32046. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  32047. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  32048. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  32049. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  32050. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  32051. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  32052. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  32053. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  32054. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  32055. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  32056. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  32057. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  32058. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  32059. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  32060. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  32061. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  32062. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  32063. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  32064. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  32065. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  32066. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  32067. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  32068. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  32069. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  32070. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  32071. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  32072. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  32073. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  32074. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  32075. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  32076. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  32077. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  32078. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  32079. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  32080. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  32081. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  32082. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  32083. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  32084. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  32085. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  32086. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  32087. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  32088. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  32089. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  32090. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  32091. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  32092. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  32093. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  32094. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  32095. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  32096. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  32097. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  32098. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  32099. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  32100. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  32101. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  32102. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  32103. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  32104. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  32105. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  32106. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  32107. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  32108. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  32109. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  32110. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  32111. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  32112. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  32113. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  32114. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  32115. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  32116. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  32117. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  32118. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  32119. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  32120. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  32121. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  32122. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  32123. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  32124. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  32125. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  32126. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  32127. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  32128. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  32129. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  32130. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  32131. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  32132. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  32133. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  32134. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  32135. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  32136. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  32137. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  32138. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  32139. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  32140. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  32141. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  32142. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  32143. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  32144. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  32145. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  32146. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  32147. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  32148. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  32149. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  32150. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  32151. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  32152. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  32153. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  32154. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  32155. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  32156. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  32157. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  32158. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  32159. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  32160. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  32161. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  32162. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  32163. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  32164. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  32165. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  32166. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  32167. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  32168. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  32169. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  32170. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  32171. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  32172. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  32173. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  32174. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  32175. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  32176. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  32177. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  32178. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  32179. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  32180. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  32181. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  32182. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  32183. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  32184. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  32185. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  32186. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  32187. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  32188. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  32189. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  32190. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  32191. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  32192. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  32193. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  32194. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  32195. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  32196. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  32197. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  32198. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  32199. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  32200. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  32201. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  32202. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  32203. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  32204. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  32205. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  32206. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  32207. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  32208. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  32209. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  32210. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  32211. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  32212. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  32213. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  32214. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  32215. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  32216. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  32217. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  32218. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  32219. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  32220. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  32221. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  32222. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  32223. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  32224. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  32225. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  32226. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  32227. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  32228. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  32229. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  32230. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  32231. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  32232. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  32233. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  32234. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  32235. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  32236. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  32237. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  32238. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  32239. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  32240. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  32241. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  32242. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  32243. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  32244. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  32245. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  32246. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  32247. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  32248. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  32249. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  32250. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  32251. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  32252. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  32253. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  32254. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  32255. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  32256. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  32257. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  32258. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  32259. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  32260. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  32261. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  32262. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  32263. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  32264. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  32265. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  32266. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  32267. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  32268. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  32269. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  32270. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  32271. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  32272. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  32273. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  32274. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  32275. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  32276. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  32277. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  32278. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  32279. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  32280. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  32281. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  32282. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  32283. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  32284. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  32285. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  32286. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  32287. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  32288. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  32289. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  32290. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  32291. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  32292. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  32293. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  32294. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  32295. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  32296. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  32297. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  32298. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  32299. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  32300. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  32301. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  32302. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  32303. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  32304. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  32305. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  32306. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  32307. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  32308. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  32309. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  32310. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  32311. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  32312. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  32313. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  32314. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  32315. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  32316. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  32317. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  32318. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  32319. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  32320. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  32321. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  32322. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  32323. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  32324. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  32325. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  32326. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  32327. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  32328. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  32329. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  32330. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  32331. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  32332. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  32333. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  32334. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  32335. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  32336. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  32337. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  32338. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  32339. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  32340. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  32341. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  32342. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  32343. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  32344. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  32345. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  32346. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  32347. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  32348. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  32349. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  32350. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  32351. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  32352. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  32353. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  32354. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  32355. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  32356. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  32357. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  32358. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  32359. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  32360. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  32361. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  32362. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  32363. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  32364. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  32365. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  32366. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  32367. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  32368. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  32369. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  32370. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  32371. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  32372. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  32373. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  32374. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  32375. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  32376. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  32377. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  32378. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  32379. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  32380. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  32381. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  32382. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  32383. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  32384. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  32385. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  32386. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  32387. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  32388. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  32389. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  32390. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  32391. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  32392. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  32393. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  32394. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  32395. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  32396. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  32397. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  32398. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  32399. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  32400. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  32401. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  32402. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  32403. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  32404. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  32405. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  32406. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  32407. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  32408. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  32409. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  32410. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  32411. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  32412. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  32413. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  32414. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  32415. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  32416. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  32417. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  32418. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  32419. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  32420. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  32421. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  32422. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  32423. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  32424. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  32425. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  32426. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  32427. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  32428. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  32429. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  32430. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  32431. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  32432. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  32433. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  32434. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  32435. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  32436. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  32437. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  32438. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  32439. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  32440. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  32441. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  32442. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  32443. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  32444. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  32445. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  32446. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  32447. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  32448. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  32449. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  32450. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  32451. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  32452. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  32453. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  32454. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  32455. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  32456. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  32457. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  32458. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  32459. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  32460. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  32461. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  32462. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  32463. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  32464. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  32465. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  32466. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  32467. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  32468. };
  32469. #endif /* WOLFSSL_NO_ML_DSA_87 */
  32470. #else
  32471. #ifndef WOLFSSL_NO_ML_DSA_44
  32472. static const byte seed_44[] = {
  32473. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  32474. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  32475. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  32476. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  32477. };
  32478. static const byte pk_44[] = {
  32479. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32480. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32481. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32482. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32483. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  32484. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  32485. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  32486. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  32487. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  32488. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  32489. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  32490. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  32491. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  32492. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  32493. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  32494. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  32495. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  32496. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  32497. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  32498. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  32499. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  32500. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  32501. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  32502. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  32503. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  32504. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  32505. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  32506. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  32507. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  32508. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  32509. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  32510. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  32511. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  32512. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  32513. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  32514. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  32515. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  32516. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  32517. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  32518. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  32519. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  32520. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  32521. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  32522. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  32523. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  32524. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  32525. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  32526. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  32527. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  32528. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  32529. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  32530. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  32531. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  32532. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  32533. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  32534. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  32535. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  32536. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  32537. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  32538. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  32539. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  32540. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  32541. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  32542. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  32543. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  32544. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  32545. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  32546. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  32547. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  32548. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  32549. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  32550. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  32551. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  32552. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  32553. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  32554. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  32555. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  32556. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  32557. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  32558. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  32559. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  32560. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  32561. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  32562. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  32563. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  32564. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  32565. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  32566. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  32567. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  32568. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  32569. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  32570. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  32571. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  32572. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  32573. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  32574. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  32575. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  32576. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  32577. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  32578. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  32579. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  32580. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  32581. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  32582. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  32583. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  32584. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  32585. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  32586. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  32587. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  32588. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  32589. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  32590. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  32591. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  32592. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  32593. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  32594. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  32595. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  32596. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  32597. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  32598. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  32599. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  32600. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  32601. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  32602. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  32603. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  32604. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  32605. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  32606. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  32607. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  32608. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  32609. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  32610. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  32611. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  32612. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  32613. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  32614. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  32615. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  32616. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  32617. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  32618. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  32619. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  32620. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  32621. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  32622. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  32623. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  32624. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  32625. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  32626. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  32627. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  32628. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  32629. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  32630. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  32631. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  32632. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  32633. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  32634. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  32635. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  32636. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  32637. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  32638. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  32639. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  32640. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  32641. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  32642. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  32643. };
  32644. static const byte sk_44[] = {
  32645. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32646. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32647. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32648. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32649. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  32650. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  32651. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  32652. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  32653. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  32654. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  32655. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  32656. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  32657. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  32658. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  32659. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  32660. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  32661. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  32662. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  32663. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  32664. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  32665. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  32666. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  32667. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  32668. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  32669. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  32670. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  32671. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  32672. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  32673. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  32674. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  32675. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  32676. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  32677. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  32678. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  32679. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  32680. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  32681. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  32682. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  32683. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  32684. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  32685. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  32686. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  32687. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  32688. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  32689. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  32690. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  32691. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  32692. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  32693. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  32694. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  32695. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  32696. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  32697. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  32698. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  32699. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  32700. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  32701. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  32702. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  32703. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  32704. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  32705. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  32706. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  32707. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  32708. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  32709. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  32710. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  32711. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  32712. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  32713. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  32714. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  32715. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  32716. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  32717. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  32718. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  32719. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  32720. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  32721. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  32722. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  32723. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  32724. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  32725. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  32726. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  32727. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  32728. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  32729. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  32730. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  32731. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  32732. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  32733. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  32734. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  32735. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  32736. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  32737. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  32738. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  32739. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  32740. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  32741. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  32742. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  32743. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  32744. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  32745. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  32746. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  32747. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  32748. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  32749. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  32750. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  32751. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  32752. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  32753. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  32754. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  32755. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  32756. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  32757. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  32758. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  32759. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  32760. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  32761. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  32762. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  32763. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  32764. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  32765. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  32766. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  32767. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  32768. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  32769. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  32770. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  32771. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  32772. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  32773. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  32774. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  32775. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  32776. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  32777. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  32778. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  32779. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  32780. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  32781. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  32782. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  32783. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  32784. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  32785. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  32786. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  32787. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  32788. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  32789. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  32790. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  32791. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  32792. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  32793. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  32794. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  32795. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  32796. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  32797. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  32798. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  32799. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  32800. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  32801. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  32802. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  32803. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  32804. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  32805. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  32806. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  32807. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  32808. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  32809. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  32810. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  32811. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  32812. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  32813. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  32814. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  32815. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  32816. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  32817. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  32818. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  32819. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  32820. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  32821. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  32822. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  32823. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  32824. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  32825. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  32826. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  32827. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  32828. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  32829. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  32830. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  32831. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  32832. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  32833. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  32834. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  32835. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  32836. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  32837. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  32838. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  32839. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  32840. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  32841. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  32842. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  32843. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  32844. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  32845. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  32846. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  32847. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  32848. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  32849. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  32850. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  32851. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  32852. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  32853. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  32854. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  32855. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  32856. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  32857. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  32858. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  32859. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  32860. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  32861. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  32862. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  32863. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  32864. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  32865. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  32866. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  32867. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  32868. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  32869. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  32870. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  32871. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  32872. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  32873. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  32874. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  32875. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  32876. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  32877. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  32878. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  32879. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  32880. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  32881. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  32882. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  32883. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  32884. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  32885. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  32886. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  32887. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  32888. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  32889. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  32890. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  32891. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  32892. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  32893. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  32894. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  32895. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  32896. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  32897. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  32898. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  32899. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  32900. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  32901. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  32902. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  32903. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  32904. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  32905. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  32906. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  32907. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  32908. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  32909. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  32910. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  32911. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  32912. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  32913. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  32914. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  32915. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  32916. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  32917. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  32918. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  32919. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  32920. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  32921. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  32922. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  32923. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  32924. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  32925. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  32926. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  32927. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  32928. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  32929. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  32930. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  32931. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  32932. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  32933. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  32934. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  32935. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  32936. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  32937. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  32938. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  32939. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  32940. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  32941. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  32942. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  32943. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  32944. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  32945. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  32946. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  32947. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  32948. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  32949. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  32950. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  32951. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  32952. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  32953. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  32954. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  32955. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  32956. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  32957. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  32958. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  32959. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  32960. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  32961. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  32962. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  32963. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  32964. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  32965. };
  32966. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  32967. #ifndef WOLFSSL_NO_ML_DSA_65
  32968. static const byte seed_65[] = {
  32969. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  32970. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  32971. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  32972. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  32973. };
  32974. static const byte pk_65[] = {
  32975. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  32976. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  32977. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  32978. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  32979. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  32980. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  32981. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  32982. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  32983. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  32984. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  32985. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  32986. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  32987. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  32988. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  32989. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  32990. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  32991. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  32992. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  32993. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  32994. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  32995. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  32996. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  32997. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  32998. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  32999. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  33000. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  33001. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  33002. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  33003. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  33004. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  33005. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  33006. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  33007. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  33008. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  33009. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  33010. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  33011. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  33012. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  33013. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  33014. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  33015. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  33016. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  33017. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  33018. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  33019. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  33020. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  33021. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  33022. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  33023. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  33024. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  33025. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  33026. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  33027. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  33028. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  33029. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  33030. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  33031. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  33032. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  33033. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  33034. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  33035. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  33036. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  33037. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  33038. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  33039. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  33040. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  33041. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  33042. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  33043. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  33044. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  33045. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  33046. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  33047. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  33048. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  33049. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  33050. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  33051. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  33052. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  33053. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  33054. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  33055. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  33056. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  33057. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  33058. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  33059. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  33060. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  33061. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  33062. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  33063. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  33064. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  33065. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  33066. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  33067. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  33068. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  33069. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  33070. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  33071. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  33072. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  33073. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  33074. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  33075. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  33076. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  33077. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  33078. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  33079. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  33080. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  33081. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  33082. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  33083. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  33084. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  33085. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  33086. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  33087. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  33088. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  33089. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  33090. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  33091. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  33092. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  33093. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  33094. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  33095. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  33096. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  33097. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  33098. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  33099. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  33100. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  33101. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  33102. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  33103. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  33104. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  33105. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  33106. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  33107. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  33108. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  33109. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  33110. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  33111. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  33112. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  33113. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  33114. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  33115. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  33116. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  33117. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  33118. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  33119. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  33120. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  33121. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  33122. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  33123. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  33124. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  33125. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  33126. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  33127. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  33128. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  33129. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  33130. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  33131. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  33132. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  33133. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  33134. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  33135. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  33136. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  33137. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  33138. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  33139. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  33140. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  33141. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  33142. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  33143. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  33144. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  33145. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  33146. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  33147. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  33148. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  33149. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  33150. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  33151. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  33152. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  33153. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  33154. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  33155. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  33156. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  33157. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  33158. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  33159. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  33160. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  33161. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  33162. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  33163. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  33164. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  33165. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  33166. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  33167. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  33168. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  33169. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  33170. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  33171. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  33172. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  33173. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  33174. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  33175. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  33176. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  33177. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  33178. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  33179. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  33180. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  33181. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  33182. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  33183. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  33184. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  33185. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  33186. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  33187. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  33188. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  33189. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  33190. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  33191. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  33192. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  33193. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  33194. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  33195. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  33196. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  33197. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  33198. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  33199. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  33200. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  33201. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  33202. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  33203. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  33204. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  33205. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  33206. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  33207. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  33208. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  33209. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  33210. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  33211. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  33212. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  33213. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  33214. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  33215. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  33216. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  33217. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  33218. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  33219. };
  33220. static const byte sk_65[] = {
  33221. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33222. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33223. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33224. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33225. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  33226. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  33227. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  33228. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  33229. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  33230. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  33231. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  33232. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  33233. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  33234. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  33235. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  33236. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  33237. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  33238. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  33239. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  33240. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  33241. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  33242. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  33243. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  33244. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  33245. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  33246. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  33247. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  33248. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  33249. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  33250. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  33251. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  33252. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  33253. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  33254. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  33255. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  33256. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  33257. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  33258. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  33259. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  33260. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  33261. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  33262. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  33263. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  33264. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  33265. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  33266. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  33267. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  33268. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  33269. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  33270. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  33271. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  33272. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  33273. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  33274. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  33275. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  33276. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  33277. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  33278. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  33279. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  33280. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  33281. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  33282. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  33283. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  33284. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  33285. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  33286. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  33287. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  33288. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  33289. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  33290. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  33291. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  33292. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  33293. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  33294. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  33295. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  33296. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  33297. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  33298. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  33299. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  33300. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  33301. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  33302. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  33303. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  33304. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  33305. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  33306. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  33307. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  33308. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  33309. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  33310. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  33311. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  33312. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  33313. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  33314. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  33315. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  33316. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  33317. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  33318. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  33319. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  33320. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  33321. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  33322. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  33323. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  33324. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  33325. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  33326. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  33327. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  33328. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  33329. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  33330. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  33331. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  33332. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  33333. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  33334. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  33335. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  33336. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  33337. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  33338. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  33339. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  33340. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  33341. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  33342. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  33343. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  33344. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  33345. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  33346. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  33347. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  33348. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  33349. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  33350. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  33351. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  33352. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  33353. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  33354. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  33355. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  33356. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  33357. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  33358. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  33359. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  33360. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  33361. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  33362. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  33363. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  33364. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  33365. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  33366. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  33367. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  33368. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  33369. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  33370. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  33371. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  33372. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  33373. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  33374. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  33375. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  33376. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  33377. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  33378. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  33379. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  33380. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  33381. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  33382. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  33383. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  33384. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  33385. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  33386. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  33387. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  33388. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  33389. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  33390. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  33391. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  33392. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  33393. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  33394. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  33395. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  33396. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  33397. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  33398. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  33399. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  33400. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  33401. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  33402. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  33403. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  33404. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  33405. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  33406. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  33407. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  33408. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  33409. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  33410. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  33411. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  33412. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  33413. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  33414. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  33415. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  33416. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  33417. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  33418. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  33419. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  33420. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  33421. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  33422. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  33423. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  33424. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  33425. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  33426. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  33427. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  33428. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  33429. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  33430. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  33431. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  33432. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  33433. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  33434. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  33435. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  33436. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  33437. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  33438. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  33439. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  33440. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  33441. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  33442. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  33443. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  33444. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  33445. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  33446. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  33447. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  33448. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  33449. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  33450. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  33451. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  33452. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  33453. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  33454. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  33455. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  33456. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  33457. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  33458. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  33459. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  33460. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  33461. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  33462. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  33463. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  33464. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  33465. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  33466. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  33467. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  33468. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  33469. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  33470. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  33471. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  33472. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  33473. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  33474. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  33475. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  33476. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  33477. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  33478. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  33479. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  33480. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  33481. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  33482. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  33483. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  33484. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  33485. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  33486. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  33487. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  33488. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  33489. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  33490. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  33491. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  33492. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  33493. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  33494. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  33495. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  33496. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  33497. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  33498. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  33499. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  33500. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  33501. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  33502. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  33503. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  33504. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  33505. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  33506. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  33507. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  33508. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  33509. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  33510. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  33511. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  33512. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  33513. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  33514. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  33515. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  33516. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  33517. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  33518. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  33519. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  33520. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  33521. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  33522. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  33523. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  33524. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  33525. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  33526. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  33527. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  33528. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  33529. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  33530. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  33531. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  33532. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  33533. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  33534. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  33535. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  33536. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  33537. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  33538. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  33539. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  33540. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  33541. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  33542. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  33543. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  33544. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  33545. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  33546. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  33547. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  33548. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  33549. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  33550. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  33551. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  33552. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  33553. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  33554. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  33555. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  33556. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  33557. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  33558. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  33559. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  33560. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  33561. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  33562. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  33563. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  33564. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  33565. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  33566. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  33567. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  33568. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  33569. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  33570. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  33571. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  33572. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  33573. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  33574. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  33575. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  33576. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  33577. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  33578. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  33579. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  33580. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  33581. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  33582. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  33583. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  33584. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  33585. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  33586. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  33587. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  33588. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  33589. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  33590. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  33591. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  33592. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  33593. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  33594. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  33595. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  33596. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  33597. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  33598. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  33599. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  33600. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  33601. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  33602. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  33603. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  33604. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  33605. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  33606. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  33607. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  33608. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  33609. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  33610. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  33611. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  33612. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  33613. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  33614. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  33615. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  33616. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  33617. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  33618. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  33619. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  33620. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  33621. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  33622. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  33623. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  33624. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  33625. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  33626. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  33627. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  33628. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  33629. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  33630. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  33631. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  33632. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  33633. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  33634. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  33635. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  33636. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  33637. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  33638. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  33639. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  33640. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  33641. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  33642. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  33643. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  33644. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  33645. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  33646. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  33647. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  33648. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  33649. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  33650. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  33651. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  33652. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  33653. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  33654. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  33655. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  33656. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  33657. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  33658. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  33659. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  33660. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  33661. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  33662. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  33663. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  33664. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  33665. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  33666. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  33667. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  33668. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  33669. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  33670. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  33671. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  33672. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  33673. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  33674. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  33675. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  33676. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  33677. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  33678. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  33679. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  33680. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  33681. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  33682. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  33683. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  33684. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  33685. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  33686. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  33687. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  33688. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  33689. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  33690. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  33691. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  33692. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  33693. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  33694. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  33695. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  33696. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  33697. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  33698. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  33699. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  33700. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  33701. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  33702. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  33703. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  33704. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  33705. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  33706. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  33707. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  33708. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  33709. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  33710. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  33711. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  33712. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  33713. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  33714. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  33715. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  33716. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  33717. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  33718. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  33719. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  33720. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  33721. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  33722. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  33723. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  33724. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  33725. };
  33726. #endif /* WOLFSSL_NO_ML_DSA_65 */
  33727. #ifndef WOLFSSL_NO_ML_DSA_87
  33728. static const byte seed_87[] = {
  33729. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  33730. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  33731. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  33732. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  33733. };
  33734. static const byte pk_87[] = {
  33735. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  33736. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  33737. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  33738. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  33739. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  33740. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  33741. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  33742. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  33743. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  33744. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  33745. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  33746. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  33747. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  33748. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  33749. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  33750. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  33751. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  33752. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  33753. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  33754. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  33755. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  33756. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  33757. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  33758. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  33759. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  33760. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  33761. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  33762. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  33763. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  33764. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  33765. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  33766. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  33767. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  33768. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  33769. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  33770. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  33771. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  33772. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  33773. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  33774. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  33775. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  33776. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  33777. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  33778. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  33779. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  33780. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  33781. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  33782. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  33783. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  33784. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  33785. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  33786. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  33787. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  33788. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  33789. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  33790. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  33791. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  33792. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  33793. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  33794. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  33795. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  33796. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  33797. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  33798. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  33799. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  33800. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  33801. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  33802. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  33803. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  33804. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  33805. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  33806. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  33807. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  33808. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  33809. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  33810. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  33811. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  33812. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  33813. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  33814. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  33815. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  33816. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  33817. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  33818. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  33819. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  33820. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  33821. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  33822. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  33823. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  33824. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  33825. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  33826. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  33827. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  33828. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  33829. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  33830. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  33831. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  33832. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  33833. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  33834. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  33835. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  33836. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  33837. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  33838. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  33839. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  33840. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  33841. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  33842. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  33843. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  33844. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  33845. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  33846. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  33847. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  33848. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  33849. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  33850. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  33851. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  33852. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  33853. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  33854. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  33855. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  33856. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  33857. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  33858. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  33859. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  33860. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  33861. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  33862. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  33863. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  33864. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  33865. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  33866. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  33867. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  33868. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  33869. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  33870. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  33871. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  33872. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  33873. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  33874. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  33875. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  33876. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  33877. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  33878. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  33879. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  33880. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  33881. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  33882. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  33883. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  33884. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  33885. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  33886. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  33887. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  33888. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  33889. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  33890. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  33891. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  33892. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  33893. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  33894. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  33895. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  33896. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  33897. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  33898. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  33899. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  33900. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  33901. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  33902. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  33903. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  33904. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  33905. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  33906. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  33907. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  33908. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  33909. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  33910. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  33911. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  33912. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  33913. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  33914. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  33915. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  33916. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  33917. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  33918. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  33919. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  33920. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  33921. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  33922. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  33923. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  33924. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  33925. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  33926. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  33927. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  33928. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  33929. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  33930. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  33931. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  33932. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  33933. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  33934. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  33935. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  33936. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  33937. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  33938. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  33939. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  33940. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  33941. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  33942. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  33943. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  33944. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  33945. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  33946. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  33947. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  33948. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  33949. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  33950. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  33951. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  33952. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  33953. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  33954. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  33955. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  33956. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  33957. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  33958. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  33959. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  33960. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  33961. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  33962. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  33963. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  33964. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  33965. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  33966. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  33967. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  33968. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  33969. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  33970. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  33971. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  33972. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  33973. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  33974. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  33975. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  33976. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  33977. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  33978. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  33979. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  33980. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  33981. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  33982. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  33983. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  33984. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  33985. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  33986. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  33987. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  33988. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  33989. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  33990. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  33991. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  33992. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  33993. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  33994. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  33995. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  33996. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  33997. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  33998. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  33999. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  34000. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  34001. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  34002. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  34003. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  34004. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  34005. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  34006. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  34007. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  34008. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  34009. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  34010. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  34011. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  34012. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  34013. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  34014. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  34015. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  34016. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  34017. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  34018. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  34019. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  34020. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  34021. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  34022. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  34023. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  34024. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  34025. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  34026. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  34027. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  34028. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  34029. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  34030. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  34031. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  34032. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  34033. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  34034. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  34035. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  34036. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  34037. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  34038. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  34039. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  34040. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  34041. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  34042. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  34043. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  34044. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  34045. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  34046. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  34047. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  34048. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  34049. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  34050. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  34051. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  34052. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  34053. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  34054. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  34055. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  34056. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  34057. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  34058. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  34059. };
  34060. static const byte sk_87[] = {
  34061. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  34062. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  34063. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  34064. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  34065. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  34066. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  34067. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  34068. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  34069. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  34070. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  34071. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  34072. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  34073. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  34074. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  34075. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  34076. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  34077. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  34078. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  34079. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  34080. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  34081. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  34082. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  34083. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  34084. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  34085. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  34086. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  34087. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  34088. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  34089. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  34090. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  34091. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  34092. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  34093. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  34094. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  34095. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  34096. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  34097. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  34098. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  34099. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  34100. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  34101. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  34102. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  34103. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  34104. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  34105. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  34106. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  34107. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  34108. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  34109. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  34110. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  34111. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  34112. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  34113. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  34114. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  34115. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  34116. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  34117. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  34118. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  34119. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  34120. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  34121. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  34122. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  34123. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  34124. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  34125. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  34126. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  34127. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  34128. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  34129. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  34130. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  34131. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  34132. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  34133. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  34134. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  34135. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  34136. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  34137. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  34138. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  34139. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  34140. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  34141. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  34142. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  34143. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  34144. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  34145. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  34146. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  34147. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  34148. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  34149. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  34150. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  34151. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  34152. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  34153. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  34154. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  34155. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  34156. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  34157. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  34158. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  34159. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  34160. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  34161. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  34162. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  34163. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  34164. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  34165. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  34166. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  34167. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  34168. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  34169. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  34170. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  34171. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  34172. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  34173. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  34174. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  34175. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  34176. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  34177. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  34178. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  34179. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  34180. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  34181. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  34182. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  34183. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  34184. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  34185. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  34186. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  34187. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  34188. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  34189. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  34190. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  34191. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  34192. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  34193. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  34194. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  34195. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  34196. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  34197. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  34198. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  34199. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  34200. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  34201. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  34202. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  34203. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  34204. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  34205. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  34206. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  34207. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  34208. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  34209. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  34210. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  34211. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  34212. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  34213. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  34214. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  34215. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  34216. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  34217. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  34218. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  34219. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  34220. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  34221. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  34222. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  34223. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  34224. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  34225. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  34226. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  34227. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  34228. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  34229. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  34230. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  34231. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  34232. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  34233. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  34234. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  34235. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  34236. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  34237. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  34238. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  34239. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  34240. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  34241. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  34242. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  34243. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  34244. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  34245. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  34246. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  34247. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  34248. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  34249. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  34250. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  34251. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  34252. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  34253. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  34254. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  34255. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  34256. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  34257. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  34258. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  34259. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  34260. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  34261. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  34262. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  34263. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  34264. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  34265. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  34266. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  34267. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  34268. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  34269. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  34270. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  34271. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  34272. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  34273. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  34274. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  34275. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  34276. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  34277. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  34278. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  34279. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  34280. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  34281. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  34282. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  34283. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  34284. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  34285. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  34286. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  34287. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  34288. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  34289. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  34290. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  34291. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  34292. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  34293. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  34294. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  34295. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  34296. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  34297. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  34298. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  34299. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  34300. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  34301. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  34302. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  34303. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  34304. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  34305. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  34306. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  34307. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  34308. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  34309. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  34310. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  34311. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  34312. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  34313. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  34314. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  34315. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  34316. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  34317. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  34318. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  34319. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  34320. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  34321. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  34322. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  34323. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  34324. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  34325. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  34326. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  34327. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  34328. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  34329. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  34330. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  34331. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  34332. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  34333. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  34334. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  34335. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  34336. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  34337. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  34338. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  34339. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  34340. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  34341. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  34342. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  34343. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  34344. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  34345. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  34346. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  34347. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  34348. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  34349. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  34350. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  34351. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  34352. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  34353. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  34354. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  34355. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  34356. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  34357. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  34358. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  34359. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  34360. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  34361. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  34362. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  34363. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  34364. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  34365. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  34366. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  34367. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  34368. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  34369. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  34370. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  34371. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  34372. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  34373. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  34374. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  34375. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  34376. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  34377. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  34378. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  34379. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  34380. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  34381. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  34382. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  34383. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  34384. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  34385. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  34386. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  34387. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  34388. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  34389. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  34390. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  34391. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  34392. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  34393. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  34394. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  34395. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  34396. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  34397. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  34398. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  34399. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  34400. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  34401. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  34402. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  34403. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  34404. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  34405. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  34406. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  34407. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  34408. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  34409. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  34410. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  34411. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  34412. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  34413. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  34414. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  34415. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  34416. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  34417. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  34418. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  34419. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  34420. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  34421. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  34422. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  34423. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  34424. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  34425. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  34426. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  34427. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  34428. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  34429. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  34430. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  34431. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  34432. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  34433. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  34434. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  34435. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  34436. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  34437. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  34438. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  34439. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  34440. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  34441. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  34442. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  34443. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  34444. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  34445. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  34446. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  34447. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  34448. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  34449. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  34450. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  34451. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  34452. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  34453. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  34454. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  34455. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  34456. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  34457. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  34458. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  34459. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  34460. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  34461. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  34462. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  34463. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  34464. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  34465. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  34466. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  34467. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  34468. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  34469. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  34470. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  34471. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  34472. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  34473. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  34474. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  34475. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  34476. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  34477. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  34478. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  34479. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  34480. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  34481. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  34482. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  34483. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  34484. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  34485. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  34486. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  34487. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  34488. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  34489. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  34490. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  34491. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  34492. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  34493. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  34494. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  34495. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  34496. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  34497. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  34498. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  34499. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  34500. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  34501. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  34502. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  34503. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  34504. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  34505. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  34506. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  34507. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  34508. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  34509. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  34510. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  34511. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  34512. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  34513. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  34514. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  34515. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  34516. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  34517. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  34518. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  34519. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  34520. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  34521. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  34522. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  34523. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  34524. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  34525. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  34526. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  34527. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  34528. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  34529. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  34530. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  34531. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  34532. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  34533. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  34534. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  34535. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  34536. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  34537. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  34538. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  34539. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  34540. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  34541. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  34542. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  34543. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  34544. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  34545. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  34546. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  34547. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  34548. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  34549. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  34550. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  34551. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  34552. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  34553. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  34554. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  34555. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  34556. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  34557. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  34558. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  34559. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  34560. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  34561. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  34562. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  34563. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  34564. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  34565. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  34566. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  34567. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  34568. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  34569. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  34570. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  34571. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  34572. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  34573. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  34574. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  34575. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  34576. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  34577. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  34578. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  34579. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  34580. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  34581. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  34582. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  34583. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  34584. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  34585. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  34586. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  34587. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  34588. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  34589. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  34590. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  34591. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  34592. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  34593. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  34594. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  34595. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  34596. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  34597. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  34598. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  34599. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  34600. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  34601. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  34602. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  34603. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  34604. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  34605. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  34606. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  34607. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  34608. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  34609. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  34610. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  34611. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  34612. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  34613. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  34614. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  34615. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  34616. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  34617. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  34618. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  34619. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  34620. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  34621. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  34622. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  34623. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  34624. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  34625. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  34626. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  34627. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  34628. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  34629. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  34630. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  34631. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  34632. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  34633. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  34634. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  34635. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  34636. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  34637. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  34638. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  34639. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  34640. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  34641. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  34642. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  34643. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  34644. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  34645. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  34646. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  34647. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  34648. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  34649. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  34650. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  34651. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  34652. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  34653. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  34654. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  34655. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  34656. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  34657. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  34658. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  34659. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  34660. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  34661. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  34662. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  34663. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  34664. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  34665. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  34666. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  34667. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  34668. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  34669. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  34670. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  34671. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  34672. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  34673. };
  34674. #endif /* WOLFSSL_NO_ML_DSA_87 */
  34675. #endif
  34676. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34677. ExpectNotNull(key);
  34678. if (key != NULL) {
  34679. XMEMSET(key, 0, sizeof(*key));
  34680. }
  34681. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  34682. #ifndef WOLFSSL_NO_ML_DSA_44
  34683. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  34684. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  34685. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  34686. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  34687. #endif
  34688. #ifndef WOLFSSL_NO_ML_DSA_65
  34689. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  34690. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  34691. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  34692. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  34693. #endif
  34694. #ifndef WOLFSSL_NO_ML_DSA_87
  34695. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  34696. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  34697. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  34698. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  34699. #endif
  34700. wc_dilithium_free(key);
  34701. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34702. #endif
  34703. return EXPECT_RESULT();
  34704. }
  34705. static int test_wc_dilithium_sig_kats(void)
  34706. {
  34707. EXPECT_DECLS;
  34708. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  34709. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
  34710. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT)
  34711. dilithium_key* key;
  34712. #ifndef WOLFSSL_NO_ML_DSA_44
  34713. static const byte sk_44[] = {
  34714. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  34715. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  34716. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  34717. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  34718. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  34719. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  34720. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  34721. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  34722. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  34723. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  34724. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  34725. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  34726. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  34727. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  34728. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  34729. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  34730. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  34731. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  34732. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  34733. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  34734. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  34735. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  34736. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  34737. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  34738. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  34739. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  34740. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  34741. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  34742. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  34743. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  34744. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  34745. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  34746. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  34747. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  34748. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  34749. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  34750. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  34751. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  34752. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  34753. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  34754. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  34755. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  34756. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  34757. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  34758. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  34759. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  34760. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  34761. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  34762. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  34763. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  34764. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  34765. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  34766. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  34767. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  34768. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  34769. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  34770. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  34771. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  34772. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  34773. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  34774. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  34775. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  34776. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  34777. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  34778. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  34779. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  34780. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  34781. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  34782. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  34783. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  34784. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  34785. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  34786. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  34787. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  34788. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  34789. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  34790. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  34791. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  34792. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  34793. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  34794. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  34795. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  34796. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  34797. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  34798. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  34799. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  34800. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  34801. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  34802. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  34803. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  34804. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  34805. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  34806. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  34807. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  34808. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  34809. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  34810. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  34811. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  34812. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  34813. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  34814. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  34815. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  34816. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  34817. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  34818. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  34819. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  34820. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  34821. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  34822. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  34823. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  34824. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  34825. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  34826. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  34827. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  34828. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  34829. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  34830. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  34831. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  34832. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  34833. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  34834. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  34835. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  34836. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  34837. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  34838. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  34839. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  34840. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  34841. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  34842. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  34843. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  34844. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  34845. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  34846. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  34847. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  34848. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  34849. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  34850. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  34851. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  34852. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  34853. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  34854. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  34855. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  34856. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  34857. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  34858. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  34859. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  34860. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  34861. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  34862. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  34863. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  34864. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  34865. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  34866. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  34867. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  34868. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  34869. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  34870. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  34871. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  34872. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  34873. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  34874. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  34875. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  34876. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  34877. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  34878. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  34879. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  34880. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  34881. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  34882. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  34883. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  34884. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  34885. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  34886. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  34887. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  34888. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  34889. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  34890. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  34891. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  34892. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  34893. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  34894. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  34895. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  34896. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  34897. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  34898. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  34899. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  34900. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  34901. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  34902. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  34903. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  34904. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  34905. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  34906. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  34907. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  34908. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  34909. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  34910. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  34911. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  34912. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  34913. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  34914. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  34915. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  34916. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  34917. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  34918. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  34919. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  34920. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  34921. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  34922. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  34923. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  34924. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  34925. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  34926. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  34927. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  34928. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  34929. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  34930. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  34931. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  34932. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  34933. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  34934. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  34935. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  34936. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  34937. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  34938. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  34939. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  34940. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  34941. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  34942. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  34943. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  34944. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  34945. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  34946. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  34947. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  34948. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  34949. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  34950. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  34951. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  34952. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  34953. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  34954. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  34955. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  34956. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  34957. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  34958. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  34959. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  34960. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  34961. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  34962. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  34963. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  34964. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  34965. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  34966. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  34967. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  34968. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  34969. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  34970. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  34971. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  34972. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  34973. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  34974. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  34975. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  34976. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  34977. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  34978. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  34979. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  34980. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  34981. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  34982. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  34983. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  34984. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  34985. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  34986. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  34987. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  34988. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  34989. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  34990. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  34991. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  34992. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  34993. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  34994. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  34995. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  34996. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  34997. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  34998. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  34999. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  35000. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  35001. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  35002. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  35003. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  35004. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  35005. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  35006. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  35007. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  35008. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  35009. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  35010. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  35011. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  35012. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  35013. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  35014. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  35015. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  35016. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  35017. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  35018. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  35019. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  35020. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  35021. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  35022. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  35023. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  35024. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  35025. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  35026. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  35027. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  35028. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  35029. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  35030. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  35031. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  35032. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  35033. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  35034. };
  35035. static const byte msg_44[] = {
  35036. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  35037. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  35038. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  35039. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  35040. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  35041. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  35042. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  35043. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  35044. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  35045. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  35046. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  35047. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  35048. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  35049. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  35050. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  35051. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  35052. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  35053. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  35054. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  35055. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  35056. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  35057. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  35058. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  35059. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  35060. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  35061. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  35062. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  35063. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  35064. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  35065. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  35066. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  35067. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  35068. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  35069. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  35070. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  35071. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  35072. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  35073. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  35074. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  35075. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  35076. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  35077. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  35078. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  35079. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  35080. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  35081. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  35082. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  35083. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  35084. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  35085. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  35086. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  35087. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  35088. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  35089. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  35090. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  35091. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  35092. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  35093. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  35094. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  35095. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  35096. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  35097. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  35098. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  35099. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  35100. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  35101. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  35102. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  35103. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  35104. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  35105. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  35106. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  35107. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  35108. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  35109. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  35110. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  35111. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  35112. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  35113. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  35114. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  35115. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  35116. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  35117. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  35118. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  35119. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  35120. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  35121. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  35122. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  35123. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  35124. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  35125. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  35126. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  35127. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  35128. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  35129. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  35130. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  35131. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  35132. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  35133. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  35134. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  35135. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  35136. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  35137. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  35138. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  35139. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  35140. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  35141. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  35142. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  35143. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  35144. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  35145. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  35146. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  35147. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  35148. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  35149. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  35150. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  35151. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  35152. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  35153. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  35154. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  35155. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  35156. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  35157. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  35158. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  35159. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  35160. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  35161. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  35162. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  35163. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  35164. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  35165. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  35166. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  35167. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  35168. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  35169. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  35170. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  35171. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  35172. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  35173. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  35174. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  35175. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  35176. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  35177. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  35178. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  35179. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  35180. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  35181. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  35182. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  35183. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  35184. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  35185. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  35186. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  35187. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  35188. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  35189. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  35190. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  35191. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  35192. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  35193. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  35194. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  35195. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  35196. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  35197. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  35198. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  35199. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  35200. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  35201. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  35202. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  35203. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  35204. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  35205. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  35206. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  35207. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  35208. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  35209. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  35210. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  35211. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  35212. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  35213. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  35214. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  35215. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  35216. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  35217. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  35218. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  35219. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  35220. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  35221. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  35222. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  35223. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  35224. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  35225. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  35226. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  35227. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  35228. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  35229. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  35230. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  35231. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  35232. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  35233. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  35234. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  35235. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  35236. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  35237. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  35238. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  35239. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  35240. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  35241. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  35242. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  35243. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  35244. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  35245. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  35246. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  35247. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  35248. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  35249. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  35250. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  35251. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  35252. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  35253. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  35254. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  35255. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  35256. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  35257. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  35258. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  35259. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  35260. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  35261. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  35262. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  35263. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  35264. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  35265. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  35266. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  35267. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  35268. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  35269. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  35270. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  35271. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  35272. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  35273. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  35274. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  35275. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  35276. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  35277. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  35278. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  35279. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  35280. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  35281. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  35282. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  35283. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  35284. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  35285. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  35286. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  35287. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  35288. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  35289. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  35290. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  35291. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  35292. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  35293. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  35294. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  35295. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  35296. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  35297. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  35298. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  35299. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  35300. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  35301. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  35302. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  35303. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  35304. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  35305. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  35306. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  35307. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  35308. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  35309. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  35310. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  35311. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  35312. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  35313. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  35314. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  35315. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  35316. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  35317. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  35318. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  35319. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  35320. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  35321. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  35322. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  35323. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  35324. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  35325. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  35326. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  35327. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  35328. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  35329. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  35330. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  35331. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  35332. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  35333. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  35334. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  35335. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  35336. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  35337. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  35338. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  35339. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  35340. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  35341. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  35342. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  35343. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  35344. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  35345. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  35346. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  35347. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  35348. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  35349. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  35350. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  35351. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  35352. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  35353. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  35354. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  35355. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  35356. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  35357. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  35358. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  35359. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  35360. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  35361. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  35362. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  35363. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  35364. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  35365. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  35366. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  35367. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  35368. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  35369. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  35370. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  35371. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  35372. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  35373. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  35374. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  35375. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  35376. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  35377. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  35378. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  35379. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  35380. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  35381. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  35382. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  35383. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  35384. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  35385. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  35386. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  35387. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  35388. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  35389. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  35390. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  35391. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  35392. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  35393. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  35394. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  35395. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  35396. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  35397. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  35398. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  35399. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  35400. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  35401. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  35402. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  35403. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  35404. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  35405. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  35406. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  35407. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  35408. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  35409. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  35410. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  35411. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  35412. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  35413. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  35414. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  35415. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  35416. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  35417. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  35418. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  35419. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  35420. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  35421. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  35422. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  35423. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  35424. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  35425. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  35426. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  35427. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  35428. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  35429. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  35430. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  35431. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  35432. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  35433. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  35434. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  35435. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  35436. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  35437. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  35438. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  35439. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  35440. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  35441. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  35442. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  35443. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  35444. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  35445. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  35446. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  35447. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  35448. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  35449. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  35450. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  35451. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  35452. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  35453. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  35454. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  35455. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  35456. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  35457. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  35458. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  35459. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  35460. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  35461. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  35462. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  35463. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  35464. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  35465. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  35466. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  35467. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  35468. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  35469. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  35470. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  35471. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  35472. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  35473. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  35474. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  35475. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  35476. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  35477. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  35478. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  35479. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  35480. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  35481. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  35482. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  35483. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  35484. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  35485. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  35486. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  35487. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  35488. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  35489. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  35490. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  35491. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  35492. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  35493. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  35494. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  35495. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  35496. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  35497. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  35498. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  35499. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  35500. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  35501. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  35502. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  35503. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  35504. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  35505. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  35506. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  35507. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  35508. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  35509. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  35510. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  35511. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  35512. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  35513. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  35514. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  35515. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  35516. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  35517. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  35518. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  35519. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  35520. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  35521. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  35522. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  35523. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  35524. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  35525. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  35526. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  35527. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  35528. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  35529. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  35530. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  35531. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  35532. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  35533. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  35534. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  35535. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  35536. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  35537. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  35538. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  35539. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  35540. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  35541. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  35542. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  35543. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  35544. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  35545. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  35546. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  35547. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  35548. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  35549. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  35550. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  35551. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  35552. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  35553. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  35554. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  35555. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  35556. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  35557. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  35558. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  35559. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  35560. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  35561. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  35562. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  35563. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  35564. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  35565. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  35566. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  35567. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  35568. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  35569. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  35570. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  35571. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  35572. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  35573. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  35574. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  35575. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  35576. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  35577. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  35578. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  35579. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  35580. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  35581. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  35582. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  35583. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  35584. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  35585. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  35586. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  35587. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  35588. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  35589. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  35590. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  35591. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  35592. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  35593. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  35594. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  35595. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  35596. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  35597. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  35598. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  35599. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  35600. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  35601. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  35602. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  35603. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  35604. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  35605. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  35606. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  35607. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  35608. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  35609. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  35610. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  35611. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  35612. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  35613. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  35614. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  35615. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  35616. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  35617. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  35618. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  35619. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  35620. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  35621. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  35622. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  35623. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  35624. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  35625. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  35626. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  35627. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  35628. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  35629. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  35630. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  35631. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  35632. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  35633. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  35634. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  35635. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  35636. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  35637. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  35638. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  35639. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  35640. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  35641. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  35642. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  35643. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  35644. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  35645. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  35646. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  35647. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  35648. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  35649. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  35650. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  35651. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  35652. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  35653. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  35654. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  35655. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  35656. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  35657. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  35658. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  35659. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  35660. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  35661. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  35662. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  35663. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  35664. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  35665. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  35666. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  35667. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  35668. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  35669. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  35670. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  35671. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  35672. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  35673. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  35674. 0x96
  35675. };
  35676. static const byte rnd_44[] = {
  35677. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  35678. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  35679. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  35680. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  35681. };
  35682. static const byte sig_44[] = {
  35683. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  35684. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  35685. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  35686. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  35687. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  35688. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  35689. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  35690. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  35691. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  35692. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  35693. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  35694. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  35695. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  35696. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  35697. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  35698. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  35699. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  35700. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  35701. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  35702. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  35703. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  35704. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  35705. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  35706. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  35707. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  35708. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  35709. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  35710. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  35711. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  35712. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  35713. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  35714. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  35715. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  35716. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  35717. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  35718. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  35719. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  35720. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  35721. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  35722. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  35723. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  35724. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  35725. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  35726. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  35727. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  35728. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  35729. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  35730. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  35731. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  35732. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  35733. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  35734. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  35735. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  35736. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  35737. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  35738. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  35739. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  35740. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  35741. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  35742. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  35743. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  35744. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  35745. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  35746. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  35747. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  35748. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  35749. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  35750. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  35751. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  35752. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  35753. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  35754. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  35755. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  35756. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  35757. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  35758. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  35759. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  35760. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  35761. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  35762. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  35763. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  35764. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  35765. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  35766. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  35767. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  35768. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  35769. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  35770. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  35771. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  35772. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  35773. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  35774. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  35775. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  35776. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  35777. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  35778. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  35779. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  35780. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  35781. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  35782. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  35783. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  35784. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  35785. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  35786. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  35787. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  35788. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  35789. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  35790. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  35791. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  35792. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  35793. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  35794. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  35795. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  35796. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  35797. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  35798. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  35799. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  35800. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  35801. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  35802. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  35803. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  35804. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  35805. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  35806. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  35807. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  35808. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  35809. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  35810. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  35811. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  35812. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  35813. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  35814. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  35815. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  35816. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  35817. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  35818. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  35819. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  35820. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  35821. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  35822. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  35823. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  35824. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  35825. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  35826. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  35827. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  35828. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  35829. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  35830. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  35831. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  35832. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  35833. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  35834. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  35835. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  35836. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  35837. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  35838. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  35839. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  35840. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  35841. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  35842. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  35843. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  35844. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  35845. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  35846. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  35847. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  35848. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  35849. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  35850. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  35851. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  35852. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  35853. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  35854. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  35855. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  35856. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  35857. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  35858. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  35859. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  35860. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  35861. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  35862. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  35863. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  35864. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  35865. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  35866. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  35867. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  35868. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  35869. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  35870. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  35871. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  35872. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  35873. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  35874. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  35875. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  35876. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  35877. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  35878. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  35879. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  35880. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  35881. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  35882. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  35883. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  35884. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  35885. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  35886. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  35887. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  35888. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  35889. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  35890. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  35891. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  35892. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  35893. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  35894. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  35895. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  35896. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  35897. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  35898. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  35899. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  35900. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  35901. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  35902. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  35903. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  35904. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  35905. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  35906. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  35907. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  35908. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  35909. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  35910. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  35911. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  35912. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  35913. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  35914. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  35915. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  35916. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  35917. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  35918. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  35919. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  35920. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  35921. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  35922. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  35923. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  35924. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  35925. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  35926. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  35927. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  35928. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  35929. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  35930. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  35931. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  35932. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  35933. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  35934. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  35935. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  35936. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  35937. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  35938. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  35939. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  35940. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  35941. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  35942. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  35943. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  35944. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  35945. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  35946. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  35947. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  35948. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  35949. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  35950. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  35951. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  35952. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  35953. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  35954. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  35955. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  35956. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  35957. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  35958. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  35959. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  35960. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  35961. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  35962. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  35963. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  35964. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  35965. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  35966. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  35967. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  35968. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  35969. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  35970. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  35971. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  35972. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  35973. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  35974. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  35975. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  35976. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  35977. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  35978. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  35979. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  35980. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  35981. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35982. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35983. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35984. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35985. 0x06, 0x17, 0x23, 0x2E
  35986. };
  35987. #endif
  35988. #ifndef WOLFSSL_NO_ML_DSA_65
  35989. static const byte sk_65[] = {
  35990. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  35991. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  35992. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  35993. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  35994. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  35995. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  35996. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  35997. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  35998. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  35999. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  36000. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  36001. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  36002. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  36003. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  36004. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  36005. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  36006. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  36007. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  36008. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  36009. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  36010. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  36011. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  36012. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  36013. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  36014. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  36015. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  36016. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  36017. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  36018. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  36019. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  36020. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  36021. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  36022. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  36023. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  36024. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  36025. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  36026. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  36027. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  36028. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  36029. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  36030. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  36031. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  36032. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  36033. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  36034. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  36035. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  36036. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  36037. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  36038. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  36039. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  36040. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  36041. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  36042. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  36043. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  36044. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  36045. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  36046. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  36047. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  36048. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  36049. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  36050. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  36051. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  36052. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  36053. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  36054. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  36055. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  36056. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  36057. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  36058. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  36059. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  36060. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  36061. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  36062. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  36063. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  36064. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  36065. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  36066. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  36067. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  36068. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  36069. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  36070. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  36071. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  36072. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  36073. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  36074. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  36075. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  36076. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  36077. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  36078. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  36079. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  36080. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  36081. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  36082. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  36083. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  36084. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  36085. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  36086. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  36087. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  36088. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  36089. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  36090. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  36091. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  36092. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  36093. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  36094. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  36095. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  36096. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  36097. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  36098. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  36099. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  36100. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  36101. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  36102. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  36103. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  36104. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  36105. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  36106. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  36107. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  36108. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  36109. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  36110. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  36111. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  36112. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  36113. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  36114. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  36115. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  36116. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  36117. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  36118. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  36119. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  36120. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  36121. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  36122. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  36123. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  36124. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  36125. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  36126. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  36127. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  36128. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  36129. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  36130. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  36131. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  36132. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  36133. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  36134. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  36135. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  36136. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  36137. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  36138. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  36139. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  36140. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  36141. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  36142. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  36143. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  36144. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  36145. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  36146. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  36147. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  36148. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  36149. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  36150. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  36151. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  36152. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  36153. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  36154. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  36155. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  36156. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  36157. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  36158. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  36159. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  36160. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  36161. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  36162. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  36163. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  36164. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  36165. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  36166. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  36167. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  36168. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  36169. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  36170. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  36171. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  36172. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  36173. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  36174. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  36175. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  36176. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  36177. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  36178. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  36179. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  36180. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  36181. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  36182. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  36183. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  36184. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  36185. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  36186. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  36187. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  36188. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  36189. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  36190. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  36191. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  36192. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  36193. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  36194. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  36195. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  36196. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  36197. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  36198. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  36199. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  36200. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  36201. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  36202. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  36203. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  36204. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  36205. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  36206. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  36207. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  36208. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  36209. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  36210. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  36211. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  36212. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  36213. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  36214. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  36215. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  36216. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  36217. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  36218. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  36219. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  36220. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  36221. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  36222. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  36223. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  36224. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  36225. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  36226. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  36227. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  36228. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  36229. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  36230. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  36231. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  36232. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  36233. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  36234. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  36235. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  36236. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  36237. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  36238. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  36239. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  36240. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  36241. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  36242. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  36243. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  36244. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  36245. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  36246. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  36247. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  36248. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  36249. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  36250. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  36251. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  36252. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  36253. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  36254. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  36255. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  36256. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  36257. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  36258. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  36259. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  36260. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  36261. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  36262. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  36263. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  36264. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  36265. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  36266. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  36267. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  36268. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  36269. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  36270. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  36271. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  36272. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  36273. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  36274. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  36275. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  36276. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  36277. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  36278. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  36279. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  36280. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  36281. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  36282. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  36283. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  36284. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  36285. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  36286. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  36287. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  36288. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  36289. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  36290. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  36291. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  36292. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  36293. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  36294. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  36295. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  36296. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  36297. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  36298. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  36299. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  36300. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  36301. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  36302. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  36303. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  36304. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  36305. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  36306. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  36307. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  36308. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  36309. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  36310. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  36311. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  36312. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  36313. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  36314. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  36315. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  36316. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  36317. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  36318. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  36319. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  36320. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  36321. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  36322. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  36323. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  36324. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  36325. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  36326. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  36327. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  36328. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  36329. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  36330. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  36331. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  36332. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  36333. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  36334. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  36335. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  36336. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  36337. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  36338. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  36339. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  36340. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  36341. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  36342. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  36343. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  36344. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  36345. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  36346. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  36347. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  36348. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  36349. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  36350. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  36351. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  36352. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  36353. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  36354. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  36355. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  36356. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  36357. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  36358. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  36359. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  36360. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  36361. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  36362. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  36363. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  36364. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  36365. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  36366. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  36367. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  36368. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  36369. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  36370. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  36371. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  36372. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  36373. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  36374. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  36375. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  36376. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  36377. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  36378. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  36379. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  36380. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  36381. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  36382. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  36383. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  36384. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  36385. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  36386. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  36387. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  36388. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  36389. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  36390. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  36391. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  36392. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  36393. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  36394. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  36395. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  36396. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  36397. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  36398. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  36399. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  36400. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  36401. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  36402. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  36403. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  36404. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  36405. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  36406. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  36407. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  36408. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  36409. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  36410. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  36411. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  36412. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  36413. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  36414. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  36415. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  36416. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  36417. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  36418. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  36419. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  36420. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  36421. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  36422. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  36423. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  36424. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  36425. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  36426. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  36427. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  36428. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  36429. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  36430. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  36431. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  36432. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  36433. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  36434. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  36435. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  36436. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  36437. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  36438. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  36439. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  36440. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  36441. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  36442. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  36443. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  36444. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  36445. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  36446. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  36447. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  36448. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  36449. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  36450. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  36451. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  36452. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  36453. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  36454. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  36455. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  36456. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  36457. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  36458. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  36459. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  36460. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  36461. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  36462. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  36463. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  36464. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  36465. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  36466. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  36467. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  36468. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  36469. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  36470. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  36471. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  36472. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  36473. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  36474. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  36475. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  36476. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  36477. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  36478. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  36479. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  36480. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  36481. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  36482. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  36483. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  36484. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  36485. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  36486. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  36487. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  36488. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  36489. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  36490. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  36491. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  36492. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  36493. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  36494. };
  36495. static const byte msg_65[] = {
  36496. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  36497. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  36498. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  36499. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  36500. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  36501. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  36502. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  36503. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  36504. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  36505. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  36506. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  36507. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  36508. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  36509. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  36510. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  36511. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  36512. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  36513. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  36514. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  36515. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  36516. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  36517. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  36518. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  36519. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  36520. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  36521. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  36522. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  36523. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  36524. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  36525. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  36526. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  36527. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  36528. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  36529. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  36530. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  36531. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  36532. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  36533. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  36534. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  36535. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  36536. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  36537. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  36538. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  36539. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  36540. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  36541. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  36542. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  36543. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  36544. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  36545. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  36546. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  36547. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  36548. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  36549. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  36550. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  36551. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  36552. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  36553. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  36554. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  36555. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  36556. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  36557. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  36558. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  36559. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  36560. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  36561. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  36562. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  36563. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  36564. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  36565. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  36566. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  36567. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  36568. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  36569. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  36570. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  36571. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  36572. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  36573. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  36574. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  36575. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  36576. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  36577. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  36578. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  36579. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  36580. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  36581. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  36582. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  36583. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  36584. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  36585. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  36586. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  36587. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  36588. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  36589. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  36590. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  36591. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  36592. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  36593. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  36594. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  36595. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  36596. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  36597. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  36598. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  36599. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  36600. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  36601. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  36602. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  36603. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  36604. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  36605. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  36606. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  36607. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  36608. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  36609. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  36610. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  36611. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  36612. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  36613. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  36614. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  36615. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  36616. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  36617. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  36618. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  36619. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  36620. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  36621. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  36622. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  36623. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  36624. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  36625. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  36626. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  36627. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  36628. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  36629. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  36630. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  36631. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  36632. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  36633. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  36634. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  36635. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  36636. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  36637. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  36638. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  36639. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  36640. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  36641. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  36642. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  36643. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  36644. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  36645. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  36646. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  36647. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  36648. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  36649. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  36650. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  36651. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  36652. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  36653. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  36654. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  36655. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  36656. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  36657. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  36658. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  36659. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  36660. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  36661. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  36662. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  36663. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  36664. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  36665. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  36666. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  36667. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  36668. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  36669. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  36670. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  36671. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  36672. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  36673. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  36674. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  36675. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  36676. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  36677. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  36678. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  36679. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  36680. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  36681. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  36682. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  36683. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  36684. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  36685. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  36686. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  36687. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  36688. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  36689. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  36690. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  36691. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  36692. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  36693. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  36694. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  36695. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  36696. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  36697. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  36698. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  36699. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  36700. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  36701. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  36702. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  36703. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  36704. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  36705. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  36706. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  36707. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  36708. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  36709. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  36710. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  36711. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  36712. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  36713. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  36714. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  36715. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  36716. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  36717. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  36718. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  36719. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  36720. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  36721. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  36722. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  36723. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  36724. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  36725. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  36726. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  36727. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  36728. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  36729. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  36730. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  36731. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  36732. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  36733. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  36734. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  36735. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  36736. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  36737. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  36738. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  36739. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  36740. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  36741. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  36742. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  36743. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  36744. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  36745. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  36746. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  36747. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  36748. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  36749. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  36750. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  36751. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  36752. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  36753. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  36754. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  36755. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  36756. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  36757. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  36758. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  36759. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  36760. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  36761. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  36762. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  36763. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  36764. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  36765. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  36766. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  36767. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  36768. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  36769. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  36770. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  36771. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  36772. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  36773. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  36774. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  36775. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  36776. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  36777. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  36778. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  36779. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  36780. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  36781. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  36782. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  36783. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  36784. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  36785. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  36786. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  36787. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  36788. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  36789. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  36790. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  36791. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  36792. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  36793. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  36794. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  36795. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  36796. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  36797. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  36798. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  36799. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  36800. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  36801. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  36802. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  36803. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  36804. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  36805. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  36806. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  36807. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  36808. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  36809. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  36810. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  36811. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  36812. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  36813. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  36814. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  36815. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  36816. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  36817. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  36818. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  36819. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  36820. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  36821. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  36822. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  36823. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  36824. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  36825. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  36826. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  36827. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  36828. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  36829. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  36830. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  36831. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  36832. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  36833. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  36834. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  36835. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  36836. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  36837. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  36838. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  36839. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  36840. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  36841. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  36842. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  36843. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  36844. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  36845. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  36846. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  36847. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  36848. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  36849. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  36850. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  36851. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  36852. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  36853. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  36854. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  36855. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  36856. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  36857. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  36858. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  36859. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  36860. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  36861. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  36862. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  36863. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  36864. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  36865. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  36866. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  36867. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  36868. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  36869. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  36870. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  36871. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  36872. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  36873. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  36874. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  36875. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  36876. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  36877. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  36878. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  36879. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  36880. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  36881. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  36882. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  36883. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  36884. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  36885. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  36886. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  36887. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  36888. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  36889. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  36890. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  36891. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  36892. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  36893. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  36894. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  36895. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  36896. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  36897. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  36898. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  36899. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  36900. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  36901. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  36902. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  36903. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  36904. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  36905. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  36906. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  36907. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  36908. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  36909. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  36910. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  36911. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  36912. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  36913. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  36914. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  36915. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  36916. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  36917. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  36918. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  36919. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  36920. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  36921. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  36922. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  36923. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  36924. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  36925. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  36926. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  36927. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  36928. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  36929. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  36930. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  36931. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  36932. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  36933. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  36934. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  36935. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  36936. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  36937. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  36938. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  36939. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  36940. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  36941. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  36942. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  36943. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  36944. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  36945. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  36946. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  36947. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  36948. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  36949. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  36950. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  36951. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  36952. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  36953. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  36954. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  36955. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  36956. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  36957. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  36958. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  36959. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  36960. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  36961. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  36962. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  36963. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  36964. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  36965. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  36966. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  36967. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  36968. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  36969. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  36970. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  36971. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  36972. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  36973. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  36974. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  36975. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  36976. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  36977. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  36978. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  36979. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  36980. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  36981. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  36982. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  36983. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  36984. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  36985. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  36986. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  36987. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  36988. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  36989. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  36990. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  36991. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  36992. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  36993. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  36994. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  36995. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  36996. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  36997. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  36998. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  36999. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  37000. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  37001. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  37002. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  37003. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  37004. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  37005. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  37006. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  37007. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  37008. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  37009. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  37010. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  37011. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  37012. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  37013. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  37014. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  37015. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  37016. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  37017. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  37018. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  37019. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  37020. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  37021. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  37022. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  37023. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  37024. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  37025. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  37026. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  37027. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  37028. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  37029. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  37030. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  37031. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  37032. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  37033. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  37034. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  37035. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  37036. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  37037. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  37038. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  37039. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  37040. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  37041. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  37042. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  37043. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  37044. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  37045. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  37046. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  37047. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  37048. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  37049. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  37050. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  37051. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  37052. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  37053. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  37054. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  37055. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  37056. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  37057. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  37058. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  37059. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  37060. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  37061. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  37062. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  37063. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  37064. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  37065. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  37066. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  37067. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  37068. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  37069. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  37070. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  37071. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  37072. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  37073. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  37074. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  37075. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  37076. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  37077. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  37078. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  37079. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  37080. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  37081. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  37082. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  37083. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  37084. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  37085. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  37086. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  37087. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  37088. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  37089. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  37090. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  37091. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  37092. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  37093. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  37094. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  37095. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  37096. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  37097. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  37098. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  37099. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  37100. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  37101. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  37102. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  37103. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  37104. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  37105. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  37106. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  37107. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  37108. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  37109. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  37110. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  37111. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  37112. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  37113. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  37114. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  37115. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  37116. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  37117. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  37118. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  37119. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  37120. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  37121. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  37122. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  37123. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  37124. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  37125. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  37126. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  37127. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  37128. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  37129. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  37130. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  37131. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  37132. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  37133. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  37134. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  37135. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  37136. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  37137. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  37138. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  37139. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  37140. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  37141. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  37142. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  37143. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  37144. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  37145. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  37146. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  37147. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  37148. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  37149. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  37150. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  37151. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  37152. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  37153. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  37154. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  37155. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  37156. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  37157. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  37158. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  37159. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  37160. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  37161. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  37162. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  37163. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  37164. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  37165. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  37166. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  37167. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  37168. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  37169. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  37170. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  37171. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  37172. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  37173. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  37174. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  37175. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  37176. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  37177. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  37178. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  37179. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  37180. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  37181. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  37182. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  37183. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  37184. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  37185. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  37186. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  37187. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  37188. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  37189. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  37190. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  37191. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  37192. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  37193. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  37194. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  37195. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  37196. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  37197. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  37198. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  37199. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  37200. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  37201. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  37202. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  37203. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  37204. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  37205. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  37206. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  37207. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  37208. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  37209. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  37210. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  37211. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  37212. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  37213. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  37214. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  37215. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  37216. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  37217. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  37218. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  37219. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  37220. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  37221. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  37222. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  37223. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  37224. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  37225. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  37226. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  37227. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  37228. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  37229. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  37230. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  37231. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  37232. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  37233. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  37234. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  37235. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  37236. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  37237. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  37238. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  37239. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  37240. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  37241. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  37242. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  37243. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  37244. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  37245. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  37246. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  37247. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  37248. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  37249. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  37250. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  37251. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  37252. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  37253. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  37254. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  37255. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  37256. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  37257. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  37258. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  37259. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  37260. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  37261. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  37262. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  37263. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  37264. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  37265. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  37266. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  37267. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  37268. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  37269. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  37270. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  37271. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  37272. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  37273. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  37274. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  37275. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  37276. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  37277. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  37278. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  37279. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  37280. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  37281. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  37282. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  37283. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  37284. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  37285. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  37286. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  37287. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  37288. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  37289. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  37290. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  37291. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  37292. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  37293. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  37294. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  37295. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  37296. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  37297. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  37298. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  37299. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  37300. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  37301. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  37302. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  37303. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  37304. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  37305. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  37306. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  37307. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  37308. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  37309. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  37310. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  37311. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  37312. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  37313. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  37314. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  37315. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  37316. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  37317. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  37318. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  37319. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  37320. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  37321. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  37322. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  37323. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  37324. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  37325. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  37326. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  37327. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  37328. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  37329. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  37330. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  37331. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  37332. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  37333. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  37334. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  37335. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  37336. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  37337. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  37338. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  37339. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  37340. 0x60, 0x28, 0x77, 0xEE
  37341. };
  37342. static const byte rnd_65[] = {
  37343. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  37344. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  37345. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  37346. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  37347. };
  37348. static const byte sig_65[] = {
  37349. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  37350. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  37351. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  37352. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  37353. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  37354. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  37355. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  37356. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  37357. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  37358. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  37359. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  37360. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  37361. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  37362. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  37363. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  37364. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  37365. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  37366. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  37367. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  37368. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  37369. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  37370. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  37371. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  37372. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  37373. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  37374. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  37375. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  37376. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  37377. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  37378. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  37379. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  37380. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  37381. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  37382. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  37383. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  37384. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  37385. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  37386. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  37387. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  37388. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  37389. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  37390. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  37391. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  37392. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  37393. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  37394. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  37395. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  37396. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  37397. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  37398. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  37399. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  37400. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  37401. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  37402. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  37403. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  37404. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  37405. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  37406. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  37407. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  37408. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  37409. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  37410. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  37411. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  37412. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  37413. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  37414. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  37415. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  37416. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  37417. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  37418. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  37419. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  37420. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  37421. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  37422. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  37423. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  37424. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  37425. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  37426. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  37427. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  37428. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  37429. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  37430. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  37431. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  37432. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  37433. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  37434. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  37435. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  37436. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  37437. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  37438. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  37439. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  37440. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  37441. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  37442. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  37443. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  37444. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  37445. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  37446. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  37447. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  37448. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  37449. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  37450. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  37451. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  37452. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  37453. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  37454. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  37455. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  37456. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  37457. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  37458. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  37459. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  37460. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  37461. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  37462. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  37463. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  37464. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  37465. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  37466. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  37467. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  37468. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  37469. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  37470. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  37471. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  37472. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  37473. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  37474. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  37475. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  37476. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  37477. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  37478. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  37479. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  37480. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  37481. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  37482. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  37483. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  37484. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  37485. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  37486. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  37487. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  37488. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  37489. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  37490. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  37491. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  37492. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  37493. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  37494. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  37495. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  37496. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  37497. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  37498. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  37499. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  37500. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  37501. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  37502. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  37503. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  37504. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  37505. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  37506. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  37507. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  37508. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  37509. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  37510. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  37511. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  37512. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  37513. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  37514. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  37515. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  37516. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  37517. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  37518. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  37519. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  37520. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  37521. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  37522. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  37523. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  37524. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  37525. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  37526. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  37527. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  37528. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  37529. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  37530. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  37531. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  37532. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  37533. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  37534. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  37535. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  37536. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  37537. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  37538. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  37539. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  37540. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  37541. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  37542. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  37543. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  37544. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  37545. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  37546. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  37547. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  37548. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  37549. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  37550. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  37551. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  37552. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  37553. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  37554. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  37555. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  37556. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  37557. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  37558. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  37559. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  37560. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  37561. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  37562. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  37563. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  37564. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  37565. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  37566. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  37567. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  37568. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  37569. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  37570. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  37571. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  37572. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  37573. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  37574. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  37575. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  37576. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  37577. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  37578. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  37579. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  37580. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  37581. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  37582. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  37583. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  37584. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  37585. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  37586. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  37587. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  37588. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  37589. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  37590. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  37591. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  37592. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  37593. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  37594. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  37595. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  37596. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  37597. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  37598. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  37599. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  37600. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  37601. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  37602. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  37603. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  37604. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  37605. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  37606. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  37607. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  37608. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  37609. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  37610. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  37611. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  37612. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  37613. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  37614. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  37615. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  37616. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  37617. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  37618. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  37619. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  37620. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  37621. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  37622. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  37623. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  37624. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  37625. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  37626. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  37627. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  37628. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  37629. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  37630. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  37631. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  37632. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  37633. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  37634. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  37635. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  37636. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  37637. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  37638. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  37639. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  37640. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  37641. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  37642. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  37643. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  37644. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  37645. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  37646. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  37647. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  37648. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  37649. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  37650. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  37651. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  37652. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  37653. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  37654. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  37655. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  37656. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  37657. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  37658. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  37659. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  37660. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  37661. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  37662. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  37663. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  37664. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  37665. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  37666. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  37667. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  37668. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  37669. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  37670. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  37671. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  37672. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  37673. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  37674. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  37675. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  37676. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  37677. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  37678. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  37679. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  37680. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  37681. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  37682. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  37683. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  37684. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  37685. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  37686. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  37687. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  37688. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  37689. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  37690. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  37691. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  37692. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  37693. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  37694. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  37695. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  37696. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  37697. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  37698. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  37699. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  37700. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  37701. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  37702. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  37703. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  37704. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  37705. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  37706. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  37707. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  37708. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  37709. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  37710. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  37711. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  37712. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  37713. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  37714. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  37715. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  37716. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  37717. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  37718. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  37719. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  37720. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  37721. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  37722. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  37723. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  37724. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  37725. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  37726. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  37727. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  37728. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  37729. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  37730. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  37731. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  37732. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  37733. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  37734. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  37735. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  37736. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  37737. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  37738. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  37739. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  37740. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  37741. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  37742. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  37743. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  37744. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  37745. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  37746. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  37747. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  37748. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  37749. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  37750. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  37751. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  37752. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  37753. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  37754. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  37755. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  37756. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  37757. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  37758. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  37759. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  37760. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37761. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  37762. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  37763. };
  37764. #endif
  37765. #ifndef WOLFSSL_NO_ML_DSA_87
  37766. static const byte sk_87[] = {
  37767. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  37768. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  37769. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  37770. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  37771. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  37772. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  37773. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  37774. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  37775. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  37776. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  37777. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  37778. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  37779. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  37780. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  37781. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  37782. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  37783. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  37784. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  37785. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  37786. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  37787. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  37788. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  37789. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  37790. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  37791. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  37792. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  37793. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  37794. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  37795. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  37796. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  37797. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  37798. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  37799. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  37800. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  37801. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  37802. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  37803. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  37804. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  37805. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  37806. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  37807. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  37808. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  37809. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  37810. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  37811. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  37812. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  37813. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  37814. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  37815. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  37816. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  37817. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  37818. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  37819. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  37820. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  37821. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  37822. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  37823. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  37824. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  37825. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  37826. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  37827. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  37828. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  37829. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  37830. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  37831. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  37832. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  37833. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  37834. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  37835. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  37836. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  37837. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  37838. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  37839. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  37840. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  37841. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  37842. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  37843. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  37844. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  37845. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  37846. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  37847. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  37848. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  37849. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  37850. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  37851. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  37852. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  37853. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  37854. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  37855. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  37856. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  37857. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  37858. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  37859. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  37860. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  37861. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  37862. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  37863. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  37864. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  37865. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  37866. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  37867. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  37868. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  37869. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  37870. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  37871. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  37872. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  37873. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  37874. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  37875. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  37876. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  37877. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  37878. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  37879. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  37880. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  37881. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  37882. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  37883. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  37884. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  37885. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  37886. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  37887. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  37888. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  37889. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  37890. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  37891. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  37892. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  37893. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  37894. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  37895. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  37896. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  37897. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  37898. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  37899. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  37900. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  37901. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  37902. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  37903. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  37904. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  37905. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  37906. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  37907. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  37908. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  37909. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  37910. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  37911. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  37912. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  37913. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  37914. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  37915. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  37916. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  37917. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  37918. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  37919. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  37920. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  37921. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  37922. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  37923. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  37924. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  37925. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  37926. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  37927. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  37928. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  37929. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  37930. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  37931. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  37932. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  37933. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  37934. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  37935. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  37936. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  37937. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  37938. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  37939. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  37940. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  37941. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  37942. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  37943. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  37944. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  37945. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  37946. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  37947. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  37948. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  37949. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  37950. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  37951. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  37952. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  37953. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  37954. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  37955. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  37956. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  37957. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  37958. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  37959. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  37960. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  37961. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  37962. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  37963. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  37964. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  37965. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  37966. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  37967. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  37968. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  37969. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  37970. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  37971. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  37972. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  37973. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  37974. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  37975. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  37976. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  37977. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  37978. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  37979. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  37980. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  37981. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  37982. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  37983. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  37984. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  37985. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  37986. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  37987. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  37988. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  37989. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  37990. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  37991. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  37992. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  37993. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  37994. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  37995. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  37996. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  37997. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  37998. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  37999. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  38000. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  38001. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  38002. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  38003. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  38004. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  38005. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  38006. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  38007. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  38008. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  38009. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  38010. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  38011. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  38012. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  38013. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  38014. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  38015. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  38016. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  38017. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  38018. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  38019. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  38020. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  38021. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  38022. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  38023. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  38024. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  38025. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  38026. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  38027. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  38028. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  38029. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  38030. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  38031. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  38032. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  38033. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  38034. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  38035. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  38036. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  38037. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  38038. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  38039. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  38040. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  38041. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  38042. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  38043. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  38044. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  38045. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  38046. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  38047. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  38048. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  38049. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  38050. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  38051. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  38052. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  38053. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  38054. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  38055. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  38056. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  38057. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  38058. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  38059. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  38060. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  38061. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  38062. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  38063. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  38064. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  38065. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  38066. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  38067. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  38068. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  38069. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  38070. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  38071. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  38072. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  38073. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  38074. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  38075. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  38076. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  38077. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  38078. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  38079. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  38080. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  38081. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  38082. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  38083. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  38084. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  38085. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  38086. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  38087. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  38088. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  38089. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  38090. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  38091. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  38092. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  38093. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  38094. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  38095. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  38096. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  38097. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  38098. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  38099. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  38100. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  38101. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  38102. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  38103. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  38104. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  38105. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  38106. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  38107. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  38108. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  38109. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  38110. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  38111. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  38112. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  38113. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  38114. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  38115. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  38116. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  38117. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  38118. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  38119. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  38120. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  38121. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  38122. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  38123. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  38124. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  38125. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  38126. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  38127. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  38128. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  38129. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  38130. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  38131. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  38132. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  38133. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  38134. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  38135. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  38136. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  38137. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  38138. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  38139. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  38140. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  38141. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  38142. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  38143. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  38144. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  38145. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  38146. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  38147. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  38148. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  38149. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  38150. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  38151. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  38152. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  38153. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  38154. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  38155. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  38156. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  38157. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  38158. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  38159. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  38160. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  38161. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  38162. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  38163. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  38164. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  38165. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  38166. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  38167. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  38168. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  38169. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  38170. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  38171. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  38172. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  38173. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  38174. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  38175. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  38176. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  38177. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  38178. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  38179. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  38180. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  38181. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  38182. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  38183. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  38184. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  38185. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  38186. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  38187. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  38188. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  38189. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  38190. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  38191. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  38192. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  38193. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  38194. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  38195. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  38196. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  38197. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  38198. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  38199. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  38200. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  38201. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  38202. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  38203. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  38204. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  38205. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  38206. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  38207. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  38208. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  38209. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  38210. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  38211. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  38212. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  38213. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  38214. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  38215. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  38216. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  38217. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  38218. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  38219. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  38220. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  38221. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  38222. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  38223. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  38224. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  38225. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  38226. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  38227. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  38228. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  38229. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  38230. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  38231. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  38232. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  38233. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  38234. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  38235. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  38236. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  38237. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  38238. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  38239. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  38240. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  38241. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  38242. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  38243. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  38244. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  38245. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  38246. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  38247. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  38248. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  38249. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  38250. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  38251. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  38252. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  38253. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  38254. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  38255. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  38256. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  38257. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  38258. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  38259. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  38260. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  38261. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  38262. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  38263. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  38264. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  38265. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  38266. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  38267. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  38268. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  38269. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  38270. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  38271. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  38272. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  38273. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  38274. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  38275. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  38276. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  38277. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  38278. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  38279. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  38280. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  38281. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  38282. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  38283. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  38284. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  38285. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  38286. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  38287. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  38288. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  38289. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  38290. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  38291. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  38292. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  38293. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  38294. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  38295. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  38296. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  38297. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  38298. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  38299. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  38300. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  38301. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  38302. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  38303. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  38304. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  38305. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  38306. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  38307. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  38308. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  38309. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  38310. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  38311. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  38312. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  38313. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  38314. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  38315. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  38316. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  38317. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  38318. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  38319. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  38320. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  38321. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  38322. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  38323. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  38324. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  38325. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  38326. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  38327. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  38328. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  38329. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  38330. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  38331. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  38332. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  38333. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  38334. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  38335. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  38336. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  38337. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  38338. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  38339. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  38340. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  38341. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  38342. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  38343. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  38344. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  38345. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  38346. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  38347. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  38348. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  38349. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  38350. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  38351. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  38352. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  38353. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  38354. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  38355. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  38356. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  38357. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  38358. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  38359. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  38360. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  38361. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  38362. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  38363. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  38364. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  38365. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  38366. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  38367. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  38368. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  38369. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  38370. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  38371. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  38372. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  38373. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  38374. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  38375. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  38376. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  38377. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  38378. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  38379. };
  38380. static const byte msg_87[] = {
  38381. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  38382. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  38383. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  38384. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  38385. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  38386. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  38387. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  38388. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  38389. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  38390. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  38391. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  38392. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  38393. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  38394. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  38395. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  38396. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  38397. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  38398. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  38399. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  38400. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  38401. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  38402. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  38403. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  38404. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  38405. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  38406. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  38407. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  38408. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  38409. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  38410. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  38411. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  38412. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  38413. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  38414. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  38415. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  38416. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  38417. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  38418. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  38419. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  38420. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  38421. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  38422. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  38423. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  38424. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  38425. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  38426. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  38427. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  38428. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  38429. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  38430. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  38431. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  38432. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  38433. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  38434. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  38435. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  38436. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  38437. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  38438. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  38439. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  38440. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  38441. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  38442. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  38443. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  38444. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  38445. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  38446. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  38447. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  38448. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  38449. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  38450. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  38451. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  38452. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  38453. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  38454. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  38455. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  38456. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  38457. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  38458. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  38459. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  38460. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  38461. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  38462. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  38463. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  38464. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  38465. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  38466. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  38467. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  38468. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  38469. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  38470. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  38471. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  38472. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  38473. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  38474. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  38475. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  38476. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  38477. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  38478. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  38479. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  38480. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  38481. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  38482. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  38483. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  38484. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  38485. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  38486. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  38487. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  38488. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  38489. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  38490. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  38491. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  38492. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  38493. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  38494. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  38495. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  38496. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  38497. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  38498. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  38499. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  38500. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  38501. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  38502. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  38503. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  38504. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  38505. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  38506. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  38507. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  38508. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  38509. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  38510. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  38511. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  38512. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  38513. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  38514. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  38515. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  38516. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  38517. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  38518. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  38519. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  38520. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  38521. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  38522. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  38523. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  38524. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  38525. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  38526. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  38527. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  38528. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  38529. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  38530. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  38531. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  38532. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  38533. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  38534. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  38535. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  38536. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  38537. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  38538. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  38539. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  38540. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  38541. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  38542. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  38543. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  38544. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  38545. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  38546. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  38547. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  38548. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  38549. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  38550. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  38551. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  38552. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  38553. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  38554. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  38555. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  38556. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  38557. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  38558. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  38559. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  38560. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  38561. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  38562. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  38563. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  38564. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  38565. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  38566. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  38567. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  38568. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  38569. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  38570. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  38571. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  38572. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  38573. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  38574. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  38575. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  38576. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  38577. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  38578. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  38579. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  38580. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  38581. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  38582. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  38583. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  38584. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  38585. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  38586. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  38587. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  38588. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  38589. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  38590. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  38591. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  38592. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  38593. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  38594. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  38595. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  38596. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  38597. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  38598. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  38599. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  38600. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  38601. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  38602. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  38603. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  38604. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  38605. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  38606. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  38607. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  38608. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  38609. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  38610. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  38611. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  38612. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  38613. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  38614. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  38615. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  38616. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  38617. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  38618. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  38619. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  38620. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  38621. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  38622. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  38623. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  38624. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  38625. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  38626. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  38627. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  38628. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  38629. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  38630. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  38631. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  38632. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  38633. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  38634. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  38635. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  38636. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  38637. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  38638. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  38639. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  38640. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  38641. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  38642. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  38643. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  38644. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  38645. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  38646. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  38647. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  38648. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  38649. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  38650. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  38651. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  38652. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  38653. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  38654. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  38655. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  38656. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  38657. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  38658. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  38659. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  38660. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  38661. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  38662. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  38663. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  38664. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  38665. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  38666. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  38667. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  38668. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  38669. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  38670. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  38671. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  38672. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  38673. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  38674. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  38675. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  38676. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  38677. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  38678. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  38679. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  38680. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  38681. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  38682. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  38683. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  38684. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  38685. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  38686. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  38687. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  38688. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  38689. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  38690. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  38691. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  38692. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  38693. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  38694. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  38695. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  38696. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  38697. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  38698. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  38699. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  38700. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  38701. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  38702. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  38703. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  38704. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  38705. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  38706. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  38707. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  38708. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  38709. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  38710. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  38711. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  38712. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  38713. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  38714. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  38715. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  38716. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  38717. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  38718. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  38719. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  38720. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  38721. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  38722. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  38723. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  38724. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  38725. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  38726. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  38727. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  38728. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  38729. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  38730. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  38731. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  38732. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  38733. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  38734. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  38735. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  38736. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  38737. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  38738. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  38739. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  38740. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  38741. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  38742. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  38743. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  38744. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  38745. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  38746. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  38747. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  38748. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  38749. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  38750. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  38751. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  38752. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  38753. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  38754. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  38755. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  38756. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  38757. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  38758. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  38759. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  38760. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  38761. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  38762. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  38763. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  38764. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  38765. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  38766. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  38767. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  38768. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  38769. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  38770. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  38771. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  38772. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  38773. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  38774. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  38775. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  38776. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  38777. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  38778. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  38779. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  38780. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  38781. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  38782. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  38783. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  38784. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  38785. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  38786. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  38787. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  38788. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  38789. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  38790. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  38791. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  38792. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  38793. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  38794. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  38795. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  38796. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  38797. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  38798. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  38799. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  38800. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  38801. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  38802. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  38803. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  38804. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  38805. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  38806. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  38807. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  38808. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  38809. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  38810. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  38811. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  38812. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  38813. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  38814. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  38815. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  38816. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  38817. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  38818. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  38819. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  38820. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  38821. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  38822. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  38823. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  38824. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  38825. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  38826. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  38827. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  38828. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  38829. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  38830. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  38831. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  38832. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  38833. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  38834. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  38835. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  38836. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  38837. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  38838. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  38839. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  38840. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  38841. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  38842. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  38843. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  38844. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  38845. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  38846. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  38847. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  38848. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  38849. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  38850. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  38851. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  38852. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  38853. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  38854. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  38855. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  38856. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  38857. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  38858. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  38859. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  38860. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  38861. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  38862. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  38863. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  38864. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  38865. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  38866. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  38867. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  38868. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  38869. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  38870. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  38871. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  38872. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  38873. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  38874. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  38875. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  38876. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  38877. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  38878. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  38879. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  38880. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  38881. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  38882. 0x94, 0x82, 0x70
  38883. };
  38884. static const byte rnd_87[] = {
  38885. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  38886. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  38887. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  38888. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  38889. };
  38890. static const byte sig_87[] = {
  38891. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  38892. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  38893. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  38894. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  38895. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  38896. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  38897. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  38898. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  38899. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  38900. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  38901. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  38902. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  38903. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  38904. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  38905. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  38906. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  38907. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  38908. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  38909. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  38910. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  38911. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  38912. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  38913. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  38914. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  38915. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  38916. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  38917. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  38918. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  38919. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  38920. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  38921. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  38922. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  38923. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  38924. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  38925. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  38926. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  38927. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  38928. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  38929. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  38930. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  38931. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  38932. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  38933. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  38934. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  38935. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  38936. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  38937. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  38938. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  38939. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  38940. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  38941. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  38942. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  38943. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  38944. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  38945. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  38946. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  38947. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  38948. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  38949. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  38950. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  38951. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  38952. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  38953. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  38954. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  38955. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  38956. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  38957. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  38958. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  38959. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  38960. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  38961. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  38962. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  38963. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  38964. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  38965. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  38966. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  38967. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  38968. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  38969. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  38970. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  38971. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  38972. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  38973. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  38974. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  38975. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  38976. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  38977. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  38978. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  38979. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  38980. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  38981. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  38982. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  38983. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  38984. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  38985. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  38986. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  38987. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  38988. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  38989. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  38990. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  38991. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  38992. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  38993. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  38994. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  38995. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  38996. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  38997. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  38998. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  38999. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  39000. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  39001. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  39002. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  39003. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  39004. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  39005. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  39006. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  39007. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  39008. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  39009. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  39010. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  39011. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  39012. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  39013. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  39014. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  39015. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  39016. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  39017. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  39018. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  39019. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  39020. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  39021. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  39022. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  39023. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  39024. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  39025. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  39026. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  39027. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  39028. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  39029. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  39030. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  39031. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  39032. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  39033. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  39034. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  39035. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  39036. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  39037. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  39038. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  39039. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  39040. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  39041. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  39042. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  39043. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  39044. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  39045. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  39046. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  39047. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  39048. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  39049. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  39050. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  39051. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  39052. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  39053. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  39054. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  39055. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  39056. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  39057. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  39058. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  39059. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  39060. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  39061. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  39062. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  39063. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  39064. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  39065. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  39066. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  39067. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  39068. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  39069. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  39070. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  39071. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  39072. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  39073. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  39074. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  39075. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  39076. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  39077. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  39078. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  39079. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  39080. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  39081. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  39082. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  39083. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  39084. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  39085. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  39086. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  39087. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  39088. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  39089. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  39090. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  39091. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  39092. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  39093. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  39094. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  39095. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  39096. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  39097. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  39098. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  39099. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  39100. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  39101. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  39102. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  39103. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  39104. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  39105. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  39106. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  39107. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  39108. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  39109. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  39110. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  39111. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  39112. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  39113. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  39114. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  39115. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  39116. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  39117. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  39118. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  39119. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  39120. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  39121. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  39122. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  39123. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  39124. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  39125. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  39126. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  39127. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  39128. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  39129. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  39130. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  39131. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  39132. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  39133. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  39134. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  39135. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  39136. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  39137. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  39138. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  39139. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  39140. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  39141. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  39142. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  39143. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  39144. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  39145. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  39146. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  39147. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  39148. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  39149. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  39150. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  39151. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  39152. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  39153. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  39154. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  39155. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  39156. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  39157. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  39158. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  39159. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  39160. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  39161. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  39162. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  39163. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  39164. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  39165. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  39166. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  39167. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  39168. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  39169. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  39170. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  39171. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  39172. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  39173. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  39174. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  39175. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  39176. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  39177. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  39178. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  39179. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  39180. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  39181. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  39182. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  39183. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  39184. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  39185. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  39186. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  39187. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  39188. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  39189. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  39190. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  39191. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  39192. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  39193. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  39194. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  39195. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  39196. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  39197. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  39198. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  39199. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  39200. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  39201. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  39202. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  39203. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  39204. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  39205. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  39206. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  39207. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  39208. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  39209. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  39210. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  39211. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  39212. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  39213. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  39214. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  39215. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  39216. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  39217. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  39218. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  39219. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  39220. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  39221. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  39222. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  39223. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  39224. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  39225. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  39226. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  39227. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  39228. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  39229. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  39230. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  39231. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  39232. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  39233. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  39234. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  39235. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  39236. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  39237. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  39238. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  39239. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  39240. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  39241. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  39242. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  39243. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  39244. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  39245. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  39246. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  39247. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  39248. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  39249. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  39250. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  39251. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  39252. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  39253. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  39254. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  39255. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  39256. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  39257. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  39258. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  39259. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  39260. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  39261. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  39262. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  39263. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  39264. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  39265. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  39266. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  39267. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  39268. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  39269. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  39270. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  39271. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  39272. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  39273. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  39274. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  39275. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  39276. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  39277. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  39278. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  39279. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  39280. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  39281. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  39282. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  39283. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  39284. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  39285. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  39286. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  39287. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  39288. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  39289. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  39290. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  39291. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  39292. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  39293. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  39294. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  39295. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  39296. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  39297. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  39298. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  39299. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  39300. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  39301. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  39302. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  39303. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  39304. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  39305. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  39306. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  39307. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  39308. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  39309. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  39310. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  39311. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  39312. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  39313. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  39314. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  39315. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  39316. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  39317. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  39318. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  39319. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  39320. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  39321. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  39322. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  39323. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  39324. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  39325. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  39326. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  39327. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  39328. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  39329. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  39330. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  39331. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  39332. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  39333. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  39334. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  39335. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  39336. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  39337. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  39338. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  39339. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  39340. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  39341. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  39342. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  39343. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  39344. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  39345. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  39346. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  39347. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  39348. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  39349. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  39350. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  39351. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  39352. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  39353. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  39354. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  39355. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  39356. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  39357. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  39358. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  39359. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  39360. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  39361. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  39362. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  39363. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  39364. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  39365. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  39366. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  39367. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  39368. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  39369. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  39370. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  39371. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  39372. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  39373. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  39374. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  39375. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  39376. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  39377. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  39378. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  39379. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  39380. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  39381. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  39382. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  39383. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  39384. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  39385. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  39386. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  39387. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  39388. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  39389. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  39390. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  39391. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  39392. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  39393. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  39394. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  39395. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  39396. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  39397. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  39398. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  39399. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  39400. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  39401. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  39402. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  39403. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  39404. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  39405. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  39406. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  39407. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  39408. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  39409. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  39410. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  39411. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  39412. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  39413. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  39414. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  39415. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  39416. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  39417. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  39418. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  39419. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  39420. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  39421. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  39422. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  39423. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  39424. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  39425. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  39426. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  39427. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  39428. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  39429. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  39430. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  39431. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  39432. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  39433. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  39434. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  39435. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  39436. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  39437. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  39438. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  39439. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  39440. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  39441. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  39442. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  39443. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  39444. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  39445. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  39446. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  39447. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  39448. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  39449. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  39450. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  39451. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  39452. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  39453. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  39454. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  39455. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  39456. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  39457. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  39458. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  39459. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  39460. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  39461. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  39462. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  39463. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  39464. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  39465. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39466. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39467. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39468. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  39469. 0x27, 0x2C, 0x32
  39470. };
  39471. #endif
  39472. byte sig[DILITHIUM_MAX_SIG_SIZE];
  39473. word32 sigLen;
  39474. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39475. ExpectNotNull(key);
  39476. if (key != NULL) {
  39477. XMEMSET(key, 0, sizeof(*key));
  39478. }
  39479. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  39480. #ifndef WOLFSSL_NO_ML_DSA_44
  39481. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  39482. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  39483. 0);
  39484. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  39485. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  39486. sig, &sigLen, key, rnd_44), 0);
  39487. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  39488. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  39489. #endif
  39490. #ifndef WOLFSSL_NO_ML_DSA_65
  39491. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  39492. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  39493. 0);
  39494. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  39495. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  39496. sig, &sigLen, key, rnd_65), 0);
  39497. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  39498. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  39499. #endif
  39500. #ifndef WOLFSSL_NO_ML_DSA_87
  39501. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  39502. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  39503. 0);
  39504. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  39505. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  39506. sig, &sigLen, key, rnd_87), 0);
  39507. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  39508. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  39509. #endif
  39510. wc_dilithium_free(key);
  39511. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39512. #endif
  39513. return EXPECT_RESULT();
  39514. }
  39515. static int test_wc_dilithium_verify_kats(void)
  39516. {
  39517. EXPECT_DECLS;
  39518. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  39519. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  39520. dilithium_key* key;
  39521. int res;
  39522. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39523. #ifndef WOLFSSL_NO_ML_DSA_44
  39524. static const byte pk_44[] = {
  39525. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  39526. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  39527. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  39528. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  39529. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  39530. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  39531. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  39532. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  39533. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  39534. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  39535. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  39536. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  39537. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  39538. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  39539. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  39540. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  39541. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  39542. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  39543. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  39544. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  39545. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  39546. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  39547. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  39548. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  39549. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  39550. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  39551. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  39552. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  39553. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  39554. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  39555. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  39556. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  39557. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  39558. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  39559. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  39560. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  39561. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  39562. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  39563. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  39564. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  39565. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  39566. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  39567. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  39568. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  39569. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  39570. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  39571. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  39572. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  39573. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  39574. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  39575. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  39576. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  39577. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  39578. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  39579. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  39580. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  39581. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  39582. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  39583. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  39584. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  39585. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  39586. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  39587. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  39588. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  39589. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  39590. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  39591. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  39592. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  39593. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  39594. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  39595. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  39596. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  39597. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  39598. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  39599. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  39600. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  39601. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  39602. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  39603. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  39604. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  39605. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  39606. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  39607. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  39608. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  39609. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  39610. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  39611. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  39612. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  39613. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  39614. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  39615. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  39616. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  39617. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  39618. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  39619. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  39620. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  39621. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  39622. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  39623. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  39624. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  39625. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  39626. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  39627. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  39628. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  39629. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  39630. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  39631. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  39632. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  39633. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  39634. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  39635. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  39636. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  39637. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  39638. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  39639. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  39640. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  39641. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  39642. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  39643. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  39644. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  39645. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  39646. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  39647. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  39648. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  39649. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  39650. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  39651. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  39652. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  39653. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  39654. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  39655. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  39656. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  39657. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  39658. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  39659. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  39660. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  39661. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  39662. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  39663. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  39664. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  39665. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  39666. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  39667. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  39668. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  39669. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  39670. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  39671. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  39672. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  39673. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  39674. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  39675. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  39676. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  39677. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  39678. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  39679. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  39680. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  39681. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  39682. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  39683. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  39684. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  39685. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  39686. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  39687. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  39688. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  39689. };
  39690. static const byte msg_44[] = {
  39691. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  39692. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  39693. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  39694. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  39695. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  39696. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  39697. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  39698. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  39699. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  39700. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  39701. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  39702. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  39703. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  39704. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  39705. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  39706. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  39707. };
  39708. static const byte sig_44[] = {
  39709. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  39710. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  39711. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  39712. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  39713. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  39714. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  39715. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  39716. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  39717. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  39718. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  39719. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  39720. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  39721. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  39722. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  39723. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  39724. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  39725. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  39726. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  39727. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  39728. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  39729. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  39730. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  39731. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  39732. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  39733. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  39734. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  39735. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  39736. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  39737. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  39738. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  39739. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  39740. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  39741. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  39742. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  39743. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  39744. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  39745. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  39746. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  39747. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  39748. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  39749. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  39750. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  39751. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  39752. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  39753. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  39754. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  39755. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  39756. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  39757. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  39758. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  39759. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  39760. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  39761. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  39762. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  39763. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  39764. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  39765. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  39766. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  39767. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  39768. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  39769. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  39770. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  39771. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  39772. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  39773. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  39774. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  39775. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  39776. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  39777. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  39778. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  39779. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  39780. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  39781. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  39782. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  39783. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  39784. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  39785. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  39786. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  39787. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  39788. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  39789. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  39790. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  39791. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  39792. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  39793. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  39794. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  39795. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  39796. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  39797. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  39798. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  39799. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  39800. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  39801. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  39802. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  39803. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  39804. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  39805. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  39806. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  39807. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  39808. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  39809. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  39810. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  39811. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  39812. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  39813. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  39814. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  39815. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  39816. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  39817. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  39818. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  39819. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  39820. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  39821. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  39822. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  39823. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  39824. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  39825. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  39826. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  39827. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  39828. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  39829. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  39830. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  39831. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  39832. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  39833. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  39834. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  39835. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  39836. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  39837. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  39838. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  39839. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  39840. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  39841. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  39842. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  39843. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  39844. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  39845. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  39846. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  39847. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  39848. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  39849. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  39850. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  39851. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  39852. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  39853. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  39854. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  39855. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  39856. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  39857. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  39858. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  39859. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  39860. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  39861. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  39862. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  39863. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  39864. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  39865. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  39866. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  39867. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  39868. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  39869. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  39870. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  39871. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  39872. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  39873. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  39874. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  39875. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  39876. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  39877. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  39878. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  39879. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  39880. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  39881. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  39882. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  39883. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  39884. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  39885. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  39886. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  39887. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  39888. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  39889. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  39890. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  39891. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  39892. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  39893. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  39894. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  39895. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  39896. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  39897. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  39898. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  39899. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  39900. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  39901. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  39902. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  39903. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  39904. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  39905. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  39906. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  39907. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  39908. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  39909. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  39910. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  39911. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  39912. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  39913. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  39914. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  39915. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  39916. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  39917. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  39918. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  39919. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  39920. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  39921. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  39922. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  39923. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  39924. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  39925. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  39926. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  39927. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  39928. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  39929. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  39930. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  39931. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  39932. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  39933. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  39934. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  39935. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  39936. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  39937. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  39938. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  39939. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  39940. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  39941. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  39942. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  39943. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  39944. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  39945. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  39946. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  39947. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  39948. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  39949. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  39950. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  39951. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  39952. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  39953. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  39954. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  39955. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  39956. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  39957. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  39958. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  39959. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  39960. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  39961. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  39962. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  39963. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  39964. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  39965. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  39966. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  39967. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  39968. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  39969. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  39970. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  39971. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  39972. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  39973. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  39974. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  39975. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  39976. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  39977. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  39978. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  39979. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  39980. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  39981. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  39982. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  39983. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  39984. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  39985. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  39986. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  39987. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  39988. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  39989. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  39990. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  39991. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  39992. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  39993. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  39994. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  39995. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  39996. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  39997. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  39998. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  39999. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  40000. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  40001. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  40002. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  40003. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  40004. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  40005. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  40006. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  40007. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  40008. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40009. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40010. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40011. 0x11, 0x19, 0x28, 0x34
  40012. };
  40013. #endif
  40014. #ifndef WOLFSSL_NO_ML_DSA_65
  40015. static const byte pk_65[] = {
  40016. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  40017. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  40018. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  40019. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  40020. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  40021. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  40022. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  40023. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  40024. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  40025. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  40026. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  40027. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  40028. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  40029. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  40030. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  40031. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  40032. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  40033. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  40034. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  40035. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  40036. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  40037. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  40038. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  40039. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  40040. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  40041. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  40042. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  40043. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  40044. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  40045. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  40046. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  40047. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  40048. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  40049. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  40050. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  40051. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  40052. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  40053. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  40054. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  40055. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  40056. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  40057. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  40058. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  40059. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  40060. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  40061. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  40062. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  40063. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  40064. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  40065. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  40066. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  40067. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  40068. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  40069. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  40070. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  40071. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  40072. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  40073. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  40074. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  40075. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  40076. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  40077. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  40078. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  40079. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  40080. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  40081. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  40082. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  40083. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  40084. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  40085. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  40086. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  40087. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  40088. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  40089. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  40090. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  40091. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  40092. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  40093. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  40094. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  40095. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  40096. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  40097. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  40098. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  40099. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  40100. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  40101. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  40102. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  40103. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  40104. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  40105. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  40106. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  40107. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  40108. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  40109. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  40110. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  40111. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  40112. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  40113. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  40114. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  40115. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  40116. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  40117. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  40118. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  40119. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  40120. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  40121. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  40122. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  40123. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  40124. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  40125. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  40126. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  40127. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  40128. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  40129. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  40130. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  40131. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  40132. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  40133. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  40134. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  40135. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  40136. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  40137. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  40138. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  40139. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  40140. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  40141. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  40142. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  40143. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  40144. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  40145. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  40146. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  40147. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  40148. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  40149. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  40150. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  40151. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  40152. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  40153. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  40154. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  40155. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  40156. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  40157. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  40158. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  40159. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  40160. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  40161. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  40162. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  40163. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  40164. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  40165. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  40166. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  40167. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  40168. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  40169. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  40170. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  40171. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  40172. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  40173. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  40174. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  40175. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  40176. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  40177. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  40178. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  40179. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  40180. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  40181. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  40182. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  40183. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  40184. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  40185. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  40186. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  40187. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  40188. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  40189. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  40190. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  40191. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  40192. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  40193. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  40194. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  40195. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  40196. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  40197. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  40198. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  40199. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  40200. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  40201. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  40202. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  40203. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  40204. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  40205. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  40206. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  40207. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  40208. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  40209. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  40210. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  40211. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  40212. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  40213. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  40214. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  40215. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  40216. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  40217. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  40218. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  40219. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  40220. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  40221. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  40222. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  40223. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  40224. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  40225. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  40226. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  40227. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  40228. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  40229. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  40230. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  40231. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  40232. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  40233. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  40234. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  40235. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  40236. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  40237. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  40238. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  40239. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  40240. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  40241. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  40242. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  40243. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  40244. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  40245. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  40246. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  40247. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  40248. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  40249. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  40250. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  40251. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  40252. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  40253. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  40254. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  40255. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  40256. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  40257. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  40258. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  40259. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  40260. };
  40261. static const byte msg_65[] = {
  40262. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  40263. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  40264. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  40265. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  40266. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  40267. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  40268. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  40269. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  40270. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  40271. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  40272. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  40273. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  40274. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  40275. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  40276. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  40277. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  40278. };
  40279. static const byte sig_65[] = {
  40280. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  40281. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  40282. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  40283. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  40284. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  40285. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  40286. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  40287. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  40288. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  40289. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  40290. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  40291. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  40292. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  40293. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  40294. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  40295. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  40296. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  40297. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  40298. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  40299. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  40300. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  40301. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  40302. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  40303. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  40304. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  40305. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  40306. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  40307. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  40308. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  40309. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  40310. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  40311. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  40312. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  40313. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  40314. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  40315. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  40316. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  40317. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  40318. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  40319. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  40320. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  40321. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  40322. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  40323. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  40324. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  40325. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  40326. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  40327. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  40328. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  40329. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  40330. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  40331. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  40332. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  40333. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  40334. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  40335. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  40336. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  40337. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  40338. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  40339. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  40340. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  40341. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  40342. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  40343. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  40344. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  40345. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  40346. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  40347. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  40348. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  40349. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  40350. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  40351. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  40352. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  40353. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  40354. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  40355. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  40356. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  40357. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  40358. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  40359. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  40360. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  40361. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  40362. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  40363. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  40364. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  40365. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  40366. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  40367. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  40368. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  40369. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  40370. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  40371. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  40372. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  40373. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  40374. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  40375. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  40376. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  40377. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  40378. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  40379. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  40380. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  40381. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  40382. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  40383. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  40384. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  40385. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  40386. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  40387. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  40388. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  40389. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  40390. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  40391. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  40392. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  40393. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  40394. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  40395. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  40396. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  40397. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  40398. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  40399. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  40400. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  40401. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  40402. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  40403. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  40404. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  40405. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  40406. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  40407. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  40408. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  40409. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  40410. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  40411. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  40412. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  40413. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  40414. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  40415. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  40416. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  40417. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  40418. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  40419. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  40420. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  40421. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  40422. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  40423. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  40424. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  40425. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  40426. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  40427. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  40428. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  40429. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  40430. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  40431. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  40432. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  40433. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  40434. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  40435. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  40436. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  40437. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  40438. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  40439. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  40440. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  40441. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  40442. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  40443. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  40444. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  40445. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  40446. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  40447. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  40448. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  40449. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  40450. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  40451. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  40452. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  40453. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  40454. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  40455. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  40456. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  40457. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  40458. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  40459. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  40460. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  40461. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  40462. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  40463. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  40464. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  40465. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  40466. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  40467. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  40468. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  40469. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  40470. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  40471. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  40472. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  40473. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  40474. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  40475. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  40476. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  40477. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  40478. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  40479. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  40480. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  40481. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  40482. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  40483. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  40484. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  40485. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  40486. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  40487. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  40488. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  40489. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  40490. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  40491. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  40492. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  40493. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  40494. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  40495. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  40496. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  40497. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  40498. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  40499. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  40500. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  40501. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  40502. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  40503. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  40504. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  40505. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  40506. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  40507. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  40508. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  40509. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  40510. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  40511. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  40512. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  40513. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  40514. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  40515. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  40516. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  40517. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  40518. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  40519. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  40520. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  40521. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  40522. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  40523. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  40524. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  40525. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  40526. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  40527. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  40528. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  40529. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  40530. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  40531. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  40532. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  40533. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  40534. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  40535. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  40536. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  40537. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  40538. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  40539. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  40540. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  40541. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  40542. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  40543. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  40544. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  40545. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  40546. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  40547. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  40548. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  40549. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  40550. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  40551. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  40552. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  40553. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  40554. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  40555. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  40556. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  40557. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  40558. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  40559. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  40560. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  40561. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  40562. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  40563. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  40564. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  40565. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  40566. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  40567. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  40568. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  40569. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  40570. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  40571. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  40572. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  40573. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  40574. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  40575. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  40576. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  40577. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  40578. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  40579. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  40580. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  40581. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  40582. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  40583. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  40584. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  40585. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  40586. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  40587. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  40588. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  40589. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  40590. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  40591. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  40592. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  40593. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  40594. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  40595. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  40596. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  40597. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  40598. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  40599. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  40600. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  40601. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  40602. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  40603. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  40604. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  40605. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  40606. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  40607. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  40608. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  40609. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  40610. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  40611. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  40612. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  40613. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  40614. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  40615. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  40616. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  40617. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  40618. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  40619. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  40620. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  40621. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  40622. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  40623. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  40624. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  40625. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  40626. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  40627. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  40628. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  40629. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  40630. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  40631. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  40632. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  40633. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  40634. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  40635. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  40636. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  40637. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  40638. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  40639. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  40640. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  40641. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  40642. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  40643. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  40644. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  40645. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  40646. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  40647. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  40648. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  40649. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  40650. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  40651. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  40652. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  40653. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  40654. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  40655. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  40656. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  40657. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  40658. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  40659. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  40660. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  40661. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  40662. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  40663. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  40664. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  40665. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  40666. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  40667. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  40668. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  40669. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  40670. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  40671. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  40672. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  40673. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  40674. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  40675. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  40676. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  40677. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  40678. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  40679. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  40680. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  40681. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  40682. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  40683. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  40684. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  40685. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  40686. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  40687. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  40688. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  40689. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  40690. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40691. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40692. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40693. 0x0B, 0x10, 0x18, 0x1A, 0x21
  40694. };
  40695. #endif
  40696. #ifndef WOLFSSL_NO_ML_DSA_87
  40697. static const byte pk_87[] = {
  40698. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  40699. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  40700. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  40701. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  40702. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  40703. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  40704. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  40705. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  40706. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  40707. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  40708. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  40709. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  40710. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  40711. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  40712. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  40713. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  40714. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  40715. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  40716. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  40717. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  40718. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  40719. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  40720. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  40721. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  40722. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  40723. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  40724. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  40725. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  40726. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  40727. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  40728. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  40729. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  40730. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  40731. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  40732. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  40733. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  40734. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  40735. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  40736. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  40737. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  40738. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  40739. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  40740. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  40741. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  40742. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  40743. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  40744. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  40745. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  40746. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  40747. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  40748. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  40749. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  40750. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  40751. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  40752. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  40753. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  40754. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  40755. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  40756. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  40757. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  40758. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  40759. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  40760. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  40761. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  40762. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  40763. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  40764. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  40765. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  40766. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  40767. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  40768. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  40769. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  40770. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  40771. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  40772. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  40773. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  40774. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  40775. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  40776. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  40777. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  40778. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  40779. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  40780. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  40781. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  40782. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  40783. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  40784. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  40785. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  40786. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  40787. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  40788. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  40789. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  40790. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  40791. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  40792. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  40793. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  40794. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  40795. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  40796. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  40797. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  40798. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  40799. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  40800. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  40801. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  40802. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  40803. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  40804. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  40805. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  40806. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  40807. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  40808. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  40809. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  40810. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  40811. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  40812. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  40813. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  40814. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  40815. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  40816. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  40817. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  40818. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  40819. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  40820. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  40821. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  40822. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  40823. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  40824. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  40825. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  40826. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  40827. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  40828. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  40829. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  40830. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  40831. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  40832. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  40833. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  40834. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  40835. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  40836. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  40837. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  40838. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  40839. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  40840. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  40841. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  40842. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  40843. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  40844. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  40845. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  40846. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  40847. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  40848. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  40849. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  40850. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  40851. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  40852. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  40853. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  40854. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  40855. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  40856. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  40857. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  40858. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  40859. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  40860. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  40861. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  40862. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  40863. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  40864. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  40865. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  40866. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  40867. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  40868. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  40869. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  40870. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  40871. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  40872. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  40873. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  40874. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  40875. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  40876. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  40877. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  40878. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  40879. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  40880. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  40881. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  40882. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  40883. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  40884. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  40885. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  40886. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  40887. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  40888. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  40889. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  40890. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  40891. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  40892. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  40893. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  40894. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  40895. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  40896. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  40897. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  40898. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  40899. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  40900. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  40901. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  40902. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  40903. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  40904. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  40905. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  40906. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  40907. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  40908. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  40909. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  40910. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  40911. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  40912. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  40913. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  40914. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  40915. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  40916. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  40917. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  40918. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  40919. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  40920. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  40921. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  40922. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  40923. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  40924. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  40925. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  40926. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  40927. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  40928. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  40929. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  40930. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  40931. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  40932. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  40933. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  40934. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  40935. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  40936. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  40937. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  40938. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  40939. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  40940. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  40941. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  40942. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  40943. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  40944. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  40945. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  40946. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  40947. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  40948. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  40949. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  40950. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  40951. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  40952. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  40953. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  40954. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  40955. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  40956. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  40957. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  40958. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  40959. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  40960. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  40961. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  40962. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  40963. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  40964. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  40965. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  40966. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  40967. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  40968. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  40969. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  40970. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  40971. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  40972. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  40973. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  40974. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  40975. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  40976. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  40977. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  40978. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  40979. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  40980. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  40981. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  40982. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  40983. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  40984. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  40985. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  40986. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  40987. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  40988. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  40989. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  40990. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  40991. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  40992. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  40993. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  40994. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  40995. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  40996. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  40997. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  40998. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  40999. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  41000. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  41001. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  41002. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  41003. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  41004. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  41005. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  41006. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  41007. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  41008. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  41009. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  41010. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  41011. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  41012. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  41013. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  41014. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  41015. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  41016. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  41017. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  41018. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  41019. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  41020. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  41021. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  41022. };
  41023. static const byte msg_87[] = {
  41024. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  41025. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  41026. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  41027. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  41028. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  41029. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  41030. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  41031. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  41032. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  41033. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  41034. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  41035. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  41036. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  41037. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  41038. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  41039. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  41040. };
  41041. static const byte sig_87[] = {
  41042. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  41043. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  41044. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  41045. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  41046. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  41047. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  41048. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  41049. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  41050. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  41051. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  41052. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  41053. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  41054. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  41055. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  41056. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  41057. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  41058. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  41059. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  41060. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  41061. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  41062. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  41063. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  41064. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  41065. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  41066. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  41067. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  41068. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  41069. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  41070. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  41071. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  41072. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  41073. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  41074. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  41075. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  41076. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  41077. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  41078. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  41079. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  41080. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  41081. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  41082. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  41083. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  41084. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  41085. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  41086. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  41087. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  41088. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  41089. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  41090. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  41091. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  41092. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  41093. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  41094. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  41095. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  41096. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  41097. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  41098. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  41099. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  41100. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  41101. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  41102. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  41103. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  41104. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  41105. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  41106. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  41107. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  41108. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  41109. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  41110. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  41111. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  41112. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  41113. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  41114. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  41115. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  41116. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  41117. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  41118. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  41119. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  41120. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  41121. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  41122. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  41123. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  41124. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  41125. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  41126. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  41127. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  41128. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  41129. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  41130. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  41131. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  41132. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  41133. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  41134. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  41135. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  41136. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  41137. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  41138. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  41139. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  41140. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  41141. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  41142. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  41143. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  41144. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  41145. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  41146. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  41147. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  41148. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  41149. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  41150. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  41151. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  41152. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  41153. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  41154. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  41155. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  41156. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  41157. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  41158. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  41159. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  41160. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  41161. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  41162. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  41163. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  41164. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  41165. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  41166. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  41167. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  41168. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  41169. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  41170. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  41171. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  41172. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  41173. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  41174. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  41175. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  41176. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  41177. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  41178. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  41179. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  41180. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  41181. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  41182. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  41183. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  41184. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  41185. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  41186. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  41187. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  41188. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  41189. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  41190. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  41191. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  41192. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  41193. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  41194. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  41195. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  41196. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  41197. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  41198. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  41199. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  41200. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  41201. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  41202. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  41203. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  41204. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  41205. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  41206. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  41207. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  41208. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  41209. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  41210. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  41211. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  41212. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  41213. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  41214. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  41215. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  41216. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  41217. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  41218. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  41219. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  41220. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  41221. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  41222. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  41223. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  41224. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  41225. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  41226. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  41227. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  41228. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  41229. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  41230. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  41231. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  41232. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  41233. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  41234. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  41235. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  41236. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  41237. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  41238. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  41239. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  41240. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  41241. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  41242. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  41243. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  41244. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  41245. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  41246. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  41247. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  41248. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  41249. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  41250. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  41251. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  41252. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  41253. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  41254. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  41255. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  41256. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  41257. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  41258. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  41259. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  41260. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  41261. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  41262. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  41263. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  41264. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  41265. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  41266. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  41267. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  41268. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  41269. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  41270. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  41271. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  41272. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  41273. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  41274. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  41275. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  41276. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  41277. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  41278. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  41279. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  41280. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  41281. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  41282. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  41283. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  41284. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  41285. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  41286. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  41287. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  41288. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  41289. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  41290. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  41291. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  41292. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  41293. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  41294. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  41295. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  41296. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  41297. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  41298. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  41299. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  41300. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  41301. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  41302. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  41303. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  41304. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  41305. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  41306. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  41307. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  41308. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  41309. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  41310. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  41311. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  41312. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  41313. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  41314. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  41315. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  41316. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  41317. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  41318. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  41319. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  41320. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  41321. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  41322. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  41323. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  41324. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  41325. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  41326. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  41327. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  41328. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  41329. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  41330. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  41331. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  41332. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  41333. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  41334. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  41335. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  41336. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  41337. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  41338. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  41339. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  41340. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  41341. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  41342. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  41343. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  41344. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  41345. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  41346. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  41347. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  41348. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  41349. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  41350. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  41351. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  41352. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  41353. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  41354. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  41355. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  41356. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  41357. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  41358. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  41359. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  41360. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  41361. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  41362. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  41363. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  41364. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  41365. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  41366. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  41367. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  41368. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  41369. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  41370. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  41371. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  41372. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  41373. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  41374. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  41375. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  41376. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  41377. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  41378. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  41379. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  41380. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  41381. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  41382. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  41383. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  41384. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  41385. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  41386. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  41387. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  41388. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  41389. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  41390. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  41391. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  41392. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  41393. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  41394. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  41395. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  41396. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  41397. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  41398. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  41399. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  41400. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  41401. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  41402. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  41403. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  41404. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  41405. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  41406. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  41407. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  41408. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  41409. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  41410. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  41411. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  41412. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  41413. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  41414. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  41415. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  41416. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  41417. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  41418. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  41419. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  41420. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  41421. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  41422. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  41423. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  41424. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  41425. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  41426. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  41427. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  41428. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  41429. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  41430. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  41431. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  41432. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  41433. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  41434. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  41435. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  41436. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  41437. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  41438. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  41439. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  41440. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  41441. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  41442. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  41443. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  41444. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  41445. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  41446. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  41447. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  41448. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  41449. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  41450. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  41451. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  41452. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  41453. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  41454. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  41455. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  41456. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  41457. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  41458. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  41459. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  41460. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  41461. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  41462. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  41463. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  41464. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  41465. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  41466. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  41467. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  41468. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  41469. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  41470. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  41471. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  41472. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  41473. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  41474. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  41475. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  41476. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  41477. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  41478. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  41479. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  41480. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  41481. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  41482. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  41483. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  41484. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  41485. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  41486. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  41487. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  41488. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  41489. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  41490. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  41491. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  41492. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  41493. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  41494. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  41495. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  41496. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  41497. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  41498. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  41499. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  41500. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  41501. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  41502. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  41503. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  41504. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  41505. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  41506. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  41507. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  41508. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  41509. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  41510. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  41511. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  41512. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  41513. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  41514. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  41515. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  41516. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  41517. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  41518. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  41519. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  41520. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  41521. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  41522. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  41523. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  41524. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  41525. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  41526. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  41527. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  41528. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  41529. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  41530. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  41531. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  41532. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  41533. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  41534. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  41535. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  41536. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  41537. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  41538. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  41539. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  41540. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  41541. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  41542. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  41543. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  41544. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  41545. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  41546. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  41547. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  41548. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  41549. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  41550. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  41551. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  41552. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  41553. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  41554. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  41555. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  41556. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  41557. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  41558. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  41559. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  41560. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  41561. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  41562. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  41563. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  41564. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  41565. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  41566. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  41567. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  41568. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  41569. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  41570. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  41571. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  41572. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  41573. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  41574. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  41575. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  41576. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  41577. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  41578. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  41579. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  41580. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  41581. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  41582. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  41583. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  41584. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  41585. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  41586. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  41587. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  41588. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  41589. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  41590. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  41591. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  41592. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  41593. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  41594. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  41595. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  41596. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  41597. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  41598. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  41599. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  41600. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  41601. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  41602. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  41603. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  41604. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  41605. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  41606. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  41607. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  41608. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  41609. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  41610. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  41611. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  41612. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  41613. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  41614. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  41615. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  41616. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  41617. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41618. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41619. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  41620. 0x29, 0x2E, 0x36
  41621. };
  41622. #endif
  41623. #else
  41624. #ifndef WOLFSSL_NO_ML_DSA_44
  41625. static const byte pk_44[] = {
  41626. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  41627. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  41628. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  41629. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  41630. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  41631. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  41632. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  41633. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  41634. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  41635. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  41636. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  41637. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  41638. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  41639. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  41640. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  41641. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  41642. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  41643. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  41644. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  41645. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  41646. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  41647. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  41648. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  41649. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  41650. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  41651. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  41652. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  41653. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  41654. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  41655. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  41656. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  41657. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  41658. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  41659. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  41660. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  41661. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  41662. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  41663. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  41664. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  41665. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  41666. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  41667. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  41668. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  41669. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  41670. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  41671. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  41672. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  41673. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  41674. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  41675. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  41676. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  41677. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  41678. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  41679. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  41680. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  41681. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  41682. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  41683. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  41684. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  41685. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  41686. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  41687. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  41688. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  41689. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  41690. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  41691. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  41692. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  41693. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  41694. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  41695. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  41696. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  41697. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  41698. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  41699. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  41700. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  41701. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  41702. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  41703. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  41704. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  41705. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  41706. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  41707. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  41708. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  41709. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  41710. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  41711. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  41712. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  41713. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  41714. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  41715. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  41716. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  41717. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  41718. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  41719. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  41720. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  41721. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  41722. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  41723. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  41724. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  41725. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  41726. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  41727. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  41728. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  41729. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  41730. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  41731. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  41732. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  41733. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  41734. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  41735. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  41736. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  41737. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  41738. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  41739. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  41740. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  41741. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  41742. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  41743. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  41744. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  41745. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  41746. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  41747. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  41748. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  41749. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  41750. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  41751. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  41752. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  41753. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  41754. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  41755. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  41756. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  41757. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  41758. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  41759. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  41760. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  41761. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  41762. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  41763. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  41764. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  41765. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  41766. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  41767. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  41768. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  41769. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  41770. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  41771. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  41772. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  41773. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  41774. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  41775. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  41776. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  41777. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  41778. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  41779. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  41780. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  41781. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  41782. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  41783. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  41784. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  41785. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  41786. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  41787. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  41788. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  41789. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  41790. };
  41791. static const byte msg_44[] = {
  41792. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  41793. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  41794. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  41795. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  41796. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  41797. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  41798. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  41799. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  41800. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  41801. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  41802. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  41803. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  41804. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  41805. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  41806. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  41807. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  41808. };
  41809. static const byte sig_44[] = {
  41810. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  41811. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  41812. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  41813. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  41814. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  41815. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  41816. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  41817. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  41818. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  41819. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  41820. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  41821. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  41822. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  41823. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  41824. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  41825. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  41826. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  41827. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  41828. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  41829. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  41830. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  41831. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  41832. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  41833. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  41834. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  41835. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  41836. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  41837. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  41838. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  41839. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  41840. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  41841. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  41842. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  41843. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  41844. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  41845. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  41846. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  41847. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  41848. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  41849. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  41850. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  41851. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  41852. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  41853. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  41854. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  41855. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  41856. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  41857. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  41858. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  41859. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  41860. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  41861. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  41862. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  41863. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  41864. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  41865. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  41866. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  41867. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  41868. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  41869. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  41870. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  41871. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  41872. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  41873. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  41874. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  41875. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  41876. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  41877. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  41878. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  41879. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  41880. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  41881. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  41882. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  41883. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  41884. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  41885. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  41886. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  41887. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  41888. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  41889. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  41890. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  41891. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  41892. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  41893. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  41894. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  41895. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  41896. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  41897. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  41898. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  41899. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  41900. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  41901. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  41902. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  41903. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  41904. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  41905. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  41906. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  41907. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  41908. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  41909. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  41910. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  41911. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  41912. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  41913. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  41914. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  41915. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  41916. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  41917. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  41918. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  41919. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  41920. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  41921. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  41922. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  41923. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  41924. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  41925. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  41926. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  41927. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  41928. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  41929. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  41930. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  41931. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  41932. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  41933. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  41934. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  41935. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  41936. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  41937. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  41938. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  41939. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  41940. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  41941. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  41942. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  41943. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  41944. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  41945. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  41946. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  41947. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  41948. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  41949. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  41950. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  41951. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  41952. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  41953. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  41954. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  41955. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  41956. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  41957. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  41958. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  41959. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  41960. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  41961. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  41962. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  41963. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  41964. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  41965. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  41966. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  41967. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  41968. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  41969. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  41970. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  41971. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  41972. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  41973. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  41974. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  41975. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  41976. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  41977. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  41978. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  41979. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  41980. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  41981. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  41982. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  41983. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  41984. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  41985. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  41986. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  41987. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  41988. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  41989. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  41990. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  41991. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  41992. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  41993. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  41994. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  41995. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  41996. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  41997. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  41998. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  41999. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  42000. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  42001. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  42002. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  42003. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  42004. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  42005. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  42006. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  42007. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  42008. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  42009. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  42010. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  42011. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  42012. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  42013. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  42014. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  42015. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  42016. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  42017. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  42018. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  42019. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  42020. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  42021. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  42022. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  42023. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  42024. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  42025. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  42026. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  42027. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  42028. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  42029. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  42030. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  42031. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  42032. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  42033. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  42034. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  42035. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  42036. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  42037. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  42038. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  42039. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  42040. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  42041. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  42042. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  42043. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  42044. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  42045. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  42046. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  42047. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  42048. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  42049. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  42050. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  42051. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  42052. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  42053. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  42054. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  42055. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  42056. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  42057. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  42058. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  42059. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  42060. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  42061. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  42062. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  42063. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  42064. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  42065. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  42066. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  42067. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  42068. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  42069. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  42070. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  42071. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  42072. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  42073. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  42074. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  42075. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  42076. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  42077. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  42078. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  42079. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  42080. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  42081. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  42082. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  42083. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  42084. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  42085. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  42086. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  42087. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  42088. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  42089. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  42090. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  42091. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  42092. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  42093. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  42094. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  42095. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  42096. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  42097. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  42098. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  42099. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  42100. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  42101. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  42102. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  42103. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  42104. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  42105. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  42106. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  42107. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  42108. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  42109. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  42110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42112. 0x10, 0x18, 0x32, 0x3B
  42113. };
  42114. #endif
  42115. #ifndef WOLFSSL_NO_ML_DSA_65
  42116. static const byte pk_65[] = {
  42117. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  42118. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  42119. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  42120. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  42121. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  42122. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  42123. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  42124. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  42125. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  42126. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  42127. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  42128. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  42129. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  42130. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  42131. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  42132. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  42133. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  42134. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  42135. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  42136. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  42137. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  42138. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  42139. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  42140. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  42141. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  42142. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  42143. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  42144. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  42145. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  42146. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  42147. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  42148. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  42149. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  42150. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  42151. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  42152. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  42153. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  42154. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  42155. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  42156. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  42157. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  42158. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  42159. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  42160. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  42161. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  42162. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  42163. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  42164. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  42165. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  42166. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  42167. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  42168. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  42169. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  42170. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  42171. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  42172. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  42173. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  42174. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  42175. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  42176. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  42177. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  42178. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  42179. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  42180. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  42181. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  42182. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  42183. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  42184. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  42185. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  42186. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  42187. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  42188. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  42189. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  42190. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  42191. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  42192. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  42193. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  42194. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  42195. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  42196. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  42197. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  42198. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  42199. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  42200. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  42201. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  42202. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  42203. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  42204. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  42205. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  42206. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  42207. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  42208. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  42209. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  42210. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  42211. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  42212. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  42213. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  42214. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  42215. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  42216. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  42217. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  42218. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  42219. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  42220. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  42221. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  42222. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  42223. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  42224. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  42225. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  42226. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  42227. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  42228. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  42229. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  42230. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  42231. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  42232. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  42233. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  42234. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  42235. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  42236. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  42237. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  42238. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  42239. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  42240. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  42241. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  42242. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  42243. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  42244. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  42245. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  42246. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  42247. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  42248. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  42249. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  42250. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  42251. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  42252. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  42253. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  42254. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  42255. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  42256. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  42257. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  42258. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  42259. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  42260. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  42261. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  42262. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  42263. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  42264. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  42265. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  42266. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  42267. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  42268. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  42269. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  42270. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  42271. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  42272. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  42273. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  42274. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  42275. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  42276. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  42277. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  42278. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  42279. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  42280. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  42281. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  42282. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  42283. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  42284. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  42285. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  42286. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  42287. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  42288. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  42289. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  42290. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  42291. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  42292. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  42293. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  42294. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  42295. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  42296. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  42297. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  42298. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  42299. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  42300. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  42301. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  42302. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  42303. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  42304. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  42305. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  42306. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  42307. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  42308. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  42309. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  42310. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  42311. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  42312. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  42313. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  42314. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  42315. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  42316. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  42317. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  42318. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  42319. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  42320. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  42321. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  42322. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  42323. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  42324. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  42325. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  42326. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  42327. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  42328. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  42329. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  42330. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  42331. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  42332. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  42333. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  42334. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  42335. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  42336. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  42337. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  42338. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  42339. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  42340. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  42341. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  42342. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  42343. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  42344. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  42345. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  42346. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  42347. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  42348. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  42349. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  42350. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  42351. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  42352. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  42353. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  42354. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  42355. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  42356. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  42357. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  42358. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  42359. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  42360. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  42361. };
  42362. static const byte msg_65[] = {
  42363. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  42364. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  42365. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  42366. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  42367. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  42368. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  42369. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  42370. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  42371. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  42372. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  42373. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  42374. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  42375. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  42376. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  42377. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  42378. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  42379. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  42380. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  42381. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  42382. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  42383. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  42384. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  42385. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  42386. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  42387. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  42388. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  42389. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  42390. 0x8E, 0x99, 0xBB
  42391. };
  42392. static const byte sig_65[] = {
  42393. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  42394. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  42395. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  42396. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  42397. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  42398. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  42399. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  42400. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  42401. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  42402. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  42403. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  42404. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  42405. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  42406. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  42407. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  42408. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  42409. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  42410. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  42411. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  42412. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  42413. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  42414. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  42415. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  42416. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  42417. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  42418. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  42419. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  42420. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  42421. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  42422. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  42423. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  42424. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  42425. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  42426. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  42427. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  42428. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  42429. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  42430. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  42431. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  42432. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  42433. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  42434. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  42435. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  42436. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  42437. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  42438. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  42439. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  42440. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  42441. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  42442. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  42443. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  42444. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  42445. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  42446. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  42447. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  42448. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  42449. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  42450. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  42451. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  42452. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  42453. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  42454. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  42455. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  42456. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  42457. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  42458. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  42459. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  42460. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  42461. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  42462. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  42463. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  42464. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  42465. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  42466. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  42467. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  42468. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  42469. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  42470. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  42471. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  42472. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  42473. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  42474. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  42475. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  42476. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  42477. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  42478. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  42479. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  42480. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  42481. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  42482. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  42483. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  42484. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  42485. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  42486. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  42487. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  42488. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  42489. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  42490. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  42491. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  42492. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  42493. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  42494. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  42495. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  42496. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  42497. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  42498. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  42499. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  42500. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  42501. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  42502. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  42503. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  42504. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  42505. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  42506. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  42507. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  42508. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  42509. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  42510. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  42511. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  42512. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  42513. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  42514. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  42515. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  42516. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  42517. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  42518. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  42519. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  42520. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  42521. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  42522. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  42523. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  42524. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  42525. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  42526. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  42527. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  42528. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  42529. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  42530. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  42531. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  42532. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  42533. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  42534. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  42535. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  42536. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  42537. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  42538. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  42539. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  42540. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  42541. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  42542. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  42543. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  42544. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  42545. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  42546. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  42547. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  42548. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  42549. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  42550. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  42551. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  42552. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  42553. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  42554. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  42555. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  42556. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  42557. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  42558. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  42559. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  42560. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  42561. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  42562. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  42563. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  42564. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  42565. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  42566. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  42567. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  42568. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  42569. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  42570. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  42571. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  42572. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  42573. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  42574. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  42575. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  42576. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  42577. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  42578. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  42579. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  42580. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  42581. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  42582. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  42583. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  42584. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  42585. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  42586. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  42587. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  42588. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  42589. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  42590. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  42591. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  42592. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  42593. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  42594. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  42595. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  42596. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  42597. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  42598. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  42599. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  42600. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  42601. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  42602. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  42603. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  42604. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  42605. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  42606. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  42607. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  42608. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  42609. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  42610. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  42611. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  42612. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  42613. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  42614. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  42615. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  42616. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  42617. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  42618. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  42619. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  42620. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  42621. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  42622. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  42623. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  42624. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  42625. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  42626. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  42627. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  42628. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  42629. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  42630. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  42631. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  42632. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  42633. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  42634. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  42635. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  42636. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  42637. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  42638. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  42639. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  42640. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  42641. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  42642. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  42643. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  42644. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  42645. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  42646. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  42647. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  42648. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  42649. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  42650. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  42651. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  42652. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  42653. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  42654. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  42655. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  42656. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  42657. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  42658. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  42659. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  42660. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  42661. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  42662. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  42663. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  42664. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  42665. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  42666. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  42667. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  42668. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  42669. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  42670. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  42671. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  42672. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  42673. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  42674. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  42675. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  42676. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  42677. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  42678. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  42679. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  42680. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  42681. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  42682. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  42683. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  42684. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  42685. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  42686. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  42687. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  42688. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  42689. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  42690. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  42691. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  42692. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  42693. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  42694. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  42695. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  42696. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  42697. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  42698. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  42699. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  42700. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  42701. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  42702. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  42703. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  42704. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  42705. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  42706. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  42707. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  42708. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  42709. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  42710. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  42711. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  42712. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  42713. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  42714. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  42715. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  42716. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  42717. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  42718. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  42719. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  42720. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  42721. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  42722. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  42723. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  42724. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  42725. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  42726. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  42727. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  42728. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  42729. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  42730. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  42731. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  42732. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  42733. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  42734. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  42735. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  42736. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  42737. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  42738. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  42739. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  42740. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  42741. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  42742. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  42743. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  42744. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  42745. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  42746. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  42747. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  42748. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  42749. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  42750. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  42751. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  42752. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  42753. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  42754. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  42755. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  42756. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  42757. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  42758. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  42759. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  42760. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  42761. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  42762. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  42763. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  42764. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  42765. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  42766. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  42767. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  42768. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  42769. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  42770. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  42771. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  42772. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  42773. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  42774. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  42775. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  42776. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  42777. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  42778. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  42779. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  42780. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  42781. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  42782. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  42783. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  42784. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  42785. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  42786. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  42787. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  42788. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  42789. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  42790. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  42791. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  42792. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  42793. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  42794. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  42795. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  42796. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  42797. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  42798. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  42799. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  42800. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  42801. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  42802. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  42803. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42804. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42805. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  42806. 0x08, 0x0E, 0x12, 0x19, 0x20
  42807. };
  42808. #endif
  42809. #ifndef WOLFSSL_NO_ML_DSA_87
  42810. static const byte pk_87[] = {
  42811. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  42812. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  42813. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  42814. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  42815. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  42816. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  42817. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  42818. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  42819. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  42820. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  42821. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  42822. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  42823. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  42824. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  42825. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  42826. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  42827. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  42828. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  42829. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  42830. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  42831. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  42832. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  42833. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  42834. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  42835. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  42836. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  42837. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  42838. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  42839. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  42840. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  42841. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  42842. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  42843. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  42844. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  42845. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  42846. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  42847. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  42848. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  42849. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  42850. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  42851. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  42852. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  42853. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  42854. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  42855. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  42856. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  42857. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  42858. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  42859. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  42860. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  42861. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  42862. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  42863. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  42864. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  42865. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  42866. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  42867. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  42868. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  42869. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  42870. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  42871. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  42872. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  42873. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  42874. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  42875. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  42876. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  42877. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  42878. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  42879. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  42880. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  42881. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  42882. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  42883. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  42884. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  42885. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  42886. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  42887. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  42888. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  42889. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  42890. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  42891. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  42892. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  42893. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  42894. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  42895. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  42896. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  42897. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  42898. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  42899. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  42900. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  42901. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  42902. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  42903. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  42904. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  42905. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  42906. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  42907. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  42908. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  42909. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  42910. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  42911. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  42912. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  42913. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  42914. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  42915. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  42916. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  42917. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  42918. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  42919. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  42920. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  42921. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  42922. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  42923. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  42924. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  42925. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  42926. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  42927. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  42928. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  42929. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  42930. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  42931. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  42932. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  42933. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  42934. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  42935. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  42936. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  42937. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  42938. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  42939. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  42940. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  42941. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  42942. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  42943. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  42944. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  42945. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  42946. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  42947. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  42948. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  42949. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  42950. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  42951. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  42952. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  42953. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  42954. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  42955. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  42956. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  42957. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  42958. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  42959. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  42960. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  42961. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  42962. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  42963. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  42964. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  42965. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  42966. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  42967. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  42968. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  42969. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  42970. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  42971. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  42972. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  42973. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  42974. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  42975. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  42976. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  42977. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  42978. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  42979. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  42980. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  42981. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  42982. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  42983. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  42984. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  42985. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  42986. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  42987. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  42988. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  42989. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  42990. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  42991. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  42992. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  42993. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  42994. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  42995. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  42996. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  42997. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  42998. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  42999. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  43000. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  43001. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  43002. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  43003. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  43004. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  43005. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  43006. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  43007. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  43008. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  43009. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  43010. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  43011. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  43012. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  43013. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  43014. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  43015. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  43016. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  43017. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  43018. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  43019. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  43020. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  43021. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  43022. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  43023. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  43024. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  43025. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  43026. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  43027. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  43028. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  43029. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  43030. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  43031. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  43032. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  43033. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  43034. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  43035. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  43036. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  43037. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  43038. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  43039. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  43040. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  43041. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  43042. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  43043. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  43044. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  43045. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  43046. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  43047. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  43048. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  43049. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  43050. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  43051. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  43052. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  43053. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  43054. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  43055. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  43056. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  43057. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  43058. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  43059. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  43060. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  43061. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  43062. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  43063. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  43064. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  43065. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  43066. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  43067. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  43068. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  43069. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  43070. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  43071. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  43072. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  43073. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  43074. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  43075. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  43076. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  43077. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  43078. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  43079. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  43080. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  43081. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  43082. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  43083. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  43084. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  43085. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  43086. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  43087. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  43088. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  43089. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  43090. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  43091. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  43092. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  43093. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  43094. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  43095. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  43096. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  43097. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  43098. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  43099. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  43100. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  43101. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  43102. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  43103. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  43104. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  43105. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  43106. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  43107. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  43108. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  43109. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  43110. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  43111. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  43112. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  43113. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  43114. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  43115. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  43116. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  43117. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  43118. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  43119. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  43120. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  43121. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  43122. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  43123. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  43124. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  43125. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  43126. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  43127. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  43128. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  43129. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  43130. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  43131. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  43132. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  43133. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  43134. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  43135. };
  43136. static const byte msg_87[] = {
  43137. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  43138. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  43139. 0xC4, 0xC3, 0xED, 0x36
  43140. };
  43141. static const byte sig_87[] = {
  43142. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  43143. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  43144. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  43145. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  43146. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  43147. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  43148. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  43149. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  43150. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  43151. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  43152. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  43153. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  43154. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  43155. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  43156. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  43157. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  43158. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  43159. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  43160. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  43161. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  43162. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  43163. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  43164. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  43165. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  43166. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  43167. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  43168. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  43169. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  43170. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  43171. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  43172. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  43173. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  43174. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  43175. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  43176. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  43177. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  43178. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  43179. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  43180. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  43181. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  43182. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  43183. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  43184. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  43185. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  43186. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  43187. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  43188. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  43189. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  43190. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  43191. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  43192. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  43193. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  43194. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  43195. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  43196. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  43197. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  43198. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  43199. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  43200. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  43201. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  43202. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  43203. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  43204. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  43205. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  43206. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  43207. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  43208. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  43209. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  43210. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  43211. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  43212. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  43213. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  43214. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  43215. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  43216. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  43217. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  43218. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  43219. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  43220. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  43221. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  43222. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  43223. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  43224. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  43225. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  43226. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  43227. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  43228. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  43229. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  43230. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  43231. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  43232. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  43233. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  43234. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  43235. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  43236. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  43237. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  43238. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  43239. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  43240. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  43241. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  43242. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  43243. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  43244. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  43245. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  43246. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  43247. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  43248. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  43249. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  43250. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  43251. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  43252. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  43253. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  43254. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  43255. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  43256. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  43257. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  43258. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  43259. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  43260. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  43261. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  43262. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  43263. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  43264. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  43265. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  43266. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  43267. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  43268. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  43269. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  43270. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  43271. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  43272. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  43273. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  43274. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  43275. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  43276. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  43277. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  43278. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  43279. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  43280. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  43281. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  43282. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  43283. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  43284. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  43285. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  43286. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  43287. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  43288. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  43289. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  43290. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  43291. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  43292. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  43293. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  43294. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  43295. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  43296. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  43297. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  43298. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  43299. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  43300. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  43301. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  43302. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  43303. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  43304. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  43305. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  43306. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  43307. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  43308. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  43309. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  43310. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  43311. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  43312. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  43313. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  43314. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  43315. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  43316. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  43317. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  43318. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  43319. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  43320. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  43321. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  43322. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  43323. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  43324. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  43325. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  43326. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  43327. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  43328. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  43329. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  43330. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  43331. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  43332. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  43333. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  43334. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  43335. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  43336. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  43337. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  43338. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  43339. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  43340. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  43341. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  43342. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  43343. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  43344. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  43345. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  43346. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  43347. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  43348. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  43349. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  43350. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  43351. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  43352. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  43353. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  43354. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  43355. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  43356. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  43357. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  43358. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  43359. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  43360. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  43361. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  43362. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  43363. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  43364. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  43365. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  43366. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  43367. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  43368. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  43369. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  43370. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  43371. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  43372. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  43373. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  43374. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  43375. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  43376. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  43377. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  43378. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  43379. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  43380. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  43381. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  43382. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  43383. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  43384. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  43385. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  43386. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  43387. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  43388. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  43389. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  43390. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  43391. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  43392. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  43393. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  43394. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  43395. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  43396. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  43397. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  43398. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  43399. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  43400. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  43401. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  43402. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  43403. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  43404. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  43405. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  43406. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  43407. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  43408. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  43409. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  43410. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  43411. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  43412. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  43413. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  43414. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  43415. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  43416. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  43417. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  43418. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  43419. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  43420. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  43421. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  43422. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  43423. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  43424. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  43425. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  43426. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  43427. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  43428. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  43429. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  43430. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  43431. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  43432. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  43433. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  43434. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  43435. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  43436. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  43437. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  43438. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  43439. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  43440. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  43441. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  43442. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  43443. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  43444. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  43445. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  43446. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  43447. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  43448. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  43449. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  43450. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  43451. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  43452. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  43453. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  43454. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  43455. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  43456. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  43457. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  43458. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  43459. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  43460. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  43461. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  43462. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  43463. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  43464. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  43465. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  43466. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  43467. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  43468. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  43469. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  43470. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  43471. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  43472. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  43473. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  43474. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  43475. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  43476. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  43477. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  43478. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  43479. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  43480. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  43481. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  43482. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  43483. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  43484. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  43485. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  43486. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  43487. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  43488. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  43489. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  43490. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  43491. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  43492. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  43493. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  43494. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  43495. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  43496. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  43497. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  43498. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  43499. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  43500. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  43501. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  43502. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  43503. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  43504. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  43505. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  43506. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  43507. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  43508. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  43509. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  43510. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  43511. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  43512. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  43513. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  43514. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  43515. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  43516. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  43517. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  43518. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  43519. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  43520. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  43521. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  43522. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  43523. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  43524. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  43525. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  43526. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  43527. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  43528. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  43529. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  43530. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  43531. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  43532. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  43533. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  43534. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  43535. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  43536. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  43537. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  43538. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  43539. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  43540. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  43541. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  43542. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  43543. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  43544. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  43545. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  43546. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  43547. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  43548. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  43549. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  43550. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  43551. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  43552. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  43553. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  43554. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  43555. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  43556. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  43557. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  43558. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  43559. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  43560. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  43561. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  43562. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  43563. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  43564. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  43565. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  43566. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  43567. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  43568. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  43569. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  43570. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  43571. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  43572. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  43573. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  43574. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  43575. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  43576. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  43577. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  43578. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  43579. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  43580. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  43581. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  43582. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  43583. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  43584. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  43585. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  43586. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  43587. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  43588. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  43589. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  43590. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  43591. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  43592. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  43593. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  43594. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  43595. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  43596. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  43597. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  43598. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  43599. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  43600. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  43601. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  43602. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  43603. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  43604. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  43605. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  43606. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  43607. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  43608. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  43609. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  43610. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  43611. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  43612. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  43613. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  43614. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  43615. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  43616. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  43617. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  43618. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  43619. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  43620. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  43621. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  43622. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  43623. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  43624. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  43625. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  43626. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  43627. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  43628. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  43629. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  43630. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  43631. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  43632. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  43633. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  43634. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  43635. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  43636. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  43637. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  43638. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  43639. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  43640. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  43641. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  43642. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  43643. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  43644. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  43645. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  43646. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  43647. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  43648. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  43649. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  43650. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  43651. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  43652. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  43653. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  43654. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  43655. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  43656. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  43657. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  43658. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  43659. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  43660. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  43661. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  43662. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  43663. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  43664. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  43665. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  43666. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  43667. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  43668. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  43669. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  43670. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  43671. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  43672. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  43673. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  43674. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  43675. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  43676. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  43677. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  43678. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  43679. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  43680. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  43681. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  43682. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  43683. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  43684. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  43685. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  43686. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  43687. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  43688. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  43689. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  43690. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  43691. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  43692. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  43693. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  43694. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  43695. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  43696. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  43697. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  43698. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  43699. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  43700. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  43701. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  43702. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  43703. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  43704. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  43705. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  43706. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  43707. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  43708. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  43709. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  43710. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  43711. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  43712. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  43713. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  43714. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  43715. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  43716. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43717. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43718. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43719. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  43720. 0x1F, 0x27, 0x2E
  43721. };
  43722. #endif
  43723. #endif
  43724. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43725. ExpectNotNull(key);
  43726. if (key != NULL) {
  43727. XMEMSET(key, 0, sizeof(*key));
  43728. }
  43729. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  43730. #ifndef WOLFSSL_NO_ML_DSA_44
  43731. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  43732. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  43733. 0);
  43734. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  43735. (word32)sizeof(msg_44), &res, key), 0);
  43736. ExpectIntEQ(res, 1);
  43737. #endif
  43738. #ifndef WOLFSSL_NO_ML_DSA_65
  43739. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  43740. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  43741. 0);
  43742. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  43743. (word32)sizeof(msg_65), &res, key), 0);
  43744. ExpectIntEQ(res, 1);
  43745. #endif
  43746. #ifndef WOLFSSL_NO_ML_DSA_87
  43747. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  43748. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  43749. 0);
  43750. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  43751. (word32)sizeof(msg_87), &res, key), 0);
  43752. ExpectIntEQ(res, 1);
  43753. #endif
  43754. wc_dilithium_free(key);
  43755. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43756. #endif
  43757. return EXPECT_RESULT();
  43758. }
  43759. /*
  43760. * Testing wc_SetSubjectBuffer
  43761. */
  43762. static int test_wc_SetSubjectBuffer(void)
  43763. {
  43764. EXPECT_DECLS;
  43765. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  43766. Cert cert;
  43767. XFILE file = XBADFILE;
  43768. byte* der = NULL;
  43769. word32 derSz;
  43770. derSz = FOURK_BUF;
  43771. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  43772. DYNAMIC_TYPE_TMP_BUFFER));
  43773. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  43774. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  43775. if (file != XBADFILE)
  43776. XFCLOSE(file);
  43777. ExpectIntEQ(wc_InitCert(&cert), 0);
  43778. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  43779. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43780. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43781. #endif
  43782. return EXPECT_RESULT();
  43783. } /* End test_wc_SetSubjectBuffer*/
  43784. /*
  43785. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  43786. */
  43787. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  43788. {
  43789. EXPECT_DECLS;
  43790. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  43791. WC_RNG rng;
  43792. Cert cert;
  43793. #if !defined(NO_RSA) && defined(HAVE_RSA)
  43794. RsaKey rsaKey;
  43795. int bits = 2048;
  43796. #endif
  43797. #if defined(HAVE_ECC)
  43798. ecc_key eccKey;
  43799. int ret;
  43800. #endif
  43801. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43802. ed25519_key ed25519Key;
  43803. #endif
  43804. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43805. ed448_key ed448Key;
  43806. #endif
  43807. #ifndef HAVE_FIPS
  43808. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  43809. #else
  43810. ExpectIntEQ(wc_InitRng(&rng), 0);
  43811. #endif
  43812. ExpectIntEQ(wc_InitCert(&cert), 0);
  43813. #if !defined(NO_RSA) && defined(HAVE_RSA) && defined(WOLFSSL_KEY_GEN)
  43814. /* RSA */
  43815. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  43816. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  43817. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  43818. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  43819. 0);
  43820. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  43821. #endif
  43822. #if defined(HAVE_ECC)
  43823. /* ECC */
  43824. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  43825. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  43826. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  43827. #if defined(WOLFSSL_ASYNC_CRYPT)
  43828. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  43829. #endif
  43830. ExpectIntEQ(ret, 0);
  43831. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  43832. 0);
  43833. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  43834. #endif
  43835. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43836. /* ED25519 */
  43837. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  43838. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  43839. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  43840. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  43841. &ed25519Key), 0);
  43842. wc_ed25519_free(&ed25519Key);
  43843. #endif
  43844. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43845. /* ED448 */
  43846. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  43847. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  43848. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  43849. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  43850. &ed448Key), 0);
  43851. wc_ed448_free(&ed448Key);
  43852. #endif
  43853. wc_FreeRng(&rng);
  43854. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  43855. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  43856. return EXPECT_RESULT();
  43857. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  43858. /*
  43859. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  43860. */
  43861. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  43862. {
  43863. EXPECT_DECLS;
  43864. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  43865. WC_RNG rng;
  43866. Cert cert;
  43867. #if !defined(NO_RSA) && defined(HAVE_RSA)
  43868. RsaKey rsaKey;
  43869. int bits = 2048;
  43870. #endif
  43871. #if defined(HAVE_ECC)
  43872. ecc_key eccKey;
  43873. int ret;
  43874. #endif
  43875. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43876. ed25519_key ed25519Key;
  43877. #endif
  43878. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43879. ed448_key ed448Key;
  43880. #endif
  43881. #ifndef HAVE_FIPS
  43882. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  43883. #else
  43884. ExpectIntEQ(wc_InitRng(&rng), 0);
  43885. #endif
  43886. ExpectIntEQ(wc_InitCert(&cert), 0);
  43887. #if !defined(NO_RSA) && defined(HAVE_RSA) && defined(WOLFSSL_KEY_GEN)
  43888. /* RSA */
  43889. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  43890. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  43891. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  43892. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  43893. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  43894. #endif
  43895. #if defined(HAVE_ECC)
  43896. /* ECC */
  43897. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  43898. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  43899. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  43900. #if defined(WOLFSSL_ASYNC_CRYPT)
  43901. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  43902. #endif
  43903. ExpectIntEQ(ret, 0);
  43904. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  43905. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  43906. #endif
  43907. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  43908. /* ED25519 */
  43909. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  43910. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  43911. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  43912. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  43913. &ed25519Key), 0);
  43914. wc_ed25519_free(&ed25519Key);
  43915. #endif
  43916. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  43917. /* ED448 */
  43918. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  43919. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  43920. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  43921. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  43922. 0);
  43923. wc_ed448_free(&ed448Key);
  43924. #endif
  43925. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  43926. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  43927. return EXPECT_RESULT();
  43928. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  43929. /*
  43930. * Testing wc_PKCS7_New()
  43931. */
  43932. static int test_wc_PKCS7_New(void)
  43933. {
  43934. EXPECT_DECLS;
  43935. #if defined(HAVE_PKCS7)
  43936. PKCS7* pkcs7 = NULL;
  43937. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  43938. wc_PKCS7_Free(pkcs7);
  43939. #endif
  43940. return EXPECT_RESULT();
  43941. } /* END test-wc_PKCS7_New */
  43942. /*
  43943. * Testing wc_PKCS7_Init()
  43944. */
  43945. static int test_wc_PKCS7_Init(void)
  43946. {
  43947. EXPECT_DECLS;
  43948. #if defined(HAVE_PKCS7)
  43949. PKCS7* pkcs7 = NULL;
  43950. void* heap = NULL;
  43951. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  43952. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  43953. /* Pass in bad args. */
  43954. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  43955. wc_PKCS7_Free(pkcs7);
  43956. #endif
  43957. return EXPECT_RESULT();
  43958. } /* END test-wc_PKCS7_Init */
  43959. /*
  43960. * Testing wc_PKCS7_InitWithCert()
  43961. */
  43962. static int test_wc_PKCS7_InitWithCert(void)
  43963. {
  43964. EXPECT_DECLS;
  43965. #if defined(HAVE_PKCS7)
  43966. PKCS7* pkcs7 = NULL;
  43967. #ifndef NO_RSA
  43968. #if defined(USE_CERT_BUFFERS_2048)
  43969. unsigned char cert[sizeof(client_cert_der_2048)];
  43970. int certSz = (int)sizeof(cert);
  43971. XMEMSET(cert, 0, certSz);
  43972. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  43973. #elif defined(USE_CERT_BUFFERS_1024)
  43974. unsigned char cert[sizeof(client_cert_der_1024)];
  43975. int certSz = (int)sizeof(cert);
  43976. XMEMSET(cert, 0, certSz);
  43977. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  43978. #else
  43979. unsigned char cert[ONEK_BUF];
  43980. XFILE fp = XBADFILE;
  43981. int certSz;
  43982. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  43983. XBADFILE);
  43984. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  43985. fp), 0);
  43986. if (fp != XBADFILE)
  43987. XFCLOSE(fp);
  43988. #endif
  43989. #elif defined(HAVE_ECC)
  43990. #if defined(USE_CERT_BUFFERS_256)
  43991. unsigned char cert[sizeof(cliecc_cert_der_256)];
  43992. int certSz = (int)sizeof(cert);
  43993. XMEMSET(cert, 0, certSz);
  43994. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  43995. #else
  43996. unsigned char cert[ONEK_BUF];
  43997. XFILE fp = XBADFILE;
  43998. int certSz;
  43999. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44000. XBADFILE);
  44001. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  44002. fp), 0);
  44003. if (fp != XBADFILE)
  44004. XFCLOSE(fp);
  44005. #endif
  44006. #else
  44007. #error PKCS7 requires ECC or RSA
  44008. #endif
  44009. #ifdef HAVE_ECC
  44010. {
  44011. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  44012. static unsigned char certWithInvalidEccKey[] = {
  44013. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  44014. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  44015. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  44016. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  44017. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44018. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  44019. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44020. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44021. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44022. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44023. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44024. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44025. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44026. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44027. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44028. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  44029. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  44030. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  44031. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  44032. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  44033. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  44034. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  44035. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  44036. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  44037. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  44038. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  44039. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  44040. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  44041. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  44042. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  44043. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  44044. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  44045. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  44046. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  44047. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  44048. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  44049. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  44050. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  44051. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  44052. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  44053. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44054. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  44055. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  44056. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44057. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  44058. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44059. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  44060. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44061. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44062. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44063. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44064. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44065. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44066. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44067. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44068. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44069. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  44070. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  44071. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  44072. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  44073. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  44074. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  44075. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  44076. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  44077. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  44078. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  44079. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  44080. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  44081. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  44082. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  44083. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  44084. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  44085. 0x08, 0xA8, 0xB4
  44086. };
  44087. #endif
  44088. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44089. /* If initialization is not successful, it's free'd in init func. */
  44090. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  44091. 0);
  44092. wc_PKCS7_Free(pkcs7);
  44093. pkcs7 = NULL;
  44094. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44095. /* Valid initialization usage. */
  44096. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44097. /* Pass in bad args. No need free for null checks, free at end.*/
  44098. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  44099. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44100. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  44101. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44102. #ifdef HAVE_ECC
  44103. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  44104. sizeof(certWithInvalidEccKey)), 0);
  44105. }
  44106. #endif
  44107. wc_PKCS7_Free(pkcs7);
  44108. #endif
  44109. return EXPECT_RESULT();
  44110. } /* END test_wc_PKCS7_InitWithCert */
  44111. /*
  44112. * Testing wc_PKCS7_EncodeData()
  44113. */
  44114. static int test_wc_PKCS7_EncodeData(void)
  44115. {
  44116. EXPECT_DECLS;
  44117. #if defined(HAVE_PKCS7)
  44118. PKCS7* pkcs7 = NULL;
  44119. byte output[FOURK_BUF];
  44120. byte data[] = "My encoded DER cert.";
  44121. #ifndef NO_RSA
  44122. #if defined(USE_CERT_BUFFERS_2048)
  44123. unsigned char cert[sizeof(client_cert_der_2048)];
  44124. unsigned char key[sizeof(client_key_der_2048)];
  44125. int certSz = (int)sizeof(cert);
  44126. int keySz = (int)sizeof(key);
  44127. XMEMSET(cert, 0, certSz);
  44128. XMEMSET(key, 0, keySz);
  44129. XMEMCPY(cert, client_cert_der_2048, certSz);
  44130. XMEMCPY(key, client_key_der_2048, keySz);
  44131. #elif defined(USE_CERT_BUFFERS_1024)
  44132. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  44133. unsigned char key[sizeof_client_key_der_1024];
  44134. int certSz = (int)sizeof(cert);
  44135. int keySz = (int)sizeof(key);
  44136. XMEMSET(cert, 0, certSz);
  44137. XMEMSET(key, 0, keySz);
  44138. XMEMCPY(cert, client_cert_der_1024, certSz);
  44139. XMEMCPY(key, client_key_der_1024, keySz);
  44140. #else
  44141. unsigned char cert[ONEK_BUF];
  44142. unsigned char key[ONEK_BUF];
  44143. XFILE fp = XBADFILE;
  44144. int certSz;
  44145. int keySz;
  44146. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44147. XBADFILE);
  44148. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44149. fp), 0);
  44150. if (fp != XBADFILE) {
  44151. XFCLOSE(fp);
  44152. fp = XBADFILE;
  44153. }
  44154. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44155. XBADFILE);
  44156. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44157. 0);
  44158. if (fp != XBADFILE)
  44159. XFCLOSE(fp);
  44160. #endif
  44161. #elif defined(HAVE_ECC)
  44162. #if defined(USE_CERT_BUFFERS_256)
  44163. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44164. unsigned char key[sizeof(ecc_clikey_der_256)];
  44165. int certSz = (int)sizeof(cert);
  44166. int keySz = (int)sizeof(key);
  44167. XMEMSET(cert, 0, certSz);
  44168. XMEMSET(key, 0, keySz);
  44169. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44170. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44171. #else
  44172. unsigned char cert[ONEK_BUF];
  44173. unsigned char key[ONEK_BUF];
  44174. XFILE fp = XBADFILE;
  44175. int certSz, keySz;
  44176. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44177. XBADFILE);
  44178. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44179. fp), 0);
  44180. if (fp != XBADFILE) {
  44181. XFCLOSE(fp);
  44182. fp = XBADFILE;
  44183. }
  44184. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44185. XBADFILE);
  44186. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44187. 0);
  44188. if (fp != XBADFILE)
  44189. XFCLOSE(fp);
  44190. #endif
  44191. #endif
  44192. XMEMSET(output, 0, sizeof(output));
  44193. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44194. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44195. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  44196. if (pkcs7 != NULL) {
  44197. pkcs7->content = data;
  44198. pkcs7->contentSz = sizeof(data);
  44199. pkcs7->privateKey = key;
  44200. pkcs7->privateKeySz = (word32)keySz;
  44201. }
  44202. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  44203. /* Test bad args. */
  44204. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  44205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44206. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  44207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44208. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  44209. wc_PKCS7_Free(pkcs7);
  44210. #endif
  44211. return EXPECT_RESULT();
  44212. } /* END test_wc_PKCS7_EncodeData */
  44213. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44214. !defined(NO_RSA) && !defined(NO_SHA256)
  44215. /* RSA sign raw digest callback */
  44216. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  44217. byte* out, word32 outSz, byte* privateKey,
  44218. word32 privateKeySz, int devid, int hashOID)
  44219. {
  44220. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  44221. byte digInfoEncoding[] = {
  44222. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  44223. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  44224. 0x00, 0x04, 0x20
  44225. };
  44226. int ret;
  44227. byte digestInfo[ONEK_BUF];
  44228. byte sig[FOURK_BUF];
  44229. word32 digestInfoSz = 0;
  44230. word32 idx = 0;
  44231. RsaKey rsa;
  44232. /* SHA-256 required only for this example callback due to above
  44233. * digInfoEncoding[] */
  44234. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  44235. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  44236. (hashOID != SHA256h)) {
  44237. return -1;
  44238. }
  44239. /* build DigestInfo */
  44240. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  44241. digestInfoSz += sizeof(digInfoEncoding);
  44242. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  44243. digestInfoSz += digestSz;
  44244. /* set up RSA key */
  44245. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  44246. if (ret != 0) {
  44247. return ret;
  44248. }
  44249. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  44250. /* sign DigestInfo */
  44251. if (ret == 0) {
  44252. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  44253. &rsa, pkcs7->rng);
  44254. if (ret > 0) {
  44255. if (ret > (int)outSz) {
  44256. /* output buffer too small */
  44257. ret = -1;
  44258. }
  44259. else {
  44260. /* success, ret holds sig size */
  44261. XMEMCPY(out, sig, ret);
  44262. }
  44263. }
  44264. }
  44265. wc_FreeRsaKey(&rsa);
  44266. return ret;
  44267. }
  44268. #endif
  44269. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  44270. typedef struct encodeSignedDataStream {
  44271. byte out[FOURK_BUF*3];
  44272. int idx;
  44273. word32 outIdx;
  44274. } encodeSignedDataStream;
  44275. /* content is 8k of partially created bundle */
  44276. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  44277. {
  44278. int ret = 0;
  44279. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44280. if (strm->outIdx < pkcs7->contentSz) {
  44281. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  44282. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  44283. *content = strm->out + strm->outIdx;
  44284. strm->outIdx += ret;
  44285. }
  44286. (void)pkcs7;
  44287. return ret;
  44288. }
  44289. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  44290. void* ctx)
  44291. {
  44292. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44293. XMEMCPY(strm->out + strm->idx, output, outputSz);
  44294. strm->idx += outputSz;
  44295. (void)pkcs7;
  44296. return 0;
  44297. }
  44298. #endif
  44299. /*
  44300. * Testing wc_PKCS7_EncodeSignedData()
  44301. */
  44302. static int test_wc_PKCS7_EncodeSignedData(void)
  44303. {
  44304. EXPECT_DECLS;
  44305. #if defined(HAVE_PKCS7)
  44306. PKCS7* pkcs7 = NULL;
  44307. WC_RNG rng;
  44308. byte output[FOURK_BUF];
  44309. byte badOut[1];
  44310. word32 outputSz = (word32)sizeof(output);
  44311. word32 badOutSz = 0;
  44312. byte data[] = "Test data to encode.";
  44313. #ifndef NO_RSA
  44314. #if defined(USE_CERT_BUFFERS_2048)
  44315. byte key[sizeof(client_key_der_2048)];
  44316. byte cert[sizeof(client_cert_der_2048)];
  44317. word32 keySz = (word32)sizeof(key);
  44318. word32 certSz = (word32)sizeof(cert);
  44319. XMEMSET(key, 0, keySz);
  44320. XMEMSET(cert, 0, certSz);
  44321. XMEMCPY(key, client_key_der_2048, keySz);
  44322. XMEMCPY(cert, client_cert_der_2048, certSz);
  44323. #elif defined(USE_CERT_BUFFERS_1024)
  44324. byte key[sizeof_client_key_der_1024];
  44325. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44326. word32 keySz = (word32)sizeof(key);
  44327. word32 certSz = (word32)sizeof(cert);
  44328. XMEMSET(key, 0, keySz);
  44329. XMEMSET(cert, 0, certSz);
  44330. XMEMCPY(key, client_key_der_1024, keySz);
  44331. XMEMCPY(cert, client_cert_der_1024, certSz);
  44332. #else
  44333. unsigned char cert[ONEK_BUF];
  44334. unsigned char key[ONEK_BUF];
  44335. XFILE fp = XBADFILE;
  44336. int certSz;
  44337. int keySz;
  44338. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44339. XBADFILE);
  44340. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44341. fp), 0);
  44342. if (fp != XBADFILE) {
  44343. XFCLOSE(fp);
  44344. fp = XBADFILE;
  44345. }
  44346. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44347. XBADFILE);
  44348. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44349. 0);
  44350. if (fp != XBADFILE)
  44351. XFCLOSE(fp);
  44352. #endif
  44353. #elif defined(HAVE_ECC)
  44354. #if defined(USE_CERT_BUFFERS_256)
  44355. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44356. unsigned char key[sizeof(ecc_clikey_der_256)];
  44357. int certSz = (int)sizeof(cert);
  44358. int keySz = (int)sizeof(key);
  44359. XMEMSET(cert, 0, certSz);
  44360. XMEMSET(key, 0, keySz);
  44361. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  44362. XMEMCPY(key, ecc_clikey_der_256, keySz);
  44363. #else
  44364. unsigned char cert[ONEK_BUF];
  44365. unsigned char key[ONEK_BUF];
  44366. XFILE fp = XBADFILE;
  44367. int certSz;
  44368. int keySz;
  44369. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44370. XBADFILE);
  44371. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  44372. if (fp != XBADFILE) {
  44373. XFCLOSE(fp);
  44374. fp = XBADFILE;
  44375. }
  44376. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44377. XBADFILE);
  44378. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  44379. if (fp != XBADFILE)
  44380. XFCLOSE(fp);
  44381. #endif
  44382. #endif
  44383. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44384. XMEMSET(output, 0, outputSz);
  44385. ExpectIntEQ(wc_InitRng(&rng), 0);
  44386. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44387. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44388. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44389. if (pkcs7 != NULL) {
  44390. pkcs7->content = data;
  44391. pkcs7->contentSz = (word32)sizeof(data);
  44392. pkcs7->privateKey = key;
  44393. pkcs7->privateKeySz = (word32)sizeof(key);
  44394. pkcs7->encryptOID = RSAk;
  44395. #ifdef NO_SHA
  44396. pkcs7->hashOID = SHA256h;
  44397. #else
  44398. pkcs7->hashOID = SHAh;
  44399. #endif
  44400. pkcs7->rng = &rng;
  44401. }
  44402. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44403. wc_PKCS7_Free(pkcs7);
  44404. pkcs7 = NULL;
  44405. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44406. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44407. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44408. #ifdef ASN_BER_TO_DER
  44409. wc_PKCS7_Free(pkcs7);
  44410. /* reinitialize and test setting stream mode */
  44411. {
  44412. int signedSz = 0;
  44413. encodeSignedDataStream strm;
  44414. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44415. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44416. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44417. if (pkcs7 != NULL) {
  44418. pkcs7->content = data;
  44419. pkcs7->contentSz = (word32)sizeof(data);
  44420. pkcs7->privateKey = key;
  44421. pkcs7->privateKeySz = (word32)sizeof(key);
  44422. pkcs7->encryptOID = RSAk;
  44423. #ifdef NO_SHA
  44424. pkcs7->hashOID = SHA256h;
  44425. #else
  44426. pkcs7->hashOID = SHAh;
  44427. #endif
  44428. pkcs7->rng = &rng;
  44429. }
  44430. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  44431. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  44432. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  44433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44434. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  44435. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  44436. outputSz), 0);
  44437. wc_PKCS7_Free(pkcs7);
  44438. pkcs7 = NULL;
  44439. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44440. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44441. /* use exact signed buffer size since BER encoded */
  44442. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  44443. wc_PKCS7_Free(pkcs7);
  44444. /* now try with using callbacks for IO */
  44445. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44446. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44447. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44448. if (pkcs7 != NULL) {
  44449. pkcs7->contentSz = FOURK_BUF*2;
  44450. pkcs7->privateKey = key;
  44451. pkcs7->privateKeySz = (word32)sizeof(key);
  44452. pkcs7->encryptOID = RSAk;
  44453. #ifdef NO_SHA
  44454. pkcs7->hashOID = SHA256h;
  44455. #else
  44456. pkcs7->hashOID = SHAh;
  44457. #endif
  44458. pkcs7->rng = &rng;
  44459. }
  44460. XMEMSET(&strm, 0, sizeof(strm));
  44461. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  44462. StreamOutputCB, (void*)&strm), 0);
  44463. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  44464. wc_PKCS7_Free(pkcs7);
  44465. pkcs7 = NULL;
  44466. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44467. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44468. /* use exact signed buffer size since BER encoded */
  44469. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  44470. }
  44471. #endif
  44472. #ifndef NO_PKCS7_STREAM
  44473. wc_PKCS7_Free(pkcs7);
  44474. pkcs7 = NULL;
  44475. {
  44476. word32 z;
  44477. int ret;
  44478. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44479. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44480. /* test for streaming mode */
  44481. ret = -1;
  44482. for (z = 0; z < outputSz && ret != 0; z++) {
  44483. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44484. if (ret < 0){
  44485. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44486. }
  44487. }
  44488. ExpectIntEQ(ret, 0);
  44489. ExpectIntNE(pkcs7->contentSz, 0);
  44490. ExpectNotNull(pkcs7->contentDynamic);
  44491. }
  44492. #endif /* !NO_PKCS7_STREAM */
  44493. /* Pass in bad args. */
  44494. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  44495. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44496. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44497. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  44498. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44499. if (pkcs7 != NULL) {
  44500. pkcs7->hashOID = 0; /* bad hashOID */
  44501. }
  44502. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  44503. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44504. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44505. !defined(NO_RSA) && !defined(NO_SHA256)
  44506. /* test RSA sign raw digest callback, if using RSA and compiled in.
  44507. * Example callback assumes SHA-256, so only run test if compiled in. */
  44508. wc_PKCS7_Free(pkcs7);
  44509. pkcs7 = NULL;
  44510. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44511. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44512. if (pkcs7 != NULL) {
  44513. pkcs7->content = data;
  44514. pkcs7->contentSz = (word32)sizeof(data);
  44515. pkcs7->privateKey = key;
  44516. pkcs7->privateKeySz = (word32)sizeof(key);
  44517. pkcs7->encryptOID = RSAk;
  44518. pkcs7->hashOID = SHA256h;
  44519. pkcs7->rng = &rng;
  44520. }
  44521. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  44522. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44523. #endif
  44524. wc_PKCS7_Free(pkcs7);
  44525. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44526. #endif
  44527. return EXPECT_RESULT();
  44528. } /* END test_wc_PKCS7_EncodeSignedData */
  44529. /*
  44530. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  44531. */
  44532. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  44533. {
  44534. EXPECT_DECLS;
  44535. #if defined(HAVE_PKCS7)
  44536. int i;
  44537. PKCS7* pkcs7 = NULL;
  44538. WC_RNG rng;
  44539. byte outputHead[FOURK_BUF/2];
  44540. byte outputFoot[FOURK_BUF/2];
  44541. word32 outputHeadSz = (word32)sizeof(outputHead);
  44542. word32 outputFootSz = (word32)sizeof(outputFoot);
  44543. byte data[FOURK_BUF];
  44544. wc_HashAlg hash;
  44545. #ifdef NO_SHA
  44546. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  44547. #else
  44548. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  44549. #endif
  44550. byte hashBuf[WC_MAX_DIGEST_SIZE];
  44551. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  44552. #ifndef NO_RSA
  44553. #if defined(USE_CERT_BUFFERS_2048)
  44554. byte key[sizeof(client_key_der_2048)];
  44555. byte cert[sizeof(client_cert_der_2048)];
  44556. word32 keySz = (word32)sizeof(key);
  44557. word32 certSz = (word32)sizeof(cert);
  44558. XMEMSET(key, 0, keySz);
  44559. XMEMSET(cert, 0, certSz);
  44560. XMEMCPY(key, client_key_der_2048, keySz);
  44561. XMEMCPY(cert, client_cert_der_2048, certSz);
  44562. #elif defined(USE_CERT_BUFFERS_1024)
  44563. byte key[sizeof_client_key_der_1024];
  44564. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44565. word32 keySz = (word32)sizeof(key);
  44566. word32 certSz = (word32)sizeof(cert);
  44567. XMEMSET(key, 0, keySz);
  44568. XMEMSET(cert, 0, certSz);
  44569. XMEMCPY(key, client_key_der_1024, keySz);
  44570. XMEMCPY(cert, client_cert_der_1024, certSz);
  44571. #else
  44572. unsigned char cert[ONEK_BUF];
  44573. unsigned char key[ONEK_BUF];
  44574. XFILE fp = XBADFILE;
  44575. int certSz;
  44576. int keySz;
  44577. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44578. XBADFILE);
  44579. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44580. fp), 0);
  44581. if (fp != XBADFILE) {
  44582. XFCLOSE(fp);
  44583. fp = XBADFILE;
  44584. }
  44585. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44586. XBADFILE);
  44587. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44588. 0);
  44589. if (fp != XBADFILE)
  44590. XFCLOSE(fp);
  44591. #endif
  44592. #elif defined(HAVE_ECC)
  44593. #if defined(USE_CERT_BUFFERS_256)
  44594. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44595. unsigned char key[sizeof(ecc_clikey_der_256)];
  44596. int certSz = (int)sizeof(cert);
  44597. int keySz = (int)sizeof(key);
  44598. XMEMSET(cert, 0, certSz);
  44599. XMEMSET(key, 0, keySz);
  44600. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44601. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44602. #else
  44603. unsigned char cert[ONEK_BUF];
  44604. unsigned char key[ONEK_BUF];
  44605. XFILE fp = XBADFILE;
  44606. int certSz;
  44607. int keySz;
  44608. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44609. XBADFILE);
  44610. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44611. fp), 0);
  44612. if (fp != XBADFILE) {
  44613. XFCLOSE(fp);
  44614. fp = XBADFILE;
  44615. }
  44616. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44617. XBADFILE);
  44618. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44619. 0);
  44620. if (fp != XBADFILE)
  44621. XFCLOSE(fp);
  44622. #endif
  44623. #endif
  44624. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44625. /* initialize large data with sequence */
  44626. for (i=0; i<(int)sizeof(data); i++)
  44627. data[i] = i & 0xff;
  44628. XMEMSET(outputHead, 0, outputHeadSz);
  44629. XMEMSET(outputFoot, 0, outputFootSz);
  44630. ExpectIntEQ(wc_InitRng(&rng), 0);
  44631. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44632. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44633. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44634. if (pkcs7 != NULL) {
  44635. pkcs7->content = NULL; /* not used for ex */
  44636. pkcs7->contentSz = (word32)sizeof(data);
  44637. pkcs7->privateKey = key;
  44638. pkcs7->privateKeySz = (word32)sizeof(key);
  44639. pkcs7->encryptOID = RSAk;
  44640. #ifdef NO_SHA
  44641. pkcs7->hashOID = SHA256h;
  44642. #else
  44643. pkcs7->hashOID = SHAh;
  44644. #endif
  44645. pkcs7->rng = &rng;
  44646. }
  44647. /* calculate hash for content */
  44648. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  44649. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  44650. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  44651. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  44652. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  44653. /* Perform PKCS7 sign using hash directly */
  44654. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44655. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  44656. ExpectIntGT(outputHeadSz, 0);
  44657. ExpectIntGT(outputFootSz, 0);
  44658. wc_PKCS7_Free(pkcs7);
  44659. pkcs7 = NULL;
  44660. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44661. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44662. /* required parameter even on verify when using _ex, if using outputHead
  44663. * and outputFoot */
  44664. if (pkcs7 != NULL) {
  44665. pkcs7->contentSz = (word32)sizeof(data);
  44666. }
  44667. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44668. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  44669. wc_PKCS7_Free(pkcs7);
  44670. pkcs7 = NULL;
  44671. /* assembly complete PKCS7 sign and use normal verify */
  44672. {
  44673. byte* output = NULL;
  44674. word32 outputSz = 0;
  44675. #ifndef NO_PKCS7_STREAM
  44676. word32 z;
  44677. int ret;
  44678. #endif /* !NO_PKCS7_STREAM */
  44679. ExpectNotNull(output = (byte*)XMALLOC(
  44680. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  44681. DYNAMIC_TYPE_TMP_BUFFER));
  44682. if (output != NULL) {
  44683. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  44684. outputSz += outputHeadSz;
  44685. XMEMCPY(&output[outputSz], data, sizeof(data));
  44686. outputSz += sizeof(data);
  44687. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  44688. outputSz += outputFootSz;
  44689. }
  44690. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44691. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44692. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44693. #ifndef NO_PKCS7_STREAM
  44694. wc_PKCS7_Free(pkcs7);
  44695. pkcs7 = NULL;
  44696. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44697. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44698. /* test for streaming mode */
  44699. ret = -1;
  44700. for (z = 0; z < outputSz && ret != 0; z++) {
  44701. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44702. if (ret < 0){
  44703. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44704. }
  44705. }
  44706. ExpectIntEQ(ret, 0);
  44707. ExpectIntNE(pkcs7->contentSz, 0);
  44708. ExpectNotNull(pkcs7->contentDynamic);
  44709. wc_PKCS7_Free(pkcs7);
  44710. pkcs7 = NULL;
  44711. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44712. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44713. #endif /* !NO_PKCS7_STREAM */
  44714. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44715. }
  44716. /* Pass in bad args. */
  44717. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44718. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44719. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44720. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44721. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44722. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44723. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44724. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44725. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44726. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44727. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44728. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44729. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44730. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44731. if (pkcs7 != NULL) {
  44732. pkcs7->hashOID = 0; /* bad hashOID */
  44733. }
  44734. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44735. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44736. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44737. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44738. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44739. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44740. #ifndef NO_PKCS7_STREAM
  44741. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44742. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44743. #else
  44744. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44745. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  44746. #endif
  44747. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44748. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44749. #ifndef NO_PKCS7_STREAM
  44750. /* can pass in 0 buffer length with streaming API */
  44751. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44752. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44753. #else
  44754. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44755. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44756. #endif
  44757. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44758. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44759. #ifndef NO_PKCS7_STREAM
  44760. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44761. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44762. #else
  44763. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44764. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  44765. #endif
  44766. wc_PKCS7_Free(pkcs7);
  44767. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44768. #endif
  44769. return EXPECT_RESULT();
  44770. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  44771. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  44772. /**
  44773. * Loads certs/keys from files or buffers into the argument buffers,
  44774. * helper function called by CreatePKCS7SignedData().
  44775. *
  44776. * Returns 0 on success, negative on error.
  44777. */
  44778. static int LoadPKCS7SignedDataCerts(
  44779. int useIntermediateCertChain, int pkAlgoType,
  44780. byte* intCARoot, word32* intCARootSz,
  44781. byte* intCA1, word32* intCA1Sz,
  44782. byte* intCA2, word32* intCA2Sz,
  44783. byte* cert, word32* certSz,
  44784. byte* key, word32* keySz)
  44785. {
  44786. EXPECT_DECLS;
  44787. int ret = 0;
  44788. XFILE fp = XBADFILE;
  44789. #ifndef NO_RSA
  44790. const char* intCARootRSA = "./certs/ca-cert.der";
  44791. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  44792. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  44793. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  44794. const char* intServKeyRSA = "./certs/server-key.der";
  44795. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  44796. const char* cli1024Cert = "./certs/1024/client-cert.der";
  44797. const char* cli1024Key = "./certs/1024/client-key.der";
  44798. #endif
  44799. #endif
  44800. #ifdef HAVE_ECC
  44801. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  44802. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  44803. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  44804. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  44805. const char* intServKeyECC = "./certs/ecc-key.der";
  44806. #ifndef USE_CERT_BUFFERS_256
  44807. const char* cliEccCert = "./certs/client-ecc-cert.der";
  44808. const char* cliEccKey = "./certs/client-ecc-key.der";
  44809. #endif
  44810. #endif
  44811. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  44812. ((useIntermediateCertChain == 1) &&
  44813. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  44814. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  44815. return BAD_FUNC_ARG;
  44816. }
  44817. /* Read/load certs and keys to use for signing based on PK type and chain */
  44818. switch (pkAlgoType) {
  44819. #ifndef NO_RSA
  44820. case RSA_TYPE:
  44821. if (useIntermediateCertChain == 1) {
  44822. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  44823. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  44824. if (fp != XBADFILE) {
  44825. XFCLOSE(fp);
  44826. fp = XBADFILE;
  44827. }
  44828. ExpectIntGT(*intCARootSz, 0);
  44829. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  44830. if (fp != XBADFILE) {
  44831. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  44832. XFCLOSE(fp);
  44833. fp = XBADFILE;
  44834. }
  44835. ExpectIntGT(*intCA1Sz, 0);
  44836. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  44837. if (fp != XBADFILE) {
  44838. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  44839. XFCLOSE(fp);
  44840. fp = XBADFILE;
  44841. }
  44842. ExpectIntGT(*intCA2Sz, 0);
  44843. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  44844. if (fp != XBADFILE) {
  44845. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44846. XFCLOSE(fp);
  44847. fp = XBADFILE;
  44848. }
  44849. ExpectIntGT(*certSz, 0);
  44850. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  44851. if (fp != XBADFILE) {
  44852. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44853. XFCLOSE(fp);
  44854. fp = XBADFILE;
  44855. }
  44856. ExpectIntGT(*keySz, 0);
  44857. }
  44858. else {
  44859. #if defined(USE_CERT_BUFFERS_2048)
  44860. *keySz = sizeof_client_key_der_2048;
  44861. *certSz = sizeof_client_cert_der_2048;
  44862. XMEMCPY(key, client_key_der_2048, *keySz);
  44863. XMEMCPY(cert, client_cert_der_2048, *certSz);
  44864. #elif defined(USE_CERT_BUFFERS_1024)
  44865. *keySz = sizeof_client_key_der_1024;
  44866. *certSz = sizeof_client_cert_der_1024;
  44867. XMEMCPY(key, client_key_der_1024, *keySz);
  44868. XMEMCPY(cert, client_cert_der_1024, *certSz);
  44869. #else
  44870. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  44871. if (fp != XBADFILE) {
  44872. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44873. XFCLOSE(fp);
  44874. fp = XBADFILE;
  44875. }
  44876. ExpectIntGT(*keySz, 0);
  44877. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  44878. if (fp != XBADFILE) {
  44879. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44880. XFCLOSE(fp);
  44881. fp = XBADFILE;
  44882. }
  44883. ExpectIntGT(*certSz, 0);
  44884. #endif /* USE_CERT_BUFFERS_2048 */
  44885. }
  44886. break;
  44887. #endif /* !NO_RSA */
  44888. #ifdef HAVE_ECC
  44889. case ECC_TYPE:
  44890. if (useIntermediateCertChain == 1) {
  44891. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  44892. if (fp != XBADFILE) {
  44893. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  44894. fp);
  44895. XFCLOSE(fp);
  44896. fp = XBADFILE;
  44897. }
  44898. ExpectIntGT(*intCARootSz, 0);
  44899. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  44900. if (fp != XBADFILE) {
  44901. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  44902. XFCLOSE(fp);
  44903. fp = XBADFILE;
  44904. }
  44905. ExpectIntGT(*intCA1Sz, 0);
  44906. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  44907. if (fp != XBADFILE) {
  44908. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  44909. XFCLOSE(fp);
  44910. fp = XBADFILE;
  44911. }
  44912. ExpectIntGT(*intCA2Sz, 0);
  44913. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  44914. if (fp != XBADFILE) {
  44915. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44916. XFCLOSE(fp);
  44917. fp = XBADFILE;
  44918. }
  44919. ExpectIntGT(*certSz, 0);
  44920. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  44921. if (fp != XBADFILE) {
  44922. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44923. XFCLOSE(fp);
  44924. fp = XBADFILE;
  44925. }
  44926. ExpectIntGT(*keySz, 0);
  44927. }
  44928. else {
  44929. #if defined(USE_CERT_BUFFERS_256)
  44930. *keySz = sizeof_ecc_clikey_der_256;
  44931. *certSz = sizeof_cliecc_cert_der_256;
  44932. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  44933. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  44934. #else
  44935. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  44936. if (fp != XBADFILE) {
  44937. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  44938. XFCLOSE(fp);
  44939. fp = XBADFILE;
  44940. }
  44941. ExpectIntGT(*keySz, 0);
  44942. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  44943. if (fp != XBADFILE) {
  44944. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  44945. XFCLOSE(fp);
  44946. fp = XBADFILE;
  44947. }
  44948. ExpectIntGT(*certSz, 0);
  44949. #endif /* USE_CERT_BUFFERS_256 */
  44950. }
  44951. break;
  44952. #endif /* HAVE_ECC */
  44953. default:
  44954. WOLFSSL_MSG("Unsupported SignedData PK type");
  44955. ret = BAD_FUNC_ARG;
  44956. break;
  44957. }
  44958. if (EXPECT_FAIL() && (ret == 0)) {
  44959. ret = BAD_FUNC_ARG;
  44960. }
  44961. return ret;
  44962. }
  44963. /**
  44964. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  44965. *
  44966. * output output buffer to place SignedData
  44967. * outputSz size of output buffer
  44968. * data data buffer to be signed
  44969. * dataSz size of data buffer
  44970. * withAttribs [1/0] include attributes in SignedData message
  44971. * detachedSig [1/0] create detached signature, no content
  44972. * useIntCertChain [1/0] use certificate chain and include intermediate and
  44973. * root CAs in bundle
  44974. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  44975. *
  44976. * Return size of bundle created on success, negative on error */
  44977. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  44978. byte* data, word32 dataSz,
  44979. int withAttribs, int detachedSig,
  44980. int useIntermediateCertChain,
  44981. int pkAlgoType)
  44982. {
  44983. EXPECT_DECLS;
  44984. int ret = 0;
  44985. WC_RNG rng;
  44986. PKCS7* pkcs7 = NULL;
  44987. static byte messageTypeOid[] =
  44988. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  44989. 0x09, 0x02 };
  44990. static byte messageType[] = { 0x13, 2, '1', '9' };
  44991. PKCS7Attrib attribs[] =
  44992. {
  44993. { messageTypeOid, sizeof(messageTypeOid), messageType,
  44994. sizeof(messageType) }
  44995. };
  44996. byte intCARoot[TWOK_BUF];
  44997. byte intCA1[TWOK_BUF];
  44998. byte intCA2[TWOK_BUF];
  44999. byte cert[TWOK_BUF];
  45000. byte key[TWOK_BUF];
  45001. word32 intCARootSz = sizeof(intCARoot);
  45002. word32 intCA1Sz = sizeof(intCA1);
  45003. word32 intCA2Sz = sizeof(intCA2);
  45004. word32 certSz = sizeof(cert);
  45005. word32 keySz = sizeof(key);
  45006. XMEMSET(intCARoot, 0, intCARootSz);
  45007. XMEMSET(intCA1, 0, intCA1Sz);
  45008. XMEMSET(intCA2, 0, intCA2Sz);
  45009. XMEMSET(cert, 0, certSz);
  45010. XMEMSET(key, 0, keySz);
  45011. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  45012. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  45013. cert, &certSz, key, &keySz);
  45014. ExpectIntEQ(ret, 0);
  45015. XMEMSET(output, 0, outputSz);
  45016. ExpectIntEQ(wc_InitRng(&rng), 0);
  45017. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45018. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45019. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45020. if (useIntermediateCertChain == 1) {
  45021. /* Add intermediate and root CA certs into SignedData Certs SET */
  45022. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  45023. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  45024. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  45025. }
  45026. if (pkcs7 != NULL) {
  45027. pkcs7->content = data;
  45028. pkcs7->contentSz = dataSz;
  45029. pkcs7->privateKey = key;
  45030. pkcs7->privateKeySz = (word32)sizeof(key);
  45031. if (pkAlgoType == RSA_TYPE) {
  45032. pkcs7->encryptOID = RSAk;
  45033. }
  45034. else {
  45035. pkcs7->encryptOID = ECDSAk;
  45036. }
  45037. #ifdef NO_SHA
  45038. pkcs7->hashOID = SHA256h;
  45039. #else
  45040. pkcs7->hashOID = SHAh;
  45041. #endif
  45042. pkcs7->rng = &rng;
  45043. if (withAttribs) {
  45044. /* include a signed attribute */
  45045. pkcs7->signedAttribs = attribs;
  45046. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  45047. }
  45048. }
  45049. if (detachedSig) {
  45050. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  45051. }
  45052. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  45053. ExpectIntGT(outputSz, 0);
  45054. wc_PKCS7_Free(pkcs7);
  45055. pkcs7 = NULL;
  45056. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45057. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45058. if (detachedSig && (pkcs7 != NULL)) {
  45059. pkcs7->content = data;
  45060. pkcs7->contentSz = dataSz;
  45061. }
  45062. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  45063. wc_PKCS7_Free(pkcs7);
  45064. wc_FreeRng(&rng);
  45065. if (EXPECT_FAIL()) {
  45066. outputSz = 0;
  45067. }
  45068. return outputSz;
  45069. }
  45070. #endif
  45071. /*
  45072. * Testing wc_PKCS_VerifySignedData()
  45073. */
  45074. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  45075. {
  45076. EXPECT_DECLS;
  45077. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  45078. PKCS7* pkcs7 = NULL;
  45079. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45080. word32 outputSz = sizeof(output);
  45081. byte data[] = "Test data to encode.";
  45082. byte badOut[1];
  45083. word32 badOutSz = 0;
  45084. byte badContent[] = "This is different content than was signed";
  45085. wc_HashAlg hash;
  45086. #ifdef NO_SHA
  45087. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45088. #else
  45089. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45090. #endif
  45091. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45092. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45093. #ifndef NO_RSA
  45094. PKCS7DecodedAttrib* decodedAttrib = NULL;
  45095. /* contentType OID (1.2.840.113549.1.9.3) */
  45096. static const byte contentTypeOid[] =
  45097. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  45098. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  45099. static const byte dataType[] =
  45100. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  45101. /* messageDigest OID (1.2.840.113549.1.9.4) */
  45102. static const byte messageDigestOid[] =
  45103. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  45104. #ifndef NO_ASN_TIME
  45105. /* signingTime OID () */
  45106. static const byte signingTimeOid[] =
  45107. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  45108. #endif
  45109. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45110. int dateLength = 0;
  45111. byte dateFormat;
  45112. const byte* datePart = NULL;
  45113. struct tm timearg;
  45114. time_t now;
  45115. struct tm* nowTm = NULL;
  45116. #ifdef NEED_TMP_TIME
  45117. struct tm tmpTimeStorage;
  45118. struct tm* tmpTime = &tmpTimeStorage;
  45119. #endif
  45120. #endif /* !NO_ASN && !NO_ASN_TIME */
  45121. #ifndef NO_PKCS7_STREAM
  45122. word32 z;
  45123. int ret;
  45124. #endif /* !NO_PKCS7_STREAM */
  45125. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45126. /* Success test with RSA certs/key */
  45127. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45128. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  45129. /* calculate hash for content, used later */
  45130. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45131. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45132. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45133. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45134. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45135. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45136. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45137. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45138. #ifndef NO_PKCS7_STREAM
  45139. wc_PKCS7_Free(pkcs7);
  45140. pkcs7 = NULL;
  45141. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45142. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45143. /* test for streaming */
  45144. ret = -1;
  45145. for (z = 0; z < outputSz && ret != 0; z++) {
  45146. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45147. if (ret < 0){
  45148. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45149. }
  45150. }
  45151. ExpectIntEQ(ret, 0);
  45152. ExpectIntNE(pkcs7->contentSz, 0);
  45153. ExpectNotNull(pkcs7->contentDynamic);
  45154. #endif /* !NO_PKCS7_STREAM */
  45155. /* Check that decoded signed attributes are correct */
  45156. /* messageDigest should be first */
  45157. if (pkcs7 != NULL) {
  45158. decodedAttrib = pkcs7->decodedAttrib;
  45159. }
  45160. ExpectNotNull(decodedAttrib);
  45161. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  45162. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  45163. decodedAttrib->oidSz), 0);
  45164. /* + 2 for OCTET STRING and length bytes */
  45165. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  45166. ExpectNotNull(decodedAttrib->value);
  45167. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  45168. #ifndef NO_ASN_TIME
  45169. /* signingTime should be second */
  45170. if (decodedAttrib != NULL) {
  45171. decodedAttrib = decodedAttrib->next;
  45172. }
  45173. ExpectNotNull(decodedAttrib);
  45174. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  45175. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  45176. decodedAttrib->oidSz), 0);
  45177. ExpectIntGT(decodedAttrib->valueSz, 0);
  45178. ExpectNotNull(decodedAttrib->value);
  45179. #endif
  45180. /* Verify signingTime if ASN and time are available */
  45181. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45182. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  45183. &datePart, &dateFormat, &dateLength), 0);
  45184. ExpectNotNull(datePart);
  45185. ExpectIntGT(dateLength, 0);
  45186. XMEMSET(&timearg, 0, sizeof(timearg));
  45187. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  45188. &timearg), 0);
  45189. /* Get current time and compare year/month/day against attribute value */
  45190. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  45191. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  45192. ExpectNotNull(nowTm);
  45193. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  45194. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  45195. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  45196. #endif /* !NO_ASN && !NO_ASN_TIME */
  45197. /* contentType should be third */
  45198. if (decodedAttrib != NULL) {
  45199. decodedAttrib = decodedAttrib->next;
  45200. }
  45201. ExpectNotNull(decodedAttrib);
  45202. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  45203. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  45204. decodedAttrib->oidSz), 0);
  45205. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  45206. ExpectNotNull(decodedAttrib->value);
  45207. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  45208. 0);
  45209. #endif /* !NO_RSA */
  45210. /* Test bad args. */
  45211. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  45212. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45213. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  45214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45215. #ifndef NO_PKCS7_STREAM
  45216. /* can pass in 0 buffer length with streaming API */
  45217. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45218. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45219. #else
  45220. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45221. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45222. #endif
  45223. wc_PKCS7_Free(pkcs7);
  45224. pkcs7 = NULL;
  45225. #ifndef NO_RSA
  45226. /* Try RSA certs/key/sig first */
  45227. outputSz = sizeof(output);
  45228. XMEMSET(output, 0, outputSz);
  45229. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45230. (word32)sizeof(data),
  45231. 1, 1, 0, RSA_TYPE)), 0);
  45232. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45233. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45234. if (pkcs7 != NULL) {
  45235. pkcs7->content = badContent;
  45236. pkcs7->contentSz = sizeof(badContent);
  45237. }
  45238. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45239. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45240. wc_PKCS7_Free(pkcs7);
  45241. pkcs7 = NULL;
  45242. #ifndef NO_PKCS7_STREAM
  45243. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45244. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45245. if (pkcs7 != NULL) {
  45246. pkcs7->content = badContent;
  45247. pkcs7->contentSz = sizeof(badContent);
  45248. }
  45249. /* test for streaming */
  45250. ret = -1;
  45251. for (z = 0; z < outputSz && ret != 0; z++) {
  45252. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45253. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45254. continue;
  45255. }
  45256. else if (ret < 0) {
  45257. break;
  45258. }
  45259. }
  45260. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45261. ExpectIntNE(pkcs7->contentSz, 0);
  45262. ExpectNotNull(pkcs7->contentDynamic);
  45263. wc_PKCS7_Free(pkcs7);
  45264. pkcs7 = NULL;
  45265. #endif /* !NO_PKCS7_STREAM */
  45266. /* Test success case with detached signature and valid content */
  45267. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45268. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45269. if (pkcs7 != NULL) {
  45270. pkcs7->content = data;
  45271. pkcs7->contentSz = sizeof(data);
  45272. }
  45273. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45274. wc_PKCS7_Free(pkcs7);
  45275. pkcs7 = NULL;
  45276. #ifndef NO_PKCS7_STREAM
  45277. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45278. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45279. if (pkcs7 != NULL) {
  45280. pkcs7->content = data;
  45281. pkcs7->contentSz = sizeof(data);
  45282. }
  45283. /* test for streaming */
  45284. ret = -1;
  45285. for (z = 0; z < outputSz && ret != 0; z++) {
  45286. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45287. if (ret < 0){
  45288. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45289. }
  45290. }
  45291. ExpectIntEQ(ret, 0);
  45292. ExpectIntNE(pkcs7->contentSz, 0);
  45293. ExpectNotNull(pkcs7->contentDynamic);
  45294. wc_PKCS7_Free(pkcs7);
  45295. pkcs7 = NULL;
  45296. #endif /* !NO_PKCS7_STREAM */
  45297. /* verify using pre-computed content digest only (no content) */
  45298. {
  45299. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45300. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45301. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45302. output, outputSz, NULL, 0), 0);
  45303. wc_PKCS7_Free(pkcs7);
  45304. pkcs7 = NULL;
  45305. }
  45306. #endif /* !NO_RSA */
  45307. /* Test verify on signedData containing intermediate/root CA certs */
  45308. #ifndef NO_RSA
  45309. outputSz = sizeof(output);
  45310. XMEMSET(output, 0, outputSz);
  45311. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45312. (word32)sizeof(data),
  45313. 0, 0, 1, RSA_TYPE)), 0);
  45314. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45315. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45316. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45317. wc_PKCS7_Free(pkcs7);
  45318. pkcs7 = NULL;
  45319. #ifndef NO_PKCS7_STREAM
  45320. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45321. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45322. /* test for streaming */
  45323. ret = -1;
  45324. for (z = 0; z < outputSz && ret != 0; z++) {
  45325. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45326. if (ret < 0){
  45327. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45328. }
  45329. }
  45330. ExpectIntEQ(ret, 0);
  45331. ExpectIntNE(pkcs7->contentSz, 0);
  45332. ExpectNotNull(pkcs7->contentDynamic);
  45333. wc_PKCS7_Free(pkcs7);
  45334. pkcs7 = NULL;
  45335. #endif /* !NO_PKCS7_STREAM */
  45336. #endif /* !NO_RSA */
  45337. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  45338. !defined(NO_FILESYSTEM)
  45339. {
  45340. XFILE signedBundle = XBADFILE;
  45341. int signedBundleSz = 0;
  45342. int chunkSz = 1;
  45343. int i, rc = 0;
  45344. byte* buf = NULL;
  45345. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  45346. "rb")) != XBADFILE);
  45347. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  45348. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  45349. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  45350. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  45351. DYNAMIC_TYPE_FILE));
  45352. if (buf != NULL) {
  45353. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  45354. signedBundleSz);
  45355. }
  45356. if (signedBundle != XBADFILE) {
  45357. XFCLOSE(signedBundle);
  45358. signedBundle = XBADFILE;
  45359. }
  45360. if (buf != NULL) {
  45361. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45362. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45363. for (i = 0; i < signedBundleSz;) {
  45364. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45365. chunkSz;
  45366. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45367. if (rc < 0 ) {
  45368. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45369. i += sz;
  45370. continue;
  45371. }
  45372. break;
  45373. }
  45374. else {
  45375. break;
  45376. }
  45377. }
  45378. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  45379. wc_PKCS7_Free(pkcs7);
  45380. pkcs7 = NULL;
  45381. }
  45382. /* now try with malformed bundle */
  45383. if (buf != NULL) {
  45384. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45385. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45386. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  45387. for (i = 0; i < signedBundleSz;) {
  45388. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45389. chunkSz;
  45390. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45391. if (rc < 0 ) {
  45392. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45393. i += sz;
  45394. continue;
  45395. }
  45396. break;
  45397. }
  45398. else {
  45399. break;
  45400. }
  45401. }
  45402. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  45403. wc_PKCS7_Free(pkcs7);
  45404. pkcs7 = NULL;
  45405. }
  45406. if (buf != NULL)
  45407. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  45408. }
  45409. #endif /* BER and stream */
  45410. #endif
  45411. return EXPECT_RESULT();
  45412. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  45413. /*
  45414. * Testing wc_PKCS_VerifySignedData()
  45415. */
  45416. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  45417. {
  45418. EXPECT_DECLS;
  45419. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  45420. PKCS7* pkcs7 = NULL;
  45421. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45422. word32 outputSz = sizeof(output);
  45423. byte data[] = "Test data to encode.";
  45424. byte badContent[] = "This is different content than was signed";
  45425. wc_HashAlg hash;
  45426. #ifndef NO_PKCS7_STREAM
  45427. word32 z;
  45428. int ret;
  45429. #endif /* !NO_PKCS7_STREAM */
  45430. #ifdef NO_SHA
  45431. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45432. #else
  45433. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45434. #endif
  45435. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45436. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45437. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45438. /* Success test with ECC certs/key */
  45439. outputSz = sizeof(output);
  45440. XMEMSET(output, 0, outputSz);
  45441. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45442. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  45443. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45444. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45445. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45446. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45447. wc_PKCS7_Free(pkcs7);
  45448. pkcs7 = NULL;
  45449. #ifndef NO_PKCS7_STREAM
  45450. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45451. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45452. /* test for streaming */
  45453. ret = -1;
  45454. for (z = 0; z < outputSz && ret != 0; z++) {
  45455. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45456. if (ret < 0){
  45457. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45458. }
  45459. }
  45460. ExpectIntEQ(ret, 0);
  45461. ExpectIntNE(pkcs7->contentSz, 0);
  45462. ExpectNotNull(pkcs7->contentDynamic);
  45463. wc_PKCS7_Free(pkcs7);
  45464. pkcs7 = NULL;
  45465. #endif /* !NO_PKCS7_STREAM */
  45466. /* Invalid content should error, use detached signature so we can
  45467. * easily change content */
  45468. outputSz = sizeof(output);
  45469. XMEMSET(output, 0, outputSz);
  45470. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45471. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  45472. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45473. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45474. if (pkcs7 != NULL) {
  45475. pkcs7->content = badContent;
  45476. pkcs7->contentSz = sizeof(badContent);
  45477. }
  45478. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45479. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45480. wc_PKCS7_Free(pkcs7);
  45481. pkcs7 = NULL;
  45482. #ifndef NO_PKCS7_STREAM
  45483. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45484. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45485. if (pkcs7 != NULL) {
  45486. pkcs7->content = badContent;
  45487. pkcs7->contentSz = sizeof(badContent);
  45488. }
  45489. /* test for streaming */
  45490. ret = -1;
  45491. for (z = 0; z < outputSz && ret != 0; z++) {
  45492. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45493. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45494. continue;
  45495. }
  45496. else if (ret < 0) {
  45497. break;
  45498. }
  45499. }
  45500. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45501. ExpectIntNE(pkcs7->contentSz, 0);
  45502. ExpectNotNull(pkcs7->contentDynamic);
  45503. wc_PKCS7_Free(pkcs7);
  45504. pkcs7 = NULL;
  45505. #endif /* !NO_PKCS7_STREAM */
  45506. /* Test success case with detached signature and valid content */
  45507. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45508. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45509. if (pkcs7 != NULL) {
  45510. pkcs7->content = data;
  45511. pkcs7->contentSz = sizeof(data);
  45512. }
  45513. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45514. wc_PKCS7_Free(pkcs7);
  45515. pkcs7 = NULL;
  45516. #ifndef NO_PKCS7_STREAM
  45517. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45518. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45519. if (pkcs7 != NULL) {
  45520. pkcs7->content = data;
  45521. pkcs7->contentSz = sizeof(data);
  45522. }
  45523. /* test for streaming */
  45524. ret = -1;
  45525. for (z = 0; z < outputSz && ret != 0; z++) {
  45526. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45527. if (ret < 0){
  45528. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45529. }
  45530. }
  45531. ExpectIntEQ(ret, 0);
  45532. ExpectIntNE(pkcs7->contentSz, 0);
  45533. ExpectNotNull(pkcs7->contentDynamic);
  45534. wc_PKCS7_Free(pkcs7);
  45535. pkcs7 = NULL;
  45536. #endif /* !NO_PKCS7_STREAM */
  45537. /* verify using pre-computed content digest only (no content) */
  45538. {
  45539. /* calculate hash for content */
  45540. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45541. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45542. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45543. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45544. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45545. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45546. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45547. output, outputSz, NULL, 0), 0);
  45548. wc_PKCS7_Free(pkcs7);
  45549. pkcs7 = NULL;
  45550. }
  45551. /* Test verify on signedData containing intermediate/root CA certs */
  45552. outputSz = sizeof(output);
  45553. XMEMSET(output, 0, outputSz);
  45554. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45555. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  45556. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45557. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45558. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45559. wc_PKCS7_Free(pkcs7);
  45560. pkcs7 = NULL;
  45561. #ifndef NO_PKCS7_STREAM
  45562. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45563. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45564. /* test for streaming */
  45565. ret = -1;
  45566. for (z = 0; z < outputSz && ret != 0; z++) {
  45567. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45568. if (ret < 0){
  45569. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45570. }
  45571. }
  45572. ExpectIntEQ(ret, 0);
  45573. ExpectIntNE(pkcs7->contentSz, 0);
  45574. ExpectNotNull(pkcs7->contentDynamic);
  45575. wc_PKCS7_Free(pkcs7);
  45576. pkcs7 = NULL;
  45577. #endif /* !NO_PKCS7_STREAM */
  45578. #endif
  45579. return EXPECT_RESULT();
  45580. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  45581. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  45582. !defined(NO_AES_256)
  45583. static const byte defKey[] = {
  45584. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45585. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45586. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45587. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45588. };
  45589. static byte aesHandle[32]; /* simulated hardware key handle */
  45590. /* return 0 on success */
  45591. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45592. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45593. byte* in, int inSz, byte* out, void* usrCtx)
  45594. {
  45595. int ret;
  45596. Aes aes;
  45597. if (usrCtx == NULL) {
  45598. /* no simulated handle passed in */
  45599. return -1;
  45600. }
  45601. switch (encryptOID) {
  45602. case AES256CBCb:
  45603. if (ivSz != AES_BLOCK_SIZE)
  45604. return BAD_FUNC_ARG;
  45605. break;
  45606. default:
  45607. WOLFSSL_MSG("Unsupported content cipher type for test");
  45608. return ALGO_ID_E;
  45609. };
  45610. /* simulate using handle to get key */
  45611. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  45612. if (ret == 0) {
  45613. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  45614. if (ret == 0)
  45615. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  45616. wc_AesFree(&aes);
  45617. }
  45618. (void)aad;
  45619. (void)aadSz;
  45620. (void)authTag;
  45621. (void)authTagSz;
  45622. (void)pkcs7;
  45623. return ret;
  45624. }
  45625. /* returns key size on success */
  45626. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  45627. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  45628. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  45629. {
  45630. int ret = -1;
  45631. (void)cekSz;
  45632. (void)cek;
  45633. (void)outSz;
  45634. (void)keyIdSz;
  45635. (void)direction;
  45636. (void)orginKey; /* used with KAKRI */
  45637. (void)orginKeySz;
  45638. if (out == NULL)
  45639. return BAD_FUNC_ARG;
  45640. if (keyId[0] != 0x00) {
  45641. return -1;
  45642. }
  45643. if (type != (int)PKCS7_KEKRI) {
  45644. return -1;
  45645. }
  45646. switch (keyWrapAlgo) {
  45647. case AES256_WRAP:
  45648. /* simulate setting a handle for later decryption but use key
  45649. * as handle in the test case here */
  45650. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  45651. aesHandle, sizeof(aesHandle), NULL);
  45652. if (ret < 0)
  45653. return ret;
  45654. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  45655. if (ret < 0)
  45656. return ret;
  45657. /* return key size on success */
  45658. return sizeof(defKey);
  45659. default:
  45660. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  45661. return BAD_KEYWRAP_ALG_E;
  45662. };
  45663. }
  45664. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  45665. /*
  45666. * Testing wc_PKCS7_EncodeEnvelopedData()
  45667. */
  45668. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  45669. {
  45670. EXPECT_DECLS;
  45671. #if defined(HAVE_PKCS7)
  45672. PKCS7* pkcs7 = NULL;
  45673. #ifdef ASN_BER_TO_DER
  45674. int encodedSz = 0;
  45675. #endif
  45676. #ifdef ECC_TIMING_RESISTANT
  45677. WC_RNG rng;
  45678. #endif
  45679. word32 tempWrd32 = 0;
  45680. byte* tmpBytePtr = NULL;
  45681. const char input[] = "Test data to encode.";
  45682. int i;
  45683. int testSz = 0;
  45684. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  45685. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45686. byte* rsaCert = NULL;
  45687. byte* rsaPrivKey = NULL;
  45688. word32 rsaCertSz;
  45689. word32 rsaPrivKeySz;
  45690. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  45691. !defined(USE_CERT_BUFFERS_2048) )
  45692. static const char* rsaClientCert = "./certs/client-cert.der";
  45693. static const char* rsaClientKey = "./certs/client-key.der";
  45694. rsaCertSz = (word32)sizeof(rsaClientCert);
  45695. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  45696. #endif
  45697. #endif
  45698. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45699. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45700. byte* eccCert = NULL;
  45701. byte* eccPrivKey = NULL;
  45702. word32 eccCertSz;
  45703. word32 eccPrivKeySz;
  45704. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  45705. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  45706. static const char* eccClientKey = "./certs/ecc-client-key.der";
  45707. #endif
  45708. #endif
  45709. /* Generic buffer size. */
  45710. byte output[ONEK_BUF];
  45711. byte decoded[sizeof(input)/sizeof(char)];
  45712. int decodedSz = 0;
  45713. #ifndef NO_FILESYSTEM
  45714. XFILE certFile = XBADFILE;
  45715. XFILE keyFile = XBADFILE;
  45716. #endif
  45717. #ifdef ECC_TIMING_RESISTANT
  45718. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45719. #endif
  45720. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45721. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45722. /* RSA certs and keys. */
  45723. #if defined(USE_CERT_BUFFERS_1024)
  45724. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  45725. /* Allocate buffer space. */
  45726. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45727. DYNAMIC_TYPE_TMP_BUFFER));
  45728. /* Init buffer. */
  45729. if (rsaCert != NULL) {
  45730. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  45731. }
  45732. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  45733. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45734. DYNAMIC_TYPE_TMP_BUFFER));
  45735. if (rsaPrivKey != NULL) {
  45736. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  45737. }
  45738. #elif defined(USE_CERT_BUFFERS_2048)
  45739. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  45740. /* Allocate buffer */
  45741. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45742. DYNAMIC_TYPE_TMP_BUFFER));
  45743. /* Init buffer. */
  45744. if (rsaCert != NULL) {
  45745. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  45746. }
  45747. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  45748. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45749. DYNAMIC_TYPE_TMP_BUFFER));
  45750. if (rsaPrivKey != NULL) {
  45751. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  45752. }
  45753. #else
  45754. /* File system. */
  45755. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  45756. rsaCertSz = (word32)FOURK_BUF;
  45757. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45758. DYNAMIC_TYPE_TMP_BUFFER));
  45759. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  45760. certFile)) > 0);
  45761. if (certFile != XBADFILE)
  45762. XFCLOSE(certFile);
  45763. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  45764. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45765. DYNAMIC_TYPE_TMP_BUFFER));
  45766. rsaPrivKeySz = (word32)FOURK_BUF;
  45767. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  45768. keyFile)) > 0);
  45769. if (keyFile != XBADFILE)
  45770. XFCLOSE(keyFile);
  45771. #endif /* USE_CERT_BUFFERS */
  45772. #endif /* NO_RSA */
  45773. /* ECC */
  45774. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45775. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45776. #ifdef USE_CERT_BUFFERS_256
  45777. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  45778. DYNAMIC_TYPE_TMP_BUFFER));
  45779. /* Init buffer. */
  45780. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  45781. if (eccCert != NULL) {
  45782. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  45783. }
  45784. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  45785. DYNAMIC_TYPE_TMP_BUFFER));
  45786. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  45787. if (eccPrivKey != NULL) {
  45788. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  45789. }
  45790. #else /* File system. */
  45791. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  45792. eccCertSz = (word32)FOURK_BUF;
  45793. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45794. DYNAMIC_TYPE_TMP_BUFFER));
  45795. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  45796. certFile)) > 0);
  45797. if (certFile != XBADFILE) {
  45798. XFCLOSE(certFile);
  45799. }
  45800. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  45801. eccPrivKeySz = (word32)FOURK_BUF;
  45802. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45803. DYNAMIC_TYPE_TMP_BUFFER));
  45804. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  45805. keyFile)) > 0);
  45806. if (keyFile != XBADFILE) {
  45807. XFCLOSE(keyFile);
  45808. }
  45809. #endif /* USE_CERT_BUFFERS_256 */
  45810. #endif /* END HAVE_ECC */
  45811. #ifndef NO_FILESYSTEM
  45812. /* Silence. */
  45813. (void)keyFile;
  45814. (void)certFile;
  45815. #endif
  45816. {
  45817. const pkcs7EnvelopedVector testVectors[] = {
  45818. /* DATA is a global variable defined in the makefile. */
  45819. #if !defined(NO_RSA)
  45820. #ifndef NO_DES3
  45821. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  45822. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45823. #endif /* NO_DES3 */
  45824. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45825. #ifndef NO_AES_128
  45826. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  45827. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45828. #endif
  45829. #ifndef NO_AES_192
  45830. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  45831. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45832. #endif
  45833. #ifndef NO_AES_256
  45834. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  45835. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  45836. #endif
  45837. #endif /* NO_AES && HAVE_AES_CBC */
  45838. #endif /* NO_RSA */
  45839. #if defined(HAVE_ECC)
  45840. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45841. #if !defined(NO_SHA) && !defined(NO_AES_128)
  45842. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45843. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  45844. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45845. #endif
  45846. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  45847. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45848. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  45849. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45850. #endif
  45851. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  45852. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  45853. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  45854. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  45855. #endif
  45856. #endif /* NO_AES && HAVE_AES_CBC*/
  45857. #endif /* END HAVE_ECC */
  45858. }; /* END pkcs7EnvelopedVector */
  45859. #ifdef ECC_TIMING_RESISTANT
  45860. ExpectIntEQ(wc_InitRng(&rng), 0);
  45861. #endif
  45862. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45863. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  45864. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  45865. for (i = 0; i < testSz; i++) {
  45866. #ifdef ASN_BER_TO_DER
  45867. encodeSignedDataStream strm;
  45868. /* test setting stream mode, the first one using IO callbacks */
  45869. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  45870. (word32)(testVectors + i)->certSz), 0);
  45871. if (pkcs7 != NULL) {
  45872. #ifdef ECC_TIMING_RESISTANT
  45873. pkcs7->rng = &rng;
  45874. #endif
  45875. if (i != 0)
  45876. pkcs7->content = (byte*)(testVectors + i)->content;
  45877. pkcs7->contentSz = (testVectors + i)->contentSz;
  45878. pkcs7->contentOID = (testVectors + i)->contentOID;
  45879. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  45880. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  45881. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  45882. pkcs7->privateKey = (testVectors + i)->privateKey;
  45883. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  45884. }
  45885. if (i == 0) {
  45886. XMEMSET(&strm, 0, sizeof(strm));
  45887. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  45888. StreamOutputCB, (void*)&strm), 0);
  45889. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  45890. }
  45891. else {
  45892. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  45893. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  45894. (word32)sizeof(output));
  45895. }
  45896. switch ((testVectors + i)->encryptOID) {
  45897. #ifndef NO_DES3
  45898. case DES3b:
  45899. case DESb:
  45900. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45901. break;
  45902. #endif
  45903. #ifdef HAVE_AESCCM
  45904. #ifdef WOLFSSL_AES_128
  45905. case AES128CCMb:
  45906. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45907. break;
  45908. #endif
  45909. #ifdef WOLFSSL_AES_192
  45910. case AES192CCMb:
  45911. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45912. break;
  45913. #endif
  45914. #ifdef WOLFSSL_AES_256
  45915. case AES256CCMb:
  45916. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45917. break;
  45918. #endif
  45919. #endif
  45920. default:
  45921. ExpectIntGE(encodedSz, 0);
  45922. }
  45923. if (encodedSz > 0) {
  45924. if (i == 0) {
  45925. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  45926. strm.out, (word32)encodedSz, decoded,
  45927. (word32)sizeof(decoded));
  45928. }
  45929. else {
  45930. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45931. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  45932. }
  45933. ExpectIntGE(decodedSz, 0);
  45934. /* Verify the size of each buffer. */
  45935. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  45936. }
  45937. wc_PKCS7_Free(pkcs7);
  45938. pkcs7 = NULL;
  45939. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45940. #endif
  45941. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  45942. (word32)(testVectors + i)->certSz), 0);
  45943. if (pkcs7 != NULL) {
  45944. #ifdef ECC_TIMING_RESISTANT
  45945. pkcs7->rng = &rng;
  45946. #endif
  45947. pkcs7->content = (byte*)(testVectors + i)->content;
  45948. pkcs7->contentSz = (testVectors + i)->contentSz;
  45949. pkcs7->contentOID = (testVectors + i)->contentOID;
  45950. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  45951. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  45952. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  45953. pkcs7->privateKey = (testVectors + i)->privateKey;
  45954. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  45955. }
  45956. #ifdef ASN_BER_TO_DER
  45957. /* test without setting stream mode */
  45958. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  45959. #endif
  45960. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  45961. (word32)sizeof(output)), 0);
  45962. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45963. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  45964. ExpectIntGE(decodedSz, 0);
  45965. /* Verify the size of each buffer. */
  45966. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  45967. /* Don't free the last time through the loop. */
  45968. if (i < testSz - 1) {
  45969. wc_PKCS7_Free(pkcs7);
  45970. pkcs7 = NULL;
  45971. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45972. }
  45973. } /* END test loop. */
  45974. }
  45975. /* Test bad args. */
  45976. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  45977. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45978. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  45979. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45980. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45981. /* Decode. */
  45982. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  45983. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45984. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45985. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45986. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45987. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  45988. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45989. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  45990. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  45991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45992. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  45993. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45994. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  45995. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  45996. /* only a failure for KARI test cases */
  45997. if (pkcs7 != NULL) {
  45998. tempWrd32 = pkcs7->singleCertSz;
  45999. pkcs7->singleCertSz = 0;
  46000. }
  46001. #if defined(WOLFSSL_ASN_TEMPLATE)
  46002. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46003. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46004. WC_NO_ERR_TRACE(BUFFER_E));
  46005. #else
  46006. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46007. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46008. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46009. #endif
  46010. if (pkcs7 != NULL) {
  46011. pkcs7->singleCertSz = tempWrd32;
  46012. tmpBytePtr = pkcs7->singleCert;
  46013. pkcs7->singleCert = NULL;
  46014. }
  46015. #ifndef NO_RSA
  46016. #if defined(NO_PKCS7_STREAM)
  46017. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  46018. * is returned from kari parse which gets set to bad func arg */
  46019. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46020. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46021. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46022. #else
  46023. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46024. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46025. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46026. #endif
  46027. #endif /* !NO_RSA */
  46028. if (pkcs7 != NULL) {
  46029. pkcs7->singleCert = tmpBytePtr;
  46030. }
  46031. #endif
  46032. if (pkcs7 != NULL) {
  46033. tempWrd32 = pkcs7->privateKeySz;
  46034. pkcs7->privateKeySz = 0;
  46035. }
  46036. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46037. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46038. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46039. if (pkcs7 != NULL) {
  46040. pkcs7->privateKeySz = tempWrd32;
  46041. tmpBytePtr = pkcs7->privateKey;
  46042. pkcs7->privateKey = NULL;
  46043. }
  46044. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46045. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46046. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46047. if (pkcs7 != NULL) {
  46048. pkcs7->privateKey = tmpBytePtr;
  46049. }
  46050. wc_PKCS7_Free(pkcs7);
  46051. pkcs7 = NULL;
  46052. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  46053. /* test of decrypt callback with KEKRI enveloped data */
  46054. {
  46055. int envelopedSz = 0;
  46056. const byte keyId[] = { 0x00 };
  46057. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46058. if (pkcs7 != NULL) {
  46059. pkcs7->content = (byte*)input;
  46060. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  46061. pkcs7->contentOID = DATA;
  46062. pkcs7->encryptOID = AES256CBCb;
  46063. }
  46064. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  46065. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  46066. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  46067. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  46068. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46069. (word32)sizeof(output))), 0);
  46070. wc_PKCS7_Free(pkcs7);
  46071. pkcs7 = NULL;
  46072. /* decode envelopedData */
  46073. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46074. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  46075. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  46076. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46077. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  46078. wc_PKCS7_Free(pkcs7);
  46079. pkcs7 = NULL;
  46080. }
  46081. #endif /* !NO_AES && !NO_AES_256 */
  46082. #ifndef NO_RSA
  46083. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46084. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46085. #endif /* NO_RSA */
  46086. #ifdef HAVE_ECC
  46087. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46088. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46089. #endif /* HAVE_ECC */
  46090. #ifdef ECC_TIMING_RESISTANT
  46091. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46092. #endif
  46093. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  46094. !defined(NO_RSA) && !defined(NO_SHA)
  46095. {
  46096. byte out[7];
  46097. byte *cms = NULL;
  46098. word32 cmsSz;
  46099. XFILE cmsFile = XBADFILE;
  46100. XMEMSET(out, 0, sizeof(out));
  46101. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46102. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  46103. != XBADFILE);
  46104. cmsSz = (word32)FOURK_BUF;
  46105. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46106. DYNAMIC_TYPE_TMP_BUFFER));
  46107. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  46108. if (cmsFile != XBADFILE)
  46109. XFCLOSE(cmsFile);
  46110. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  46111. sizeof_client_cert_der_2048), 0);
  46112. if (pkcs7 != NULL) {
  46113. pkcs7->privateKey = (byte*)client_key_der_2048;
  46114. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  46115. }
  46116. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46117. 2), 0);
  46118. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46119. sizeof(out)), 0);
  46120. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46121. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  46122. wc_PKCS7_Free(pkcs7);
  46123. pkcs7 = NULL;
  46124. }
  46125. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  46126. #endif /* HAVE_PKCS7 */
  46127. return EXPECT_RESULT();
  46128. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  46129. /*
  46130. * Testing wc_PKCS7_EncodeEncryptedData()
  46131. */
  46132. static int test_wc_PKCS7_EncodeEncryptedData(void)
  46133. {
  46134. EXPECT_DECLS;
  46135. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  46136. PKCS7* pkcs7 = NULL;
  46137. byte* tmpBytePtr = NULL;
  46138. byte encrypted[TWOK_BUF];
  46139. byte decoded[TWOK_BUF];
  46140. word32 tmpWrd32 = 0;
  46141. int tmpInt = 0;
  46142. int decodedSz = 0;
  46143. int encryptedSz = 0;
  46144. int testSz = 0;
  46145. int i = 0;
  46146. const byte data[] = { /* Hello World */
  46147. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46148. 0x72,0x6c,0x64
  46149. };
  46150. #ifndef NO_DES3
  46151. byte desKey[] = {
  46152. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  46153. };
  46154. byte des3Key[] = {
  46155. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  46156. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  46157. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  46158. };
  46159. #endif
  46160. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46161. #ifndef NO_AES_128
  46162. byte aes128Key[] = {
  46163. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46164. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46165. };
  46166. #endif
  46167. #ifndef NO_AES_192
  46168. byte aes192Key[] = {
  46169. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46170. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46171. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46172. };
  46173. #endif
  46174. #ifndef NO_AES_256
  46175. byte aes256Key[] = {
  46176. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46177. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46178. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46179. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46180. };
  46181. #endif
  46182. #endif /* !NO_AES && HAVE_AES_CBC */
  46183. const pkcs7EncryptedVector testVectors[] =
  46184. {
  46185. #ifndef NO_DES3
  46186. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  46187. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  46188. #endif /* !NO_DES3 */
  46189. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46190. #ifndef NO_AES_128
  46191. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  46192. sizeof(aes128Key)},
  46193. #endif
  46194. #ifndef NO_AES_192
  46195. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  46196. sizeof(aes192Key)},
  46197. #endif
  46198. #ifndef NO_AES_256
  46199. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46200. sizeof(aes256Key)},
  46201. #endif
  46202. #endif /* !NO_AES && HAVE_AES_CBC */
  46203. };
  46204. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  46205. for (i = 0; i < testSz; i++) {
  46206. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46207. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46208. if (pkcs7 != NULL) {
  46209. pkcs7->content = (byte*)testVectors[i].content;
  46210. pkcs7->contentSz = testVectors[i].contentSz;
  46211. pkcs7->contentOID = testVectors[i].contentOID;
  46212. pkcs7->encryptOID = testVectors[i].encryptOID;
  46213. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  46214. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  46215. pkcs7->heap = HEAP_HINT;
  46216. }
  46217. /* encode encryptedData */
  46218. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46219. sizeof(encrypted)), 0);
  46220. /* Decode encryptedData */
  46221. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  46222. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  46223. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  46224. /* Keep values for last itr. */
  46225. if (i < testSz - 1) {
  46226. wc_PKCS7_Free(pkcs7);
  46227. pkcs7 = NULL;
  46228. }
  46229. }
  46230. if (pkcs7 == NULL || testSz == 0) {
  46231. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46232. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46233. }
  46234. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  46235. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46236. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  46237. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46238. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46239. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46240. /* Testing the struct. */
  46241. if (pkcs7 != NULL) {
  46242. tmpBytePtr = pkcs7->content;
  46243. pkcs7->content = NULL;
  46244. }
  46245. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46246. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46247. if (pkcs7 != NULL) {
  46248. pkcs7->content = tmpBytePtr;
  46249. tmpWrd32 = pkcs7->contentSz;
  46250. pkcs7->contentSz = 0;
  46251. }
  46252. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46253. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46254. if (pkcs7 != NULL) {
  46255. pkcs7->contentSz = tmpWrd32;
  46256. tmpInt = pkcs7->encryptOID;
  46257. pkcs7->encryptOID = 0;
  46258. }
  46259. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46260. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46261. if (pkcs7 != NULL) {
  46262. pkcs7->encryptOID = tmpInt;
  46263. tmpBytePtr = pkcs7->encryptionKey;
  46264. pkcs7->encryptionKey = NULL;
  46265. }
  46266. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46267. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46268. if (pkcs7 != NULL) {
  46269. pkcs7->encryptionKey = tmpBytePtr;
  46270. tmpWrd32 = pkcs7->encryptionKeySz;
  46271. pkcs7->encryptionKeySz = 0;
  46272. }
  46273. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46274. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46275. if (pkcs7 != NULL) {
  46276. pkcs7->encryptionKeySz = tmpWrd32;
  46277. }
  46278. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  46279. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46280. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  46281. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46282. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  46283. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46284. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46285. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46286. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46287. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46288. /* Test struct fields */
  46289. if (pkcs7 != NULL) {
  46290. tmpBytePtr = pkcs7->encryptionKey;
  46291. pkcs7->encryptionKey = NULL;
  46292. }
  46293. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46294. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46295. if (pkcs7 != NULL) {
  46296. pkcs7->encryptionKey = tmpBytePtr;
  46297. pkcs7->encryptionKeySz = 0;
  46298. }
  46299. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46300. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46301. wc_PKCS7_Free(pkcs7);
  46302. #endif
  46303. return EXPECT_RESULT();
  46304. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  46305. /*
  46306. * Testing wc_PKCS7_Degenerate()
  46307. */
  46308. static int test_wc_PKCS7_Degenerate(void)
  46309. {
  46310. EXPECT_DECLS;
  46311. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  46312. PKCS7* pkcs7 = NULL;
  46313. char fName[] = "./certs/test-degenerate.p7b";
  46314. XFILE f = XBADFILE;
  46315. byte der[4096];
  46316. word32 derSz = 0;
  46317. #ifndef NO_PKCS7_STREAM
  46318. word32 z;
  46319. int ret;
  46320. #endif /* !NO_PKCS7_STREAM */
  46321. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46322. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46323. if (f != XBADFILE)
  46324. XFCLOSE(f);
  46325. /* test degenerate success */
  46326. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46327. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46328. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46329. #ifndef NO_RSA
  46330. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46331. #ifndef NO_PKCS7_STREAM
  46332. wc_PKCS7_Free(pkcs7);
  46333. pkcs7 = NULL;
  46334. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46335. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46336. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46337. /* test for streaming */
  46338. ret = -1;
  46339. for (z = 0; z < derSz && ret != 0; z++) {
  46340. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46341. if (ret < 0){
  46342. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46343. }
  46344. }
  46345. ExpectIntEQ(ret, 0);
  46346. #endif /* !NO_PKCS7_STREAM */
  46347. #else
  46348. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46349. #endif /* NO_RSA */
  46350. wc_PKCS7_Free(pkcs7);
  46351. pkcs7 = NULL;
  46352. /* test with turning off degenerate cases */
  46353. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46354. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46355. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46356. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46357. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  46358. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46359. #ifndef NO_PKCS7_STREAM
  46360. wc_PKCS7_Free(pkcs7);
  46361. pkcs7 = NULL;
  46362. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46363. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46364. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46365. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46366. /* test for streaming */
  46367. ret = -1;
  46368. for (z = 0; z < derSz && ret != 0; z++) {
  46369. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46370. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46371. continue;
  46372. }
  46373. else
  46374. break;
  46375. }
  46376. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46377. #endif /* !NO_PKCS7_STREAM */
  46378. wc_PKCS7_Free(pkcs7);
  46379. #endif
  46380. return EXPECT_RESULT();
  46381. } /* END test_wc_PKCS7_Degenerate() */
  46382. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46383. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  46384. static byte berContent[] = {
  46385. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46386. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  46387. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  46388. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  46389. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  46390. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  46391. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  46392. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  46393. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  46394. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  46395. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  46396. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  46397. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  46398. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  46399. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  46400. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  46401. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  46402. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  46403. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  46404. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  46405. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  46406. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  46407. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  46408. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  46409. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  46410. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  46411. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46412. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  46413. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  46414. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  46415. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  46416. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  46417. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  46418. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  46419. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  46420. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  46421. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  46422. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  46423. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  46424. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  46425. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  46426. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  46427. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  46428. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  46429. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46430. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  46431. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  46432. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  46433. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  46434. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  46435. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  46436. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  46437. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  46438. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  46439. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  46440. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  46441. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  46442. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  46443. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  46444. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  46445. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  46446. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  46447. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  46448. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  46449. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  46450. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  46451. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  46452. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  46453. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  46454. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  46455. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  46456. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  46457. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  46458. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  46459. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  46460. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  46461. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  46462. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  46463. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  46464. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  46465. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  46466. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  46467. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  46468. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  46469. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  46470. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  46471. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  46472. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  46473. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  46474. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  46475. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  46476. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  46477. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  46478. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  46479. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  46480. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  46481. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  46482. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  46483. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  46484. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  46485. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  46486. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  46487. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  46488. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  46489. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  46490. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  46491. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  46492. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  46493. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  46494. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  46495. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  46496. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  46497. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  46498. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  46499. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  46500. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  46501. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  46502. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  46503. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  46504. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  46505. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  46506. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  46507. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  46508. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  46509. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  46510. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  46511. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  46512. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  46513. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  46514. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  46515. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  46516. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  46517. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  46518. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  46519. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  46520. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  46521. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  46522. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  46523. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  46524. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  46525. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  46526. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  46527. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  46528. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  46529. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  46530. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  46531. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  46532. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  46533. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  46534. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  46535. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  46536. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  46537. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  46538. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  46539. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  46540. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  46541. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  46542. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  46543. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  46544. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  46545. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  46546. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  46547. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  46548. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  46549. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  46550. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  46551. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  46552. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  46553. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  46554. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  46555. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  46556. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  46557. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  46558. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  46559. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  46560. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  46561. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  46562. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  46563. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  46564. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  46565. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  46566. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  46567. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  46568. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  46569. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  46570. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  46571. 0x00, 0x00, 0x00, 0x00, 0x00
  46572. };
  46573. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  46574. * !NO_DES3 && !NO_SHA
  46575. */
  46576. /*
  46577. * Testing wc_PKCS7_BER()
  46578. */
  46579. static int test_wc_PKCS7_BER(void)
  46580. {
  46581. EXPECT_DECLS;
  46582. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46583. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  46584. PKCS7* pkcs7 = NULL;
  46585. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  46586. XFILE f = XBADFILE;
  46587. byte der[4096];
  46588. #ifndef NO_DES3
  46589. byte decoded[2048];
  46590. #endif
  46591. word32 derSz = 0;
  46592. #ifndef NO_PKCS7_STREAM
  46593. word32 z;
  46594. int ret;
  46595. #endif /* !NO_PKCS7_STREAM */
  46596. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46597. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46598. if (f != XBADFILE) {
  46599. XFCLOSE(f);
  46600. f = XBADFILE;
  46601. }
  46602. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46603. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46604. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46605. #ifndef NO_RSA
  46606. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46607. #ifndef NO_PKCS7_STREAM
  46608. wc_PKCS7_Free(pkcs7);
  46609. pkcs7 = NULL;
  46610. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46611. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46612. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46613. /* test for streaming */
  46614. ret = -1;
  46615. for (z = 0; z < derSz && ret != 0; z++) {
  46616. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46617. if (ret < 0){
  46618. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46619. }
  46620. }
  46621. ExpectIntEQ(ret, 0);
  46622. #endif /* !NO_PKCS7_STREAM */
  46623. #else
  46624. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46625. #endif
  46626. wc_PKCS7_Free(pkcs7);
  46627. pkcs7 = NULL;
  46628. #ifndef NO_DES3
  46629. /* decode BER content */
  46630. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  46631. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46632. if (f != XBADFILE) {
  46633. XFCLOSE(f);
  46634. f = XBADFILE;
  46635. }
  46636. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46637. #ifndef NO_RSA
  46638. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46639. #else
  46640. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46641. #endif
  46642. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  46643. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46644. if (f != XBADFILE) {
  46645. XFCLOSE(f);
  46646. f = XBADFILE;
  46647. }
  46648. if (pkcs7 != NULL) {
  46649. pkcs7->privateKey = der;
  46650. pkcs7->privateKeySz = derSz;
  46651. }
  46652. #ifndef NO_RSA
  46653. #ifdef WOLFSSL_SP_MATH
  46654. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46655. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  46656. #else
  46657. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46658. sizeof(berContent), decoded, sizeof(decoded)), 0);
  46659. #endif
  46660. #else
  46661. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46662. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  46663. #endif
  46664. wc_PKCS7_Free(pkcs7);
  46665. #endif /* !NO_DES3 */
  46666. #endif
  46667. return EXPECT_RESULT();
  46668. } /* END test_wc_PKCS7_BER() */
  46669. static int test_wc_PKCS7_signed_enveloped(void)
  46670. {
  46671. EXPECT_DECLS;
  46672. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  46673. !defined(NO_FILESYSTEM)
  46674. XFILE f = XBADFILE;
  46675. PKCS7* pkcs7 = NULL;
  46676. #ifdef HAVE_AES_CBC
  46677. PKCS7* inner = NULL;
  46678. #endif
  46679. WC_RNG rng;
  46680. unsigned char key[FOURK_BUF/2];
  46681. unsigned char cert[FOURK_BUF/2];
  46682. unsigned char env[FOURK_BUF];
  46683. int envSz = FOURK_BUF;
  46684. int keySz = 0;
  46685. int certSz = 0;
  46686. unsigned char sig[FOURK_BUF * 2];
  46687. int sigSz = FOURK_BUF * 2;
  46688. #ifdef HAVE_AES_CBC
  46689. unsigned char decoded[FOURK_BUF];
  46690. int decodedSz = FOURK_BUF;
  46691. #endif
  46692. #ifndef NO_PKCS7_STREAM
  46693. int z;
  46694. int ret;
  46695. #endif /* !NO_PKCS7_STREAM */
  46696. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46697. /* load cert */
  46698. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  46699. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  46700. if (f != XBADFILE) {
  46701. XFCLOSE(f);
  46702. f = XBADFILE;
  46703. }
  46704. /* load key */
  46705. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  46706. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  46707. if (f != XBADFILE) {
  46708. XFCLOSE(f);
  46709. f = XBADFILE;
  46710. }
  46711. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  46712. /* sign cert for envelope */
  46713. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46714. ExpectIntEQ(wc_InitRng(&rng), 0);
  46715. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46716. if (pkcs7 != NULL) {
  46717. pkcs7->content = cert;
  46718. pkcs7->contentSz = (word32)certSz;
  46719. pkcs7->contentOID = DATA;
  46720. pkcs7->privateKey = key;
  46721. pkcs7->privateKeySz = (word32)keySz;
  46722. pkcs7->encryptOID = RSAk;
  46723. pkcs7->hashOID = SHA256h;
  46724. pkcs7->rng = &rng;
  46725. }
  46726. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46727. wc_PKCS7_Free(pkcs7);
  46728. pkcs7 = NULL;
  46729. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46730. #ifdef HAVE_AES_CBC
  46731. /* create envelope */
  46732. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46733. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46734. if (pkcs7 != NULL) {
  46735. pkcs7->content = sig;
  46736. pkcs7->contentSz = (word32)sigSz;
  46737. pkcs7->contentOID = DATA;
  46738. pkcs7->encryptOID = AES256CBCb;
  46739. pkcs7->privateKey = key;
  46740. pkcs7->privateKeySz = (word32)keySz;
  46741. }
  46742. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  46743. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  46744. wc_PKCS7_Free(pkcs7);
  46745. pkcs7 = NULL;
  46746. #endif
  46747. /* create bad signed enveloped data */
  46748. sigSz = FOURK_BUF * 2;
  46749. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46750. ExpectIntEQ(wc_InitRng(&rng), 0);
  46751. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46752. if (pkcs7 != NULL) {
  46753. pkcs7->content = env;
  46754. pkcs7->contentSz = (word32)envSz;
  46755. pkcs7->contentOID = DATA;
  46756. pkcs7->privateKey = key;
  46757. pkcs7->privateKeySz = (word32)keySz;
  46758. pkcs7->encryptOID = RSAk;
  46759. pkcs7->hashOID = SHA256h;
  46760. pkcs7->rng = &rng;
  46761. }
  46762. /* Set no certs in bundle for this test. */
  46763. if (pkcs7 != NULL) {
  46764. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  46765. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46766. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  46767. }
  46768. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46769. wc_PKCS7_Free(pkcs7);
  46770. pkcs7 = NULL;
  46771. /* check verify fails */
  46772. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46773. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46774. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  46775. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  46776. /* try verifying the signature manually */
  46777. {
  46778. RsaKey rKey;
  46779. word32 idx = 0;
  46780. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  46781. WC_MAX_DIGEST_SIZE];
  46782. int digestSz = 0;
  46783. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  46784. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  46785. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  46786. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  46787. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  46788. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  46789. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  46790. /* verify was success */
  46791. }
  46792. wc_PKCS7_Free(pkcs7);
  46793. pkcs7 = NULL;
  46794. /* initializing the PKCS7 struct with the signing certificate should pass */
  46795. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46796. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46797. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  46798. #ifndef NO_PKCS7_STREAM
  46799. wc_PKCS7_Free(pkcs7);
  46800. pkcs7 = NULL;
  46801. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46802. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46803. /* test for streaming */
  46804. ret = -1;
  46805. for (z = 0; z < sigSz && ret != 0; z++) {
  46806. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  46807. if (ret < 0){
  46808. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46809. }
  46810. }
  46811. ExpectIntEQ(ret, 0);
  46812. #endif /* !NO_PKCS7_STREAM */
  46813. wc_PKCS7_Free(pkcs7);
  46814. pkcs7 = NULL;
  46815. /* create valid degenerate bundle */
  46816. sigSz = FOURK_BUF * 2;
  46817. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46818. if (pkcs7 != NULL) {
  46819. pkcs7->content = env;
  46820. pkcs7->contentSz = (word32)envSz;
  46821. pkcs7->contentOID = DATA;
  46822. pkcs7->privateKey = key;
  46823. pkcs7->privateKeySz = (word32)keySz;
  46824. pkcs7->encryptOID = RSAk;
  46825. pkcs7->hashOID = SHA256h;
  46826. pkcs7->rng = &rng;
  46827. }
  46828. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  46829. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46830. wc_PKCS7_Free(pkcs7);
  46831. pkcs7 = NULL;
  46832. wc_FreeRng(&rng);
  46833. /* check verify */
  46834. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46835. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46836. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  46837. ExpectNotNull(pkcs7->content);
  46838. #ifndef NO_PKCS7_STREAM
  46839. wc_PKCS7_Free(pkcs7);
  46840. pkcs7 = NULL;
  46841. /* create valid degenerate bundle */
  46842. sigSz = FOURK_BUF * 2;
  46843. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46844. if (pkcs7 != NULL) {
  46845. pkcs7->content = env;
  46846. pkcs7->contentSz = (word32)envSz;
  46847. pkcs7->contentOID = DATA;
  46848. pkcs7->privateKey = key;
  46849. pkcs7->privateKeySz = (word32)keySz;
  46850. pkcs7->encryptOID = RSAk;
  46851. pkcs7->hashOID = SHA256h;
  46852. pkcs7->rng = &rng;
  46853. }
  46854. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  46855. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46856. wc_PKCS7_Free(pkcs7);
  46857. pkcs7 = NULL;
  46858. wc_FreeRng(&rng);
  46859. /* check verify */
  46860. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46861. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46862. /* test for streaming */
  46863. ret = -1;
  46864. for (z = 0; z < sigSz && ret != 0; z++) {
  46865. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  46866. if (ret < 0){
  46867. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46868. }
  46869. }
  46870. ExpectIntEQ(ret, 0);
  46871. #endif /* !NO_PKCS7_STREAM */
  46872. #ifdef HAVE_AES_CBC
  46873. /* check decode */
  46874. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  46875. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  46876. if (inner != NULL) {
  46877. inner->privateKey = key;
  46878. inner->privateKeySz = (word32)keySz;
  46879. }
  46880. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  46881. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  46882. wc_PKCS7_Free(inner);
  46883. inner = NULL;
  46884. #endif
  46885. wc_PKCS7_Free(pkcs7);
  46886. pkcs7 = NULL;
  46887. #ifdef HAVE_AES_CBC
  46888. /* check cert set */
  46889. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46890. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46891. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  46892. ExpectNotNull(pkcs7->singleCert);
  46893. ExpectIntNE(pkcs7->singleCertSz, 0);
  46894. wc_PKCS7_Free(pkcs7);
  46895. pkcs7 = NULL;
  46896. #ifndef NO_PKCS7_STREAM
  46897. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46898. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46899. /* test for streaming */
  46900. ret = -1;
  46901. for (z = 0; z < decodedSz && ret != 0; z++) {
  46902. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  46903. if (ret < 0){
  46904. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46905. }
  46906. }
  46907. ExpectIntEQ(ret, 0);
  46908. ExpectNotNull(pkcs7->singleCert);
  46909. ExpectIntNE(pkcs7->singleCertSz, 0);
  46910. wc_PKCS7_Free(pkcs7);
  46911. pkcs7 = NULL;
  46912. #endif /* !NO_PKCS7_STREAM */
  46913. #endif
  46914. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  46915. return EXPECT_RESULT();
  46916. }
  46917. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  46918. {
  46919. EXPECT_DECLS;
  46920. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46921. && !defined(NO_AES)
  46922. PKCS7* pkcs7 = NULL;
  46923. void* heap = NULL;
  46924. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46925. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46926. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46927. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  46928. wc_PKCS7_Free(pkcs7);
  46929. #endif
  46930. return EXPECT_RESULT();
  46931. }
  46932. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  46933. {
  46934. EXPECT_DECLS;
  46935. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46936. && !defined(NO_AES)
  46937. PKCS7* pkcs7 = NULL;
  46938. void* heap = NULL;
  46939. WOLFSSL_CTX* ctx = NULL;
  46940. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46941. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46942. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46943. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  46944. wc_PKCS7_Free(pkcs7);
  46945. #endif
  46946. return EXPECT_RESULT();
  46947. }
  46948. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  46949. {
  46950. EXPECT_DECLS;
  46951. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46952. && !defined(NO_AES)
  46953. PKCS7* pkcs7 = NULL;
  46954. void* heap = NULL;
  46955. WOLFSSL_CTX* ctx = NULL;
  46956. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  46957. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  46958. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46959. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  46960. wc_PKCS7_Free(pkcs7);
  46961. #endif
  46962. return EXPECT_RESULT();
  46963. }
  46964. static int test_wc_PKCS7_DecodeCompressedData(void)
  46965. {
  46966. EXPECT_DECLS;
  46967. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  46968. && !defined(NO_AES) && defined(HAVE_LIBZ)
  46969. PKCS7* pkcs7 = NULL;
  46970. void* heap = NULL;
  46971. byte out[4096];
  46972. byte* decompressed = NULL;
  46973. int outSz;
  46974. int decompressedSz;
  46975. const char* cert = "./certs/client-cert.pem";
  46976. byte* cert_buf = NULL;
  46977. size_t cert_sz = 0;
  46978. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  46979. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  46980. DYNAMIC_TYPE_TMP_BUFFER)));
  46981. decompressedSz = (int)cert_sz;
  46982. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  46983. if (pkcs7 != NULL) {
  46984. pkcs7->content = (byte*)cert_buf;
  46985. pkcs7->contentSz = (word32)cert_sz;
  46986. pkcs7->contentOID = DATA;
  46987. }
  46988. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  46989. sizeof(out))), 0);
  46990. wc_PKCS7_Free(pkcs7);
  46991. pkcs7 = NULL;
  46992. /* compressed key should be smaller than when started */
  46993. ExpectIntLT(outSz, cert_sz);
  46994. /* test decompression */
  46995. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  46996. ExpectIntEQ(pkcs7->contentOID, 0);
  46997. /* fail case with out buffer too small */
  46998. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  46999. decompressed, outSz), 0);
  47000. /* success case */
  47001. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  47002. decompressed, decompressedSz), cert_sz);
  47003. ExpectIntEQ(pkcs7->contentOID, DATA);
  47004. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47005. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47006. decompressed = NULL;
  47007. /* test decompression function with different 'max' inputs */
  47008. outSz = sizeof(out);
  47009. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  47010. 0);
  47011. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  47012. out, outSz, 0, heap), 0);
  47013. ExpectNull(decompressed);
  47014. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  47015. out, outSz, 0, heap), 0);
  47016. ExpectNotNull(decompressed);
  47017. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47018. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47019. decompressed = NULL;
  47020. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  47021. out, outSz, 0, heap), 0);
  47022. ExpectNotNull(decompressed);
  47023. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47024. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47025. if (cert_buf != NULL)
  47026. free(cert_buf);
  47027. wc_PKCS7_Free(pkcs7);
  47028. #endif
  47029. return EXPECT_RESULT();
  47030. }
  47031. static int test_wc_i2d_PKCS12(void)
  47032. {
  47033. EXPECT_DECLS;
  47034. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  47035. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47036. && !defined(NO_AES) && !defined(NO_SHA)
  47037. WC_PKCS12* pkcs12 = NULL;
  47038. unsigned char der[FOURK_BUF * 2];
  47039. unsigned char* pt;
  47040. int derSz = 0;
  47041. unsigned char out[FOURK_BUF * 2];
  47042. int outSz = FOURK_BUF * 2;
  47043. const char p12_f[] = "./certs/test-servercert.p12";
  47044. XFILE f = XBADFILE;
  47045. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  47046. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  47047. if (f != XBADFILE)
  47048. XFCLOSE(f);
  47049. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47050. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  47051. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47052. ExpectIntEQ(outSz, derSz);
  47053. outSz = derSz - 1;
  47054. pt = out;
  47055. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  47056. outSz = derSz;
  47057. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  47058. ExpectIntEQ((pt == out), 0);
  47059. pt = NULL;
  47060. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  47061. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  47062. wc_PKCS12_free(pkcs12);
  47063. pkcs12 = NULL;
  47064. /* Run the same test but use wc_d2i_PKCS12_fp. */
  47065. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47066. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47067. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47068. ExpectIntEQ(outSz, derSz);
  47069. wc_PKCS12_free(pkcs12);
  47070. pkcs12 = NULL;
  47071. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  47072. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47073. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47074. ExpectIntEQ(outSz, derSz);
  47075. wc_PKCS12_free(pkcs12);
  47076. pkcs12 = NULL;
  47077. #endif
  47078. return EXPECT_RESULT();
  47079. }
  47080. /* Testing wc_SignatureGetSize() for signature type ECC */
  47081. static int test_wc_SignatureGetSize_ecc(void)
  47082. {
  47083. EXPECT_DECLS;
  47084. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  47085. enum wc_SignatureType sig_type;
  47086. word32 key_len;
  47087. ecc_key ecc;
  47088. const char* qx =
  47089. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  47090. const char* qy =
  47091. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  47092. const char* d =
  47093. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  47094. XMEMSET(&ecc, 0, sizeof(ecc_key));
  47095. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  47096. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  47097. /* Input for signature type ECC */
  47098. sig_type = WC_SIGNATURE_TYPE_ECC;
  47099. key_len = sizeof(ecc_key);
  47100. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  47101. /* Test bad args */
  47102. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47103. sig_type = (enum wc_SignatureType) 100;
  47104. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47105. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47106. sig_type = WC_SIGNATURE_TYPE_ECC;
  47107. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  47108. key_len = (word32)0;
  47109. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47110. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  47111. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  47112. return EXPECT_RESULT();
  47113. } /* END test_wc_SignatureGetSize_ecc() */
  47114. /* Testing wc_SignatureGetSize() for signature type rsa */
  47115. static int test_wc_SignatureGetSize_rsa(void)
  47116. {
  47117. EXPECT_DECLS;
  47118. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  47119. enum wc_SignatureType sig_type;
  47120. word32 key_len;
  47121. word32 idx = 0;
  47122. RsaKey rsa_key;
  47123. byte* tmp = NULL;
  47124. size_t bytes;
  47125. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  47126. #ifdef USE_CERT_BUFFERS_1024
  47127. bytes = (size_t)sizeof_client_key_der_1024;
  47128. if (bytes < (size_t)sizeof_client_key_der_1024)
  47129. bytes = (size_t)sizeof_client_cert_der_1024;
  47130. #elif defined(USE_CERT_BUFFERS_2048)
  47131. bytes = (size_t)sizeof_client_key_der_2048;
  47132. if (bytes < (size_t)sizeof_client_cert_der_2048)
  47133. bytes = (size_t)sizeof_client_cert_der_2048;
  47134. #else
  47135. bytes = FOURK_BUF;
  47136. #endif
  47137. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  47138. DYNAMIC_TYPE_TMP_BUFFER));
  47139. if (tmp != NULL) {
  47140. #ifdef USE_CERT_BUFFERS_1024
  47141. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  47142. #elif defined(USE_CERT_BUFFERS_2048)
  47143. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  47144. #elif !defined(NO_FILESYSTEM)
  47145. XFILE file = XBADFILE;
  47146. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  47147. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  47148. if (file != XBADFILE)
  47149. XFCLOSE(file);
  47150. }
  47151. #else
  47152. ExpectFail();
  47153. #endif
  47154. }
  47155. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  47156. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  47157. /* Input for signature type RSA */
  47158. sig_type = WC_SIGNATURE_TYPE_RSA;
  47159. key_len = sizeof(RsaKey);
  47160. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  47161. /* Test bad args */
  47162. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47163. sig_type = (enum wc_SignatureType)100;
  47164. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47165. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47166. sig_type = WC_SIGNATURE_TYPE_RSA;
  47167. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47168. key_len = (word32)0;
  47169. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47170. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  47171. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47172. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  47173. return EXPECT_RESULT();
  47174. } /* END test_wc_SignatureGetSize_rsa(void) */
  47175. /*----------------------------------------------------------------------------*
  47176. | hash.h Tests
  47177. *----------------------------------------------------------------------------*/
  47178. static int test_wc_HashInit(void)
  47179. {
  47180. EXPECT_DECLS;
  47181. int i; /* 0 indicates tests passed, 1 indicates failure */
  47182. wc_HashAlg hash;
  47183. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47184. enum wc_HashType enumArray[] = {
  47185. #ifndef NO_MD5
  47186. WC_HASH_TYPE_MD5,
  47187. #endif
  47188. #ifndef NO_SHA
  47189. WC_HASH_TYPE_SHA,
  47190. #endif
  47191. #ifdef WOLFSSL_SHA224
  47192. WC_HASH_TYPE_SHA224,
  47193. #endif
  47194. #ifndef NO_SHA256
  47195. WC_HASH_TYPE_SHA256,
  47196. #endif
  47197. #ifdef WOLFSSL_SHA384
  47198. WC_HASH_TYPE_SHA384,
  47199. #endif
  47200. #ifdef WOLFSSL_SHA512
  47201. WC_HASH_TYPE_SHA512,
  47202. #endif
  47203. };
  47204. /* dynamically finds the length */
  47205. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47206. /* For loop to test various arguments... */
  47207. for (i = 0; i < enumlen; i++) {
  47208. /* check for bad args */
  47209. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47210. wc_HashFree(&hash, enumArray[i]);
  47211. /* check for null ptr */
  47212. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47213. } /* end of for loop */
  47214. return EXPECT_RESULT();
  47215. } /* end of test_wc_HashInit */
  47216. /*
  47217. * Unit test function for wc_HashSetFlags()
  47218. */
  47219. static int test_wc_HashSetFlags(void)
  47220. {
  47221. EXPECT_DECLS;
  47222. #ifdef WOLFSSL_HASH_FLAGS
  47223. wc_HashAlg hash;
  47224. word32 flags = 0;
  47225. int i, j;
  47226. int notSupportedLen;
  47227. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47228. enum wc_HashType enumArray[] = {
  47229. #ifndef NO_MD5
  47230. WC_HASH_TYPE_MD5,
  47231. #endif
  47232. #ifndef NO_SHA
  47233. WC_HASH_TYPE_SHA,
  47234. #endif
  47235. #ifdef WOLFSSL_SHA224
  47236. WC_HASH_TYPE_SHA224,
  47237. #endif
  47238. #ifndef NO_SHA256
  47239. WC_HASH_TYPE_SHA256,
  47240. #endif
  47241. #ifdef WOLFSSL_SHA384
  47242. WC_HASH_TYPE_SHA384,
  47243. #endif
  47244. #ifdef WOLFSSL_SHA512
  47245. WC_HASH_TYPE_SHA512,
  47246. #endif
  47247. #ifdef WOLFSSL_SHA3
  47248. WC_HASH_TYPE_SHA3_224,
  47249. #endif
  47250. };
  47251. enum wc_HashType notSupported[] = {
  47252. WC_HASH_TYPE_MD5_SHA,
  47253. WC_HASH_TYPE_MD2,
  47254. WC_HASH_TYPE_MD4,
  47255. WC_HASH_TYPE_BLAKE2B,
  47256. WC_HASH_TYPE_BLAKE2S,
  47257. WC_HASH_TYPE_NONE,
  47258. };
  47259. /* dynamically finds the length */
  47260. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47261. /* For loop to test various arguments... */
  47262. for (i = 0; i < enumlen; i++) {
  47263. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47264. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  47265. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47266. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47267. wc_HashFree(&hash, enumArray[i]);
  47268. }
  47269. /* For loop to test not supported cases */
  47270. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47271. for (j = 0; j < notSupportedLen; j++) {
  47272. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47273. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  47274. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47275. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47276. }
  47277. #endif
  47278. return EXPECT_RESULT();
  47279. } /* END test_wc_HashSetFlags */
  47280. /*
  47281. * Unit test function for wc_HashGetFlags()
  47282. */
  47283. static int test_wc_HashGetFlags(void)
  47284. {
  47285. EXPECT_DECLS;
  47286. #ifdef WOLFSSL_HASH_FLAGS
  47287. wc_HashAlg hash;
  47288. word32 flags = 0;
  47289. int i, j;
  47290. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47291. enum wc_HashType enumArray[] = {
  47292. #ifndef NO_MD5
  47293. WC_HASH_TYPE_MD5,
  47294. #endif
  47295. #ifndef NO_SHA
  47296. WC_HASH_TYPE_SHA,
  47297. #endif
  47298. #ifdef WOLFSSL_SHA224
  47299. WC_HASH_TYPE_SHA224,
  47300. #endif
  47301. #ifndef NO_SHA256
  47302. WC_HASH_TYPE_SHA256,
  47303. #endif
  47304. #ifdef WOLFSSL_SHA384
  47305. WC_HASH_TYPE_SHA384,
  47306. #endif
  47307. #ifdef WOLFSSL_SHA512
  47308. WC_HASH_TYPE_SHA512,
  47309. #endif
  47310. #ifdef WOLFSSL_SHA3
  47311. WC_HASH_TYPE_SHA3_224,
  47312. #endif
  47313. };
  47314. enum wc_HashType notSupported[] = {
  47315. WC_HASH_TYPE_MD5_SHA,
  47316. WC_HASH_TYPE_MD2,
  47317. WC_HASH_TYPE_MD4,
  47318. WC_HASH_TYPE_BLAKE2B,
  47319. WC_HASH_TYPE_BLAKE2S,
  47320. WC_HASH_TYPE_NONE,
  47321. };
  47322. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47323. int notSupportedLen;
  47324. /* For loop to test various arguments... */
  47325. for (i = 0; i < enumlen; i++) {
  47326. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47327. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  47328. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47329. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47330. wc_HashFree(&hash, enumArray[i]);
  47331. }
  47332. /* For loop to test not supported cases */
  47333. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47334. for (j = 0; j < notSupportedLen; j++) {
  47335. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47336. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  47337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47338. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47339. }
  47340. #endif
  47341. return EXPECT_RESULT();
  47342. } /* END test_wc_HashGetFlags */
  47343. /*----------------------------------------------------------------------------*
  47344. | Compatibility Tests
  47345. *----------------------------------------------------------------------------*/
  47346. /*----------------------------------------------------------------------------*
  47347. | ASN.1 Tests
  47348. *----------------------------------------------------------------------------*/
  47349. static int test_wolfSSL_ASN1_BIT_STRING(void)
  47350. {
  47351. EXPECT_DECLS;
  47352. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  47353. ASN1_BIT_STRING* str = NULL;
  47354. ASN1_BIT_STRING* str2 = NULL;
  47355. unsigned char* der = NULL;
  47356. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47357. /* Empty data testing. */
  47358. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  47359. ASN1_BIT_STRING_free(str);
  47360. str = NULL;
  47361. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47362. /* Invalid parameter testing. */
  47363. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  47364. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  47365. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  47366. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  47367. /* No bit string - bit is always 0. */
  47368. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  47369. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  47370. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47371. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  47372. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  47373. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  47374. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  47375. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47376. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  47377. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  47378. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  47379. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  47380. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  47381. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  47382. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  47383. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  47384. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  47385. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  47386. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  47387. #ifdef WOLFSSL_ASN_TEMPLATE
  47388. {
  47389. const unsigned char* tmp = der;
  47390. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  47391. }
  47392. #endif
  47393. ASN1_BIT_STRING_free(str);
  47394. ASN1_BIT_STRING_free(str2);
  47395. ASN1_BIT_STRING_free(NULL);
  47396. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  47397. #endif
  47398. return EXPECT_RESULT();
  47399. }
  47400. static int test_wolfSSL_ASN1_INTEGER(void)
  47401. {
  47402. EXPECT_DECLS;
  47403. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47404. ASN1_INTEGER* a = NULL;
  47405. ASN1_INTEGER* dup = NULL;
  47406. const unsigned char invalidLenDer[] = {
  47407. 0x02, 0x20, 0x00
  47408. };
  47409. const unsigned char longDer[] = {
  47410. 0x02, 0x20,
  47411. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47412. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47413. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47414. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  47415. };
  47416. const unsigned char* p;
  47417. /* Invalid parameter testing. */
  47418. ASN1_INTEGER_free(NULL);
  47419. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  47420. ExpectNotNull(a = ASN1_INTEGER_new());
  47421. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47422. ASN1_INTEGER_free(dup);
  47423. dup = NULL;
  47424. ASN1_INTEGER_free(a);
  47425. a = NULL;
  47426. p = longDer;
  47427. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  47428. p = longDer;
  47429. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  47430. ExpectPtrNE(p, longDer);
  47431. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47432. ASN1_INTEGER_free(dup);
  47433. ASN1_INTEGER_free(a);
  47434. #endif
  47435. return EXPECT_RESULT();
  47436. }
  47437. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  47438. {
  47439. EXPECT_DECLS;
  47440. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47441. ASN1_INTEGER* a = NULL;
  47442. ASN1_INTEGER* b = NULL;
  47443. ExpectNotNull(a = ASN1_INTEGER_new());
  47444. ExpectNotNull(b = ASN1_INTEGER_new());
  47445. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  47446. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47447. /* Invalid parameter testing. */
  47448. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  47449. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  47450. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  47451. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47452. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  47453. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47454. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  47455. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47456. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47457. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47458. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  47459. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  47460. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47461. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  47462. ASN1_INTEGER_free(b);
  47463. ASN1_INTEGER_free(a);
  47464. #endif
  47465. return EXPECT_RESULT();
  47466. }
  47467. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  47468. {
  47469. EXPECT_DECLS;
  47470. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47471. ASN1_INTEGER* ai = NULL;
  47472. ASN1_INTEGER* ai2 = NULL;
  47473. BIGNUM* bn = NULL;
  47474. BIGNUM* bn2 = NULL;
  47475. ExpectNotNull(ai = ASN1_INTEGER_new());
  47476. ExpectNotNull(bn2 = BN_new());
  47477. /* Invalid parameter testing. */
  47478. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  47479. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  47480. /* at the moment hard setting since no set function */
  47481. if (ai != NULL) {
  47482. ai->data[0] = 0xff; /* No DER encoding. */
  47483. ai->length = 1;
  47484. }
  47485. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47486. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47487. BN_free(bn);
  47488. bn = NULL;
  47489. #else
  47490. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47491. #endif
  47492. if (ai != NULL) {
  47493. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47494. ai->data[1] = 0x04; /* bad length of integer */
  47495. ai->data[2] = 0x03;
  47496. ai->length = 3;
  47497. }
  47498. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47499. /* Interpreted as a number 0x020403. */
  47500. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47501. BN_free(bn);
  47502. bn = NULL;
  47503. #else
  47504. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47505. #endif
  47506. if (ai != NULL) {
  47507. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47508. ai->data[1] = 0x01; /* length of integer */
  47509. ai->data[2] = 0x03;
  47510. ai->length = 3;
  47511. }
  47512. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47513. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  47514. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47515. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47516. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47517. if (ai != NULL) {
  47518. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47519. ai->data[1] = 0x02; /* length of integer */
  47520. ai->data[2] = 0x00; /* padding byte to ensure positive */
  47521. ai->data[3] = 0xff;
  47522. ai->length = 4;
  47523. }
  47524. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47525. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47526. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47527. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47528. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47529. if (ai != NULL) {
  47530. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47531. ai->data[1] = 0x01; /* length of integer */
  47532. ai->data[2] = 0x00;
  47533. ai->length = 3;
  47534. }
  47535. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47536. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47537. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47538. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47539. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47540. if (ai != NULL) {
  47541. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47542. ai->data[1] = 0x01; /* length of integer */
  47543. ai->data[2] = 0x01;
  47544. ai->length = 3;
  47545. ai->negative = 1;
  47546. }
  47547. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47548. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47549. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47550. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47551. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47552. BN_free(bn2);
  47553. BN_free(bn);
  47554. ASN1_INTEGER_free(ai2);
  47555. ASN1_INTEGER_free(ai);
  47556. #endif
  47557. return EXPECT_RESULT();
  47558. }
  47559. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  47560. {
  47561. EXPECT_DECLS;
  47562. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47563. ASN1_INTEGER *a = NULL;
  47564. long val;
  47565. ExpectNotNull(a = ASN1_INTEGER_new());
  47566. /* Invalid parameter testing. */
  47567. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  47568. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47569. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  47570. #else
  47571. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  47572. #endif
  47573. ASN1_INTEGER_free(a);
  47574. a = NULL;
  47575. ExpectNotNull(a = ASN1_INTEGER_new());
  47576. val = 0;
  47577. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  47578. ASN1_INTEGER_free(a);
  47579. a = NULL;
  47580. /* 0 */
  47581. ExpectNotNull(a = ASN1_INTEGER_new());
  47582. val = 0;
  47583. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47584. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47585. ASN1_INTEGER_free(a);
  47586. a = NULL;
  47587. /* 40 */
  47588. ExpectNotNull(a = ASN1_INTEGER_new());
  47589. val = 40;
  47590. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47591. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47592. ASN1_INTEGER_free(a);
  47593. a = NULL;
  47594. /* -40 */
  47595. ExpectNotNull(a = ASN1_INTEGER_new());
  47596. val = -40;
  47597. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47598. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47599. ASN1_INTEGER_free(a);
  47600. a = NULL;
  47601. /* 128 */
  47602. ExpectNotNull(a = ASN1_INTEGER_new());
  47603. val = 128;
  47604. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47605. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47606. ASN1_INTEGER_free(a);
  47607. a = NULL;
  47608. /* -128 */
  47609. ExpectNotNull(a = ASN1_INTEGER_new());
  47610. val = -128;
  47611. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47612. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47613. ASN1_INTEGER_free(a);
  47614. a = NULL;
  47615. /* 200 */
  47616. ExpectNotNull(a = ASN1_INTEGER_new());
  47617. val = 200;
  47618. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47619. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47620. ASN1_INTEGER_free(a);
  47621. a = NULL;
  47622. /* int max (2147483647) */
  47623. ExpectNotNull(a = ASN1_INTEGER_new());
  47624. val = 2147483647;
  47625. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47626. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47627. ASN1_INTEGER_free(a);
  47628. a = NULL;
  47629. /* int min (-2147483648) */
  47630. ExpectNotNull(a = ASN1_INTEGER_new());
  47631. val = -2147483647 - 1;
  47632. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47633. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47634. ASN1_INTEGER_free(a);
  47635. a = NULL;
  47636. /* long max positive */
  47637. ExpectNotNull(a = ASN1_INTEGER_new());
  47638. val = (long)(((unsigned long)-1) >> 1);
  47639. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47640. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47641. ASN1_INTEGER_free(a);
  47642. #endif
  47643. return EXPECT_RESULT();
  47644. }
  47645. #if defined(OPENSSL_EXTRA)
  47646. typedef struct ASN1IntTestVector {
  47647. const byte* der;
  47648. const size_t derSz;
  47649. const long value;
  47650. } ASN1IntTestVector;
  47651. #endif
  47652. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  47653. {
  47654. EXPECT_DECLS;
  47655. #if defined(OPENSSL_EXTRA)
  47656. size_t i;
  47657. WOLFSSL_ASN1_INTEGER* a = NULL;
  47658. WOLFSSL_ASN1_INTEGER* b = NULL;
  47659. WOLFSSL_ASN1_INTEGER* c = NULL;
  47660. const byte* p = NULL;
  47661. byte* p2 = NULL;
  47662. byte* reEncoded = NULL;
  47663. int reEncodedSz = 0;
  47664. static const byte zeroDer[] = {
  47665. 0x02, 0x01, 0x00
  47666. };
  47667. static const byte oneDer[] = {
  47668. 0x02, 0x01, 0x01
  47669. };
  47670. static const byte negativeDer[] = {
  47671. 0x02, 0x03, 0xC1, 0x16, 0x0D
  47672. };
  47673. static const byte positiveDer[] = {
  47674. 0x02, 0x03, 0x01, 0x00, 0x01
  47675. };
  47676. static const byte primeDer[] = {
  47677. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  47678. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  47679. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  47680. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  47681. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  47682. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  47683. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  47684. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  47685. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  47686. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  47687. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  47688. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  47689. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  47690. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  47691. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  47692. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  47693. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  47694. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  47695. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  47696. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  47697. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  47698. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  47699. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  47700. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  47701. };
  47702. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  47703. static const ASN1IntTestVector testVectors[] = {
  47704. {zeroDer, sizeof(zeroDer), 0},
  47705. {oneDer, sizeof(oneDer), 1},
  47706. {negativeDer, sizeof(negativeDer), -4123123},
  47707. {positiveDer, sizeof(positiveDer), 65537},
  47708. {primeDer, sizeof(primeDer), 0}
  47709. };
  47710. static const size_t NUM_TEST_VECTORS =
  47711. sizeof(testVectors)/sizeof(testVectors[0]);
  47712. /* Check d2i error conditions */
  47713. /* NULL pointer to input. */
  47714. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  47715. ExpectNull(b);
  47716. /* NULL input. */
  47717. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  47718. ExpectNull(b);
  47719. /* 0 length. */
  47720. p = testVectors[0].der;
  47721. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  47722. ExpectNull(b);
  47723. /* Negative length. */
  47724. p = testVectors[0].der;
  47725. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  47726. ExpectNull(b);
  47727. /* Garbage DER input. */
  47728. p = garbageDer;
  47729. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  47730. ExpectNull(b);
  47731. /* Check i2d error conditions */
  47732. /* NULL input. */
  47733. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  47734. /* 0 length input data buffer (a->length == 0). */
  47735. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  47736. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47737. if (a != NULL)
  47738. a->data = NULL;
  47739. /* NULL input data buffer. */
  47740. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47741. if (a != NULL) {
  47742. /* Reset a->data. */
  47743. a->data = a->intData;
  47744. }
  47745. /* Set a to valid value. */
  47746. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  47747. /* NULL output buffer. */
  47748. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  47749. wolfSSL_ASN1_INTEGER_free(a);
  47750. a = NULL;
  47751. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  47752. p = testVectors[i].der;
  47753. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  47754. testVectors[i].derSz));
  47755. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47756. if (testVectors[i].derSz <= sizeof(long)) {
  47757. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  47758. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  47759. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  47760. wolfSSL_ASN1_INTEGER_free(c);
  47761. c = NULL;
  47762. }
  47763. /* Convert to DER without a pre-allocated output buffer. */
  47764. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  47765. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  47766. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  47767. /* Convert to DER with a pre-allocated output buffer. In this case, the
  47768. * output buffer pointer should be incremented just past the end of the
  47769. * encoded data. */
  47770. p2 = reEncoded;
  47771. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  47772. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  47773. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  47774. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  47775. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  47776. reEncoded = NULL;
  47777. wolfSSL_ASN1_INTEGER_free(a);
  47778. a = NULL;
  47779. }
  47780. #endif /* OPENSSL_EXTRA */
  47781. return EXPECT_RESULT();
  47782. }
  47783. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  47784. {
  47785. EXPECT_DECLS;
  47786. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  47787. BIO* bio = NULL;
  47788. BIO* out = NULL;
  47789. BIO* fixed = NULL;
  47790. ASN1_INTEGER* ai = NULL;
  47791. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  47792. char tmp[1024];
  47793. int tmpSz;
  47794. const char expected1[] = "123456";
  47795. const char expected2[] = "112345678912345678901234567890";
  47796. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  47797. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  47798. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  47799. ExpectNotNull(ai = ASN1_INTEGER_new());
  47800. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  47801. /* Invalid parameter testing. */
  47802. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  47803. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  47804. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  47805. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  47806. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  47807. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  47808. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  47809. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  47810. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  47811. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  47812. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  47813. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  47814. /* No data to read from BIO. */
  47815. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  47816. /* read first line */
  47817. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47818. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  47819. XMEMSET(tmp, 0, 1024);
  47820. tmpSz = BIO_read(out, tmp, 1024);
  47821. ExpectIntEQ(tmpSz, 6);
  47822. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  47823. /* fail on second line (not % 2) */
  47824. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  47825. /* read 3rd long line */
  47826. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47827. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  47828. XMEMSET(tmp, 0, 1024);
  47829. tmpSz = BIO_read(out, tmp, 1024);
  47830. ExpectIntEQ(tmpSz, 30);
  47831. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  47832. /* fail on empty line */
  47833. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  47834. BIO_free(bio);
  47835. bio = NULL;
  47836. /* Make long integer, requiring dynamic memory, even longer. */
  47837. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  47838. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47839. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  47840. XMEMSET(tmp, 0, 1024);
  47841. tmpSz = BIO_read(out, tmp, 1024);
  47842. ExpectIntEQ(tmpSz, 48);
  47843. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  47844. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  47845. XMEMSET(tmp, 0, 1024);
  47846. tmpSz = BIO_read(out, tmp, 1024);
  47847. ExpectIntEQ(tmpSz, 56);
  47848. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  47849. BIO_free(bio);
  47850. BIO_free(out);
  47851. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  47852. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  47853. /* Ensure there is 0 bytes available to write into. */
  47854. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  47855. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  47856. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  47857. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  47858. BIO_free(fixed);
  47859. ASN1_INTEGER_free(ai);
  47860. #endif
  47861. return EXPECT_RESULT();
  47862. }
  47863. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  47864. {
  47865. EXPECT_DECLS;
  47866. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47867. ASN1_INTEGER *a = NULL;
  47868. unsigned char *pp = NULL,*tpp = NULL;
  47869. int ret = 0;
  47870. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  47871. /* Invalid parameter testing. */
  47872. /* Set pp to an invalid value. */
  47873. pp = NULL;
  47874. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  47875. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  47876. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  47877. /* 40 */
  47878. if (a != NULL) {
  47879. a->intData[0] = ASN_INTEGER;
  47880. a->intData[1] = 1;
  47881. a->intData[2] = 40;
  47882. }
  47883. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47884. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47885. DYNAMIC_TYPE_TMP_BUFFER));
  47886. tpp = pp;
  47887. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47888. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47889. tpp--;
  47890. ExpectIntEQ(*tpp, 40);
  47891. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47892. pp = NULL;
  47893. /* 128 */
  47894. if (a != NULL) {
  47895. a->intData[0] = ASN_INTEGER;
  47896. a->intData[1] = 1;
  47897. a->intData[2] = 128;
  47898. }
  47899. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47900. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47901. DYNAMIC_TYPE_TMP_BUFFER));
  47902. tpp = pp;
  47903. if (tpp != NULL) {
  47904. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47905. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47906. tpp--;
  47907. ExpectIntEQ(*(tpp--), 128);
  47908. ExpectIntEQ(*tpp, 0);
  47909. }
  47910. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47911. pp = NULL;
  47912. /* -40 */
  47913. if (a != NULL) {
  47914. a->intData[0] = ASN_INTEGER;
  47915. a->intData[1] = 1;
  47916. a->intData[2] = 40;
  47917. a->negative = 1;
  47918. }
  47919. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47920. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47921. DYNAMIC_TYPE_TMP_BUFFER));
  47922. tpp = pp;
  47923. if (tpp != NULL) {
  47924. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47925. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47926. tpp--;
  47927. ExpectIntEQ(*tpp, 216);
  47928. }
  47929. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47930. pp = NULL;
  47931. /* -128 */
  47932. if (a != NULL) {
  47933. a->intData[0] = ASN_INTEGER;
  47934. a->intData[1] = 1;
  47935. a->intData[2] = 128;
  47936. a->negative = 1;
  47937. }
  47938. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47939. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47940. DYNAMIC_TYPE_TMP_BUFFER));
  47941. tpp = pp;
  47942. if (tpp != NULL) {
  47943. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47944. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47945. tpp--;
  47946. ExpectIntEQ(*tpp, 128);
  47947. }
  47948. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47949. pp = NULL;
  47950. /* -200 */
  47951. if (a != NULL) {
  47952. a->intData[0] = ASN_INTEGER;
  47953. a->intData[1] = 1;
  47954. a->intData[2] = 200;
  47955. a->negative = 1;
  47956. }
  47957. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  47958. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47959. DYNAMIC_TYPE_TMP_BUFFER));
  47960. tpp = pp;
  47961. if (tpp != NULL) {
  47962. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47963. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  47964. tpp--;
  47965. ExpectIntEQ(*(tpp--), 56);
  47966. ExpectIntEQ(*tpp, 255);
  47967. }
  47968. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47969. pp = NULL;
  47970. /* Empty */
  47971. if (a != NULL) {
  47972. a->intData[0] = ASN_INTEGER;
  47973. a->intData[1] = 0;
  47974. a->negative = 0;
  47975. }
  47976. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47977. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47978. DYNAMIC_TYPE_TMP_BUFFER));
  47979. tpp = pp;
  47980. if (tpp != NULL) {
  47981. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  47982. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  47983. tpp--;
  47984. ExpectIntEQ(*tpp, 0);
  47985. }
  47986. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  47987. pp = NULL;
  47988. /* 0 */
  47989. if (a != NULL) {
  47990. a->intData[0] = ASN_INTEGER;
  47991. a->intData[1] = 1;
  47992. a->intData[2] = 0;
  47993. a->negative = 1;
  47994. }
  47995. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  47996. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  47997. DYNAMIC_TYPE_TMP_BUFFER));
  47998. if (tpp != NULL) {
  47999. tpp = pp;
  48000. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48001. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48002. tpp--;
  48003. ExpectIntEQ(*tpp, 0);
  48004. }
  48005. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48006. pp = NULL;
  48007. /* 0x100 */
  48008. if (a != NULL) {
  48009. a->intData[0] = ASN_INTEGER;
  48010. a->intData[1] = 2;
  48011. a->intData[2] = 0x01;
  48012. a->intData[3] = 0x00;
  48013. a->negative = 0;
  48014. }
  48015. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48016. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48017. DYNAMIC_TYPE_TMP_BUFFER));
  48018. if (tpp != NULL) {
  48019. tpp = pp;
  48020. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48021. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48022. tpp -= 2;
  48023. ExpectIntEQ(tpp[0], 0x01);
  48024. ExpectIntEQ(tpp[1], 0x00);
  48025. }
  48026. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48027. pp = NULL;
  48028. /* -0x8000 => 0x8000 */
  48029. if (a != NULL) {
  48030. a->intData[0] = ASN_INTEGER;
  48031. a->intData[1] = 2;
  48032. a->intData[2] = 0x80;
  48033. a->intData[3] = 0x00;
  48034. a->negative = 1;
  48035. }
  48036. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48037. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48038. DYNAMIC_TYPE_TMP_BUFFER));
  48039. tpp = pp;
  48040. if (tpp != NULL) {
  48041. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48042. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48043. tpp -= 2;
  48044. ExpectIntEQ(tpp[0], 0x80);
  48045. ExpectIntEQ(tpp[1], 0x00);
  48046. }
  48047. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48048. pp = NULL;
  48049. /* -0x8001 => 0xFF7FFF */
  48050. if (a != NULL) {
  48051. a->intData[0] = ASN_INTEGER;
  48052. a->intData[1] = 2;
  48053. a->intData[2] = 0x80;
  48054. a->intData[3] = 0x01;
  48055. a->negative = 1;
  48056. }
  48057. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  48058. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48059. DYNAMIC_TYPE_TMP_BUFFER));
  48060. tpp = pp;
  48061. if (tpp != NULL) {
  48062. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48063. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  48064. tpp -= 3;
  48065. ExpectIntEQ(tpp[0], 0xFF);
  48066. ExpectIntEQ(tpp[1], 0x7F);
  48067. ExpectIntEQ(tpp[2], 0xFF);
  48068. }
  48069. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48070. wolfSSL_ASN1_INTEGER_free(a);
  48071. #endif /* OPENSSL_EXTRA && !NO_ASN */
  48072. return EXPECT_RESULT();
  48073. }
  48074. static int test_wolfSSL_ASN1_OBJECT(void)
  48075. {
  48076. EXPECT_DECLS;
  48077. #if defined(OPENSSL_EXTRA)
  48078. ASN1_OBJECT* a = NULL;
  48079. ASN1_OBJECT s;
  48080. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  48081. /* Invalid parameter testing. */
  48082. ASN1_OBJECT_free(NULL);
  48083. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  48084. /* Test that a static ASN1_OBJECT can be freed. */
  48085. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48086. ASN1_OBJECT_free(&s);
  48087. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48088. ASN1_OBJECT_free(a);
  48089. a = NULL;
  48090. s.obj = der;
  48091. s.objSz = sizeof(der);
  48092. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48093. ASN1_OBJECT_free(a);
  48094. ASN1_OBJECT_free(&s);
  48095. #endif /* OPENSSL_EXTRA */
  48096. return EXPECT_RESULT();
  48097. }
  48098. static int test_wolfSSL_ASN1_get_object(void)
  48099. {
  48100. EXPECT_DECLS;
  48101. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  48102. const unsigned char* derBuf = cliecc_cert_der_256;
  48103. const unsigned char* nullPtr = NULL;
  48104. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  48105. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  48106. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  48107. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  48108. const unsigned char* p;
  48109. unsigned char objDer[10];
  48110. unsigned char* der;
  48111. unsigned char* derPtr;
  48112. int len = sizeof_cliecc_cert_der_256;
  48113. long asnLen = 0;
  48114. int tag = 0;
  48115. int cls = 0;
  48116. ASN1_OBJECT* a = NULL;
  48117. ASN1_OBJECT s;
  48118. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48119. /* Invalid encoding at length. */
  48120. p = objDerInvalidLen;
  48121. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48122. 0x80);
  48123. p = objDerBadLen;
  48124. /* Error = 0x80, Constructed = 0x20 */
  48125. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48126. 0x80 | 0x20);
  48127. /* Read a couple TLV triplets and make sure they match the expected values
  48128. */
  48129. /* SEQUENCE */
  48130. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  48131. ExpectIntEQ(asnLen, 861);
  48132. ExpectIntEQ(tag, 0x10);
  48133. ExpectIntEQ(cls, 0);
  48134. /* SEQUENCE */
  48135. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48136. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48137. ExpectIntEQ(asnLen, 772);
  48138. ExpectIntEQ(tag, 0x10);
  48139. ExpectIntEQ(cls, 0);
  48140. /* [0] */
  48141. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48142. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48143. ExpectIntEQ(asnLen, 3);
  48144. ExpectIntEQ(tag, 0);
  48145. ExpectIntEQ(cls, 0x80);
  48146. /* INTEGER */
  48147. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48148. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48149. ExpectIntEQ(asnLen, 1);
  48150. ExpectIntEQ(tag, 0x2);
  48151. ExpectIntEQ(cls, 0);
  48152. derBuf += asnLen;
  48153. /* INTEGER */
  48154. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48155. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48156. ExpectIntEQ(asnLen, 20);
  48157. ExpectIntEQ(tag, 0x2);
  48158. ExpectIntEQ(cls, 0);
  48159. derBuf += asnLen;
  48160. /* SEQUENCE */
  48161. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48162. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48163. ExpectIntEQ(asnLen, 10);
  48164. ExpectIntEQ(tag, 0x10);
  48165. ExpectIntEQ(cls, 0);
  48166. /* Found OBJECT_ID. */
  48167. /* Invalid parameter testing. */
  48168. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  48169. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  48170. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  48171. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  48172. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  48173. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  48174. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  48175. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  48176. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  48177. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  48178. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48179. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48180. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  48181. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  48182. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  48183. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  48184. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  48185. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48186. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48187. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  48188. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  48189. /* Invalid encoding at length. */
  48190. p = objDerInvalidLen;
  48191. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  48192. p = objDerBadLen;
  48193. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  48194. p = objDerNotObj;
  48195. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  48196. p = objDerNoData;
  48197. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  48198. /* Create an ASN OBJECT from content */
  48199. p = derBuf + 2;
  48200. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  48201. ASN1_OBJECT_free(a);
  48202. a = NULL;
  48203. /* Create an ASN OBJECT from DER */
  48204. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  48205. /* Invalid parameter testing. */
  48206. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  48207. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  48208. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  48209. der = NULL;
  48210. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  48211. derPtr = objDer;
  48212. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  48213. ExpectPtrNE(derPtr, objDer);
  48214. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  48215. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  48216. ASN1_OBJECT_free(a);
  48217. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  48218. return EXPECT_RESULT();
  48219. }
  48220. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  48221. {
  48222. EXPECT_DECLS;
  48223. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48224. ASN1_OBJECT* obj = NULL;
  48225. ASN1_OBJECT* a = NULL;
  48226. BIO *bio = NULL;
  48227. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  48228. const unsigned char* p;
  48229. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  48230. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  48231. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  48232. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  48233. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  48234. /* No DER encoding in ASN1_OBJECT. */
  48235. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  48236. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  48237. ASN1_OBJECT_free(a);
  48238. a = NULL;
  48239. /* DER encoding */
  48240. p = notObjDer;
  48241. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  48242. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  48243. ASN1_OBJECT_free(a);
  48244. BIO_free(bio);
  48245. ASN1_OBJECT_free(obj);
  48246. #endif
  48247. return EXPECT_RESULT();
  48248. }
  48249. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  48250. {
  48251. EXPECT_DECLS;
  48252. #if defined(OPENSSL_EXTRA) && \
  48253. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  48254. char buf[50] = {0};
  48255. ASN1_OBJECT* obj;
  48256. const char* oid = "2.5.29.19";
  48257. const char* ln = "X509v3 Basic Constraints";
  48258. obj = NULL;
  48259. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  48260. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  48261. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  48262. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  48263. XMEMSET(buf, 0, sizeof(buf));
  48264. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  48265. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  48266. ASN1_OBJECT_free(obj);
  48267. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  48268. return EXPECT_RESULT();
  48269. }
  48270. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  48271. {
  48272. EXPECT_DECLS;
  48273. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  48274. WOLFSSL_STACK* sk = NULL;
  48275. WOLFSSL_ASN1_OBJECT* obj;
  48276. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48277. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48278. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48279. sk = NULL;
  48280. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48281. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  48282. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  48283. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  48284. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48285. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  48286. sk = NULL;
  48287. /* obj freed in pop_free call. */
  48288. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48289. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48290. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48291. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  48292. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48293. wolfSSL_ASN1_OBJECT_free(obj);
  48294. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  48295. return EXPECT_RESULT();
  48296. }
  48297. static int test_wolfSSL_ASN1_STRING(void)
  48298. {
  48299. EXPECT_DECLS;
  48300. #if defined(OPENSSL_EXTRA)
  48301. ASN1_STRING* str = NULL;
  48302. ASN1_STRING* c = NULL;
  48303. const char data[] = "hello wolfSSL";
  48304. const char data2[] = "Same len data";
  48305. const char longData[] =
  48306. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48307. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48308. ASN1_STRING_free(str);
  48309. str = NULL;
  48310. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48311. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  48312. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  48313. /* Check setting to NULL works. */
  48314. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  48315. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  48316. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48317. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  48318. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  48319. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  48320. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  48321. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  48322. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  48323. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  48324. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  48325. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  48326. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  48327. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48328. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  48329. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  48330. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  48331. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  48332. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48333. /* Check setting back to smaller size frees dynamic data. */
  48334. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48335. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  48336. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  48337. ExpectNull(ASN1_STRING_get0_data(NULL));
  48338. ExpectNotNull(ASN1_STRING_get0_data(str));
  48339. ExpectNull(ASN1_STRING_data(NULL));
  48340. ExpectNotNull(ASN1_STRING_data(str));
  48341. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  48342. ExpectIntGT(ASN1_STRING_length(str), 0);
  48343. ASN1_STRING_free(c);
  48344. ASN1_STRING_free(str);
  48345. ASN1_STRING_free(NULL);
  48346. #ifndef NO_WOLFSSL_STUB
  48347. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  48348. #endif
  48349. #endif
  48350. return EXPECT_RESULT();
  48351. }
  48352. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  48353. {
  48354. EXPECT_DECLS;
  48355. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  48356. !defined(NO_FILESYSTEM)
  48357. WOLFSSL_X509* x509 = NULL;
  48358. WOLFSSL_X509_NAME* subject = NULL;
  48359. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  48360. WOLFSSL_ASN1_STRING* a = NULL;
  48361. FILE* file = XBADFILE;
  48362. int idx = 0;
  48363. char targetOutput[16] = "www.wolfssl.com";
  48364. unsigned char* actual_output = NULL;
  48365. int len = 0;
  48366. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  48367. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  48368. if (file != XBADFILE)
  48369. fclose(file);
  48370. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  48371. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  48372. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  48373. NID_commonName, -1)), 5);
  48374. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  48375. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  48376. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  48377. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  48378. a = NULL;
  48379. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  48380. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  48381. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  48382. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  48383. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  48384. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  48385. wolfSSL_X509_free(x509);
  48386. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48387. ExpectNotNull(a = ASN1_STRING_new());
  48388. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  48389. ASN1_STRING_free(a);
  48390. #endif
  48391. return EXPECT_RESULT();
  48392. }
  48393. static int test_wolfSSL_i2s_ASN1_STRING(void)
  48394. {
  48395. EXPECT_DECLS;
  48396. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48397. WOLFSSL_ASN1_STRING* str = NULL;
  48398. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  48399. char* ret = NULL;
  48400. ExpectNotNull(str = ASN1_STRING_new());
  48401. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  48402. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48403. ret = NULL;
  48404. /* No data. */
  48405. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48406. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48407. ret = NULL;
  48408. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  48409. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48410. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48411. ret = NULL;
  48412. ExpectIntEQ(ASN1_STRING_set(str, data, -1), 1);
  48413. /* No type. */
  48414. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48415. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48416. ASN1_STRING_free(str);
  48417. #endif
  48418. return EXPECT_RESULT();
  48419. }
  48420. static int test_wolfSSL_ASN1_STRING_canon(void)
  48421. {
  48422. EXPECT_DECLS;
  48423. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  48424. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  48425. defined(OPENSSL_EXTRA_X509_SMALL))
  48426. WOLFSSL_ASN1_STRING* orig = NULL;
  48427. WOLFSSL_ASN1_STRING* canon = NULL;
  48428. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  48429. const char* whitespaceOnly = "\t\r\n";
  48430. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  48431. const char* canonData = "\x01 \x02 \xff tt";
  48432. const char longData[] =
  48433. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48434. ExpectNotNull(orig = ASN1_STRING_new());
  48435. ExpectNotNull(canon = ASN1_STRING_new());
  48436. /* Invalid parameter testing. */
  48437. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48438. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48439. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48440. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48441. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48442. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  48443. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48444. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48445. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  48446. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48447. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48448. ASN1_STRING_free(orig);
  48449. orig = NULL;
  48450. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48451. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  48452. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48453. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  48454. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48455. ASN1_STRING_free(orig);
  48456. orig = NULL;
  48457. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48458. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  48459. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48460. ASN1_STRING_free(orig);
  48461. orig = NULL;
  48462. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48463. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48464. ASN1_STRING_free(orig);
  48465. ASN1_STRING_free(canon);
  48466. #endif
  48467. #endif
  48468. return EXPECT_RESULT();
  48469. }
  48470. static int test_wolfSSL_ASN1_STRING_print(void)
  48471. {
  48472. EXPECT_DECLS;
  48473. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  48474. !defined(NO_BIO)
  48475. ASN1_STRING* asnStr = NULL;
  48476. const char HELLO_DATA[]= \
  48477. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  48478. #define MAX_UNPRINTABLE_CHAR 32
  48479. #define MAX_BUF 255
  48480. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  48481. unsigned char expected[sizeof(unprintableData)+1];
  48482. unsigned char rbuf[MAX_BUF];
  48483. BIO *bio = NULL;
  48484. int p_len;
  48485. int i;
  48486. /* setup */
  48487. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  48488. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  48489. expected[i] = (unsigned char)HELLO_DATA[i];
  48490. }
  48491. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  48492. unprintableData[sizeof(HELLO_DATA)+i] = i;
  48493. if (i == (int)'\n' || i == (int)'\r')
  48494. expected[sizeof(HELLO_DATA)+i] = i;
  48495. else
  48496. expected[sizeof(HELLO_DATA)+i] = '.';
  48497. }
  48498. unprintableData[sizeof(unprintableData)-1] = '\0';
  48499. expected[sizeof(expected)-1] = '\0';
  48500. XMEMSET(rbuf, 0, MAX_BUF);
  48501. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48502. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  48503. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48504. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  48505. (int)sizeof(unprintableData)), 1);
  48506. /* test */
  48507. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  48508. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  48509. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  48510. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  48511. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  48512. ExpectStrEQ((char*)rbuf, (const char*)expected);
  48513. BIO_free(bio);
  48514. bio = NULL;
  48515. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48516. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48517. /* Ensure there is 0 bytes available to write into. */
  48518. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  48519. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48520. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48521. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48522. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  48523. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48524. BIO_free(bio);
  48525. ASN1_STRING_free(asnStr);
  48526. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  48527. return EXPECT_RESULT();
  48528. }
  48529. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  48530. {
  48531. EXPECT_DECLS;
  48532. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48533. ASN1_STRING* asn_str = NULL;
  48534. const char data[] = "Hello wolfSSL!";
  48535. ASN1_STRING* esc_str = NULL;
  48536. const char esc_data[] = "a+;<>";
  48537. ASN1_STRING* neg_int = NULL;
  48538. const char neg_int_data[] = "\xff";
  48539. ASN1_STRING* neg_enum = NULL;
  48540. const char neg_enum_data[] = "\xff";
  48541. BIO *bio = NULL;
  48542. BIO *fixed = NULL;
  48543. unsigned long flags;
  48544. int p_len;
  48545. unsigned char rbuf[255];
  48546. /* setup */
  48547. XMEMSET(rbuf, 0, 255);
  48548. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48549. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  48550. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48551. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48552. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  48553. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48554. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  48555. sizeof(esc_data)), 1);
  48556. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  48557. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  48558. sizeof(neg_int_data) - 1), 1);
  48559. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  48560. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  48561. sizeof(neg_enum_data) - 1), 1);
  48562. /* Invalid parameter testing. */
  48563. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  48564. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  48565. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  48566. /* no flags */
  48567. XMEMSET(rbuf, 0, 255);
  48568. flags = 0;
  48569. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  48570. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  48571. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  48572. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48573. /* Ensure there is 0 bytes available to write into. */
  48574. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48575. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48576. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48577. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48578. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  48579. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48580. /* RFC2253 Escape */
  48581. XMEMSET(rbuf, 0, 255);
  48582. flags = ASN1_STRFLGS_ESC_2253;
  48583. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  48584. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  48585. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  48586. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48587. /* Ensure there is 0 bytes available to write into. */
  48588. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48589. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48590. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48591. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48592. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  48593. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48594. /* Show type */
  48595. XMEMSET(rbuf, 0, 255);
  48596. flags = ASN1_STRFLGS_SHOW_TYPE;
  48597. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  48598. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  48599. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  48600. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48601. /* Ensure there is 0 bytes available to write into. */
  48602. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48603. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48604. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48605. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48606. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  48607. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48608. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  48609. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48610. /* Dump All */
  48611. XMEMSET(rbuf, 0, 255);
  48612. flags = ASN1_STRFLGS_DUMP_ALL;
  48613. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  48614. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  48615. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  48616. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48617. /* Ensure there is 0 bytes available to write into. */
  48618. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48619. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48620. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48621. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48622. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48623. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48624. /* Dump Der */
  48625. XMEMSET(rbuf, 0, 255);
  48626. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  48627. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  48628. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  48629. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  48630. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48631. /* Ensure there is 0 bytes available to write into. */
  48632. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48633. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48634. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48635. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48636. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  48637. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48638. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48639. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48640. /* Dump All + Show type */
  48641. XMEMSET(rbuf, 0, 255);
  48642. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48643. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  48644. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  48645. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  48646. /* Dump All + Show type - Negative Integer. */
  48647. XMEMSET(rbuf, 0, 255);
  48648. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48649. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  48650. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  48651. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  48652. /* Dump All + Show type - Negative Enumerated. */
  48653. XMEMSET(rbuf, 0, 255);
  48654. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48655. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  48656. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  48657. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  48658. BIO_free(fixed);
  48659. BIO_free(bio);
  48660. ASN1_STRING_free(asn_str);
  48661. ASN1_STRING_free(esc_str);
  48662. ASN1_STRING_free(neg_int);
  48663. ASN1_STRING_free(neg_enum);
  48664. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  48665. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  48666. #endif
  48667. return EXPECT_RESULT();
  48668. }
  48669. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  48670. {
  48671. EXPECT_DECLS;
  48672. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  48673. ASN1_STRING* asn1str_test = NULL;
  48674. ASN1_STRING* asn1str_answer = NULL;
  48675. /* Each character is encoded using 4 bytes */
  48676. char input[] = {
  48677. 0, 0, 0, 'T',
  48678. 0, 0, 0, 'e',
  48679. 0, 0, 0, 's',
  48680. 0, 0, 0, 't',
  48681. };
  48682. char output[] = "Test";
  48683. char badInput[] = {
  48684. 1, 0, 0, 'T',
  48685. 0, 1, 0, 'e',
  48686. 0, 0, 1, 's',
  48687. };
  48688. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  48689. /* Test wrong type. */
  48690. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48691. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48692. ASN1_STRING_free(asn1str_test);
  48693. asn1str_test = NULL;
  48694. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  48695. /* Test bad length. */
  48696. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  48697. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48698. /* Test bad input. */
  48699. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  48700. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48701. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  48702. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48703. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  48704. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48705. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  48706. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  48707. ExpectNotNull(
  48708. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48709. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  48710. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  48711. ASN1_STRING_free(asn1str_test);
  48712. ASN1_STRING_free(asn1str_answer);
  48713. #endif /* OPENSSL_ALL && !NO_ASN */
  48714. return EXPECT_RESULT();
  48715. }
  48716. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  48717. {
  48718. EXPECT_DECLS;
  48719. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48720. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  48721. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  48722. if (asn1_gtime != NULL)
  48723. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  48724. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  48725. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  48726. return EXPECT_RESULT();
  48727. }
  48728. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  48729. {
  48730. EXPECT_DECLS;
  48731. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  48732. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  48733. BIO* bio = NULL;
  48734. unsigned char buf[24];
  48735. int i;
  48736. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48737. BIO_set_write_buf_size(bio, 24);
  48738. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  48739. /* Type not set. */
  48740. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48741. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  48742. /* Invalid parameters testing. */
  48743. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48744. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48745. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48746. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  48747. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  48748. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  48749. BIO_free(bio);
  48750. bio = NULL;
  48751. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48752. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48753. /* Ensure there is 0 bytes available to write into. */
  48754. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  48755. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48756. for (i = 1; i < 20; i++) {
  48757. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  48758. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48759. }
  48760. BIO_free(bio);
  48761. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  48762. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  48763. return EXPECT_RESULT();
  48764. }
  48765. static int test_wolfSSL_ASN1_TIME(void)
  48766. {
  48767. EXPECT_DECLS;
  48768. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48769. WOLFSSL_ASN1_TIME* asn_time = NULL;
  48770. unsigned char *data;
  48771. ExpectNotNull(asn_time = ASN1_TIME_new());
  48772. #ifndef NO_WOLFSSL_STUB
  48773. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  48774. #endif
  48775. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  48776. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  48777. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  48778. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  48779. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  48780. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  48781. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  48782. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  48783. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  48784. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  48785. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  48786. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  48787. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  48788. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  48789. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  48790. ASN1_TIME_free(asn_time);
  48791. ASN1_TIME_free(NULL);
  48792. #endif
  48793. return EXPECT_RESULT();
  48794. }
  48795. static int test_wolfSSL_ASN1_TIME_to_string(void)
  48796. {
  48797. EXPECT_DECLS;
  48798. #ifndef NO_ASN_TIME
  48799. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  48800. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  48801. WOLFSSL_ASN1_TIME* t = NULL;
  48802. char buf[ASN_GENERALIZED_TIME_SIZE];
  48803. ExpectNotNull((t = ASN1_TIME_new()));
  48804. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  48805. /* Invalid parameter testing. */
  48806. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  48807. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  48808. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  48809. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  48810. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  48811. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  48812. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  48813. /* Buffer needs to be longer than minimum of 5 characters. */
  48814. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  48815. ASN1_TIME_free(t);
  48816. #endif
  48817. #endif /* NO_ASN_TIME */
  48818. return EXPECT_RESULT();
  48819. }
  48820. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  48821. {
  48822. EXPECT_DECLS;
  48823. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48824. ASN1_TIME* fromTime = NULL;
  48825. ASN1_TIME* closeToTime = NULL;
  48826. ASN1_TIME* toTime = NULL;
  48827. ASN1_TIME* invalidTime = NULL;
  48828. int daysDiff = 0;
  48829. int secsDiff = 0;
  48830. ExpectNotNull((fromTime = ASN1_TIME_new()));
  48831. /* Feb 22, 2003, 21:15:15 */
  48832. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  48833. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  48834. /* Feb 22, 2003, 21:16:15 */
  48835. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  48836. ExpectNotNull((toTime = ASN1_TIME_new()));
  48837. /* Dec 19, 2010, 18:10:11 */
  48838. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  48839. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  48840. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  48841. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  48842. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  48843. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  48844. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48845. /* Error conditions. */
  48846. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  48847. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  48848. /* If both times are NULL, difference is 0. */
  48849. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  48850. ExpectIntEQ(daysDiff, 0);
  48851. ExpectIntEQ(secsDiff, 0);
  48852. /* If one time is NULL, it defaults to the current time. */
  48853. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  48854. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  48855. /* Normal operation. Both times non-NULL. */
  48856. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48857. ExpectIntEQ(daysDiff, 2856);
  48858. ExpectIntEQ(secsDiff, 75296);
  48859. /* Swapping the times should return negative values. */
  48860. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  48861. ExpectIntEQ(daysDiff, -2856);
  48862. ExpectIntEQ(secsDiff, -75296);
  48863. /* Compare with invalid time string. */
  48864. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  48865. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  48866. /* Compare with days difference of 0. */
  48867. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  48868. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  48869. /* Days and seconds differences not 0. */
  48870. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  48871. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  48872. /* Same time. */
  48873. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  48874. /* Compare regression test: No seconds difference, just difference in days.
  48875. */
  48876. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  48877. ASN1_TIME_set_string(toTime, "19800101000000Z");
  48878. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  48879. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  48880. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  48881. /* Edge case with Unix epoch. */
  48882. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  48883. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  48884. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48885. ExpectIntEQ(daysDiff, 3652);
  48886. ExpectIntEQ(secsDiff, 0);
  48887. /* Edge case with year > 2038 (year 2038 problem). */
  48888. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  48889. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  48890. ExpectIntEQ(daysDiff, 2932896);
  48891. ExpectIntEQ(secsDiff, 86399);
  48892. ASN1_TIME_free(fromTime);
  48893. ASN1_TIME_free(closeToTime);
  48894. ASN1_TIME_free(toTime);
  48895. ASN1_TIME_free(invalidTime);
  48896. #endif
  48897. return EXPECT_RESULT();
  48898. }
  48899. static int test_wolfSSL_ASN1_TIME_adj(void)
  48900. {
  48901. EXPECT_DECLS;
  48902. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  48903. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  48904. const int year = 365*24*60*60;
  48905. const int day = 24*60*60;
  48906. const int hour = 60*60;
  48907. const int mini = 60;
  48908. const byte asn_utc_time = ASN_UTC_TIME;
  48909. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  48910. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  48911. #endif
  48912. WOLFSSL_ASN1_TIME* asn_time = NULL;
  48913. WOLFSSL_ASN1_TIME* s = NULL;
  48914. int offset_day;
  48915. long offset_sec;
  48916. char date_str[CTC_DATE_SIZE + 1];
  48917. time_t t;
  48918. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  48919. /* UTC notation test */
  48920. /* 2000/2/15 20:30:00 */
  48921. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  48922. offset_day = 7;
  48923. offset_sec = 45 * mini;
  48924. /* offset_sec = -45 * min;*/
  48925. ExpectNotNull(asn_time =
  48926. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  48927. ExpectTrue(asn_time->type == asn_utc_time);
  48928. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48929. CTC_DATE_SIZE));
  48930. date_str[CTC_DATE_SIZE] = '\0';
  48931. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  48932. /* negative offset */
  48933. offset_sec = -45 * mini;
  48934. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  48935. ExpectNotNull(asn_time);
  48936. ExpectTrue(asn_time->type == asn_utc_time);
  48937. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48938. CTC_DATE_SIZE));
  48939. date_str[CTC_DATE_SIZE] = '\0';
  48940. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  48941. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  48942. s = NULL;
  48943. XMEMSET(date_str, 0, sizeof(date_str));
  48944. /* Generalized time will overflow time_t if not long */
  48945. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  48946. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  48947. DYNAMIC_TYPE_OPENSSL);
  48948. /* GeneralizedTime notation test */
  48949. /* 2055/03/01 09:00:00 */
  48950. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  48951. offset_day = 12;
  48952. offset_sec = 10 * mini;
  48953. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  48954. offset_sec));
  48955. ExpectTrue(asn_time->type == asn_gen_time);
  48956. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48957. CTC_DATE_SIZE));
  48958. date_str[CTC_DATE_SIZE] = '\0';
  48959. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  48960. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  48961. s = NULL;
  48962. XMEMSET(date_str, 0, sizeof(date_str));
  48963. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  48964. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  48965. s = NULL;
  48966. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  48967. offset_day = 7;
  48968. offset_sec = 45 * mini;
  48969. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  48970. offset_sec));
  48971. ExpectTrue(asn_time->type == asn_utc_time);
  48972. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48973. CTC_DATE_SIZE));
  48974. date_str[CTC_DATE_SIZE] = '\0';
  48975. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  48976. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  48977. asn_time = NULL;
  48978. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  48979. offset_sec));
  48980. ExpectTrue(asn_time->type == asn_utc_time);
  48981. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  48982. CTC_DATE_SIZE));
  48983. date_str[CTC_DATE_SIZE] = '\0';
  48984. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  48985. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  48986. #endif
  48987. return EXPECT_RESULT();
  48988. }
  48989. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  48990. {
  48991. EXPECT_DECLS;
  48992. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  48993. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  48994. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  48995. ASN1_TIME asnTime;
  48996. struct tm tm;
  48997. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  48998. XMEMSET(&tm, 0, sizeof(struct tm));
  48999. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49000. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  49001. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  49002. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49003. ExpectIntEQ(tm.tm_sec, 15);
  49004. ExpectIntEQ(tm.tm_min, 15);
  49005. ExpectIntEQ(tm.tm_hour, 21);
  49006. ExpectIntEQ(tm.tm_mday, 22);
  49007. ExpectIntEQ(tm.tm_mon, 1);
  49008. ExpectIntEQ(tm.tm_year, 100);
  49009. ExpectIntEQ(tm.tm_isdst, 0);
  49010. #ifdef XMKTIME
  49011. ExpectIntEQ(tm.tm_wday, 2);
  49012. ExpectIntEQ(tm.tm_yday, 52);
  49013. #endif
  49014. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  49015. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49016. ExpectIntEQ(tm.tm_year, 50);
  49017. /* Get current time. */
  49018. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  49019. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  49020. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49021. /* 0 length. */
  49022. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49023. /* No type. */
  49024. asnTime.length = 1;
  49025. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49026. /* Not UTCTIME length. */
  49027. asnTime.type = V_ASN1_UTCTIME;
  49028. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49029. /* Not GENERALIZEDTIME length. */
  49030. asnTime.type = V_ASN1_GENERALIZEDTIME;
  49031. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49032. /* Not Zulu timezone. */
  49033. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  49034. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49035. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  49036. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49037. #ifdef XMKTIME
  49038. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  49039. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49040. ExpectIntEQ(tm.tm_sec, 47);
  49041. ExpectIntEQ(tm.tm_min, 22);
  49042. ExpectIntEQ(tm.tm_hour, 21);
  49043. ExpectIntEQ(tm.tm_mday, 12);
  49044. ExpectIntEQ(tm.tm_mon, 4);
  49045. ExpectIntEQ(tm.tm_year, 123);
  49046. ExpectIntEQ(tm.tm_wday, 5);
  49047. ExpectIntEQ(tm.tm_yday, 131);
  49048. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  49049. fields are zeroed out as expected. */
  49050. ExpectIntEQ(tm.tm_isdst, 0);
  49051. #endif
  49052. #endif
  49053. return EXPECT_RESULT();
  49054. }
  49055. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  49056. {
  49057. EXPECT_DECLS;
  49058. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49059. WOLFSSL_ASN1_TIME *t = NULL;
  49060. WOLFSSL_ASN1_TIME *out = NULL;
  49061. WOLFSSL_ASN1_TIME *gtime = NULL;
  49062. int tlen = 0;
  49063. unsigned char *data = NULL;
  49064. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49065. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  49066. /* type not set. */
  49067. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49068. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49069. t = NULL;
  49070. /* UTC Time test */
  49071. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49072. if (t != NULL) {
  49073. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  49074. t->type = ASN_UTC_TIME;
  49075. t->length = ASN_UTC_TIME_SIZE;
  49076. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49077. }
  49078. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  49079. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  49080. out = NULL;
  49081. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49082. wolfSSL_ASN1_TIME_free(gtime);
  49083. gtime = NULL;
  49084. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  49085. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49086. ExpectPtrEq(gtime, out);
  49087. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49088. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49089. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49090. /* Generalized Time test */
  49091. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49092. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49093. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49094. if (t != NULL) {
  49095. t->type = ASN_GENERALIZED_TIME;
  49096. t->length = ASN_GENERALIZED_TIME_SIZE;
  49097. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  49098. }
  49099. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  49100. ASN_GENERALIZED_TIME_SIZE);
  49101. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  49102. "20050727123456Z");
  49103. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49104. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49105. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49106. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49107. /* UTC Time to Generalized Time 1900's test */
  49108. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49109. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49110. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49111. if (t != NULL) {
  49112. t->type = ASN_UTC_TIME;
  49113. t->length = ASN_UTC_TIME_SIZE;
  49114. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  49115. }
  49116. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49117. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49118. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49119. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  49120. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49121. /* Null parameter test */
  49122. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49123. gtime = NULL;
  49124. out = NULL;
  49125. if (t != NULL) {
  49126. t->type = ASN_UTC_TIME;
  49127. t->length = ASN_UTC_TIME_SIZE;
  49128. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49129. }
  49130. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  49131. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49132. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49133. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49134. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49135. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49136. #endif
  49137. return EXPECT_RESULT();
  49138. }
  49139. static int test_wolfSSL_ASN1_TIME_print(void)
  49140. {
  49141. EXPECT_DECLS;
  49142. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  49143. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49144. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  49145. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  49146. !defined(NO_ASN_TIME)
  49147. BIO* bio = NULL;
  49148. BIO* fixed = NULL;
  49149. X509* x509 = NULL;
  49150. const unsigned char* der = client_cert_der_2048;
  49151. ASN1_TIME* notAfter = NULL;
  49152. ASN1_TIME* notBefore = NULL;
  49153. unsigned char buf[25];
  49154. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49155. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49156. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  49157. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  49158. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  49159. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  49160. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  49161. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  49162. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  49163. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49164. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  49165. /* Test BIO_write fails. */
  49166. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49167. /* Ensure there is 0 bytes available to write into. */
  49168. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  49169. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49170. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49171. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49172. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  49173. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49174. /* create a bad time and test results */
  49175. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  49176. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  49177. if (EXPECT_SUCCESS()) {
  49178. notAfter->data[8] = 0;
  49179. notAfter->data[3] = 0;
  49180. }
  49181. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  49182. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49183. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49184. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  49185. BIO_free(bio);
  49186. BIO_free(fixed);
  49187. X509_free(x509);
  49188. #endif
  49189. return EXPECT_RESULT();
  49190. }
  49191. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  49192. {
  49193. EXPECT_DECLS;
  49194. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  49195. BIO* bio = NULL;
  49196. ASN1_UTCTIME* utc = NULL;
  49197. unsigned char buf[25];
  49198. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  49199. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  49200. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  49201. /* Valid date */
  49202. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49203. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  49204. DYNAMIC_TYPE_ASN1));
  49205. if (utc != NULL) {
  49206. utc->type = ASN_UTC_TIME;
  49207. utc->length = ASN_UTC_TIME_SIZE;
  49208. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  49209. }
  49210. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  49211. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  49212. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  49213. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  49214. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49215. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  49216. XMEMSET(buf, 0, sizeof(buf));
  49217. BIO_free(bio);
  49218. bio = NULL;
  49219. /* Invalid format */
  49220. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49221. if (utc != NULL) {
  49222. utc->type = ASN_UTC_TIME;
  49223. utc->length = ASN_UTC_TIME_SIZE;
  49224. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  49225. }
  49226. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49227. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49228. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49229. /* Invalid type */
  49230. if (utc != NULL) {
  49231. utc->type = ASN_GENERALIZED_TIME;
  49232. utc->length = ASN_GENERALIZED_TIME_SIZE;
  49233. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  49234. }
  49235. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49236. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  49237. BIO_free(bio);
  49238. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49239. return EXPECT_RESULT();
  49240. }
  49241. static int test_wolfSSL_ASN1_TYPE(void)
  49242. {
  49243. EXPECT_DECLS;
  49244. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  49245. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  49246. WOLFSSL_ASN1_TYPE* t = NULL;
  49247. WOLFSSL_ASN1_OBJECT* obj = NULL;
  49248. #ifndef NO_ASN_TIME
  49249. WOLFSSL_ASN1_TIME* time = NULL;
  49250. #endif
  49251. WOLFSSL_ASN1_STRING* str = NULL;
  49252. unsigned char data[] = { 0x00 };
  49253. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  49254. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49255. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  49256. wolfSSL_ASN1_TYPE_free(t);
  49257. t = NULL;
  49258. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49259. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  49260. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  49261. wolfSSL_ASN1_TYPE_free(t);
  49262. t = NULL;
  49263. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49264. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49265. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  49266. wolfSSL_ASN1_TYPE_free(t);
  49267. t = NULL;
  49268. #ifndef NO_ASN_TIME
  49269. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49270. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49271. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  49272. wolfSSL_ASN1_TYPE_free(t);
  49273. t = NULL;
  49274. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49275. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49276. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  49277. wolfSSL_ASN1_TYPE_free(t);
  49278. t = NULL;
  49279. #endif
  49280. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49281. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49282. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  49283. wolfSSL_ASN1_TYPE_free(t);
  49284. t = NULL;
  49285. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49286. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49287. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  49288. wolfSSL_ASN1_TYPE_free(t);
  49289. t = NULL;
  49290. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49291. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49292. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  49293. wolfSSL_ASN1_TYPE_free(t);
  49294. t = NULL;
  49295. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49296. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49297. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  49298. wolfSSL_ASN1_TYPE_free(t);
  49299. t = NULL;
  49300. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49301. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49302. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  49303. wolfSSL_ASN1_TYPE_free(t);
  49304. t = NULL;
  49305. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49306. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49307. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  49308. wolfSSL_ASN1_TYPE_free(t);
  49309. t = NULL;
  49310. #endif
  49311. return EXPECT_RESULT();
  49312. }
  49313. /* Testing code used in old dpp.c in hostap */
  49314. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49315. typedef struct {
  49316. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  49317. * as an OID identifying the curve */
  49318. X509_ALGOR *alg;
  49319. /* Compressed format public key per ANSI X9.63 */
  49320. ASN1_BIT_STRING *pub_key;
  49321. } DPP_BOOTSTRAPPING_KEY;
  49322. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  49323. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  49324. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  49325. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  49326. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  49327. typedef struct {
  49328. int type;
  49329. union {
  49330. ASN1_BIT_STRING *str1;
  49331. ASN1_BIT_STRING *str2;
  49332. ASN1_BIT_STRING *str3;
  49333. } d;
  49334. } ASN1_CHOICE_TEST;
  49335. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  49336. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  49337. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  49338. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  49339. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  49340. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  49341. /* Test nested objects */
  49342. typedef struct {
  49343. DPP_BOOTSTRAPPING_KEY* key;
  49344. ASN1_INTEGER* asnNum;
  49345. ASN1_INTEGER* expNum;
  49346. STACK_OF(ASN1_GENERALSTRING) *strList;
  49347. ASN1_CHOICE_TEST* str;
  49348. } TEST_ASN1_NEST1;
  49349. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  49350. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  49351. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  49352. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  49353. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  49354. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  49355. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  49356. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  49357. typedef struct {
  49358. ASN1_INTEGER* num;
  49359. DPP_BOOTSTRAPPING_KEY* key;
  49360. TEST_ASN1_NEST1* asn1_obj;
  49361. } TEST_ASN1_NEST2;
  49362. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  49363. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  49364. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  49365. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  49366. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  49367. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  49368. /* End nested objects */
  49369. typedef struct {
  49370. ASN1_INTEGER *integer;
  49371. } TEST_ASN1;
  49372. ASN1_SEQUENCE(TEST_ASN1) = {
  49373. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  49374. } ASN1_SEQUENCE_END(TEST_ASN1)
  49375. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  49376. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  49377. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  49378. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  49379. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  49380. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  49381. #endif
  49382. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  49383. {
  49384. EXPECT_DECLS;
  49385. /* Testing code used in dpp.c in hostap */
  49386. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49387. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  49388. EC_KEY *eckey = NULL;
  49389. EVP_PKEY *key = NULL;
  49390. size_t len = 0;
  49391. unsigned char *der = NULL;
  49392. unsigned char *der2 = NULL;
  49393. const unsigned char *tmp = NULL;
  49394. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  49395. const unsigned char *in = ecc_clikey_der_256;
  49396. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  49397. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  49398. const EC_GROUP *group = NULL;
  49399. const EC_POINT *point = NULL;
  49400. int nid;
  49401. TEST_ASN1 *test_asn1 = NULL;
  49402. TEST_ASN1 *test_asn1_2 = NULL;
  49403. const unsigned char badObjDer[] = { 0x06, 0x00 };
  49404. const unsigned char goodObjDer[] = {
  49405. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  49406. };
  49407. WOLFSSL_ASN1_ITEM emptyTemplate;
  49408. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  49409. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49410. der = NULL;
  49411. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  49412. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  49413. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49414. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  49415. (long)sizeof_ecc_clikey_der_256));
  49416. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  49417. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  49418. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  49419. nid = EC_GROUP_get_curve_name(group);
  49420. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49421. group_obj = OBJ_nid2obj(nid);
  49422. if ((ec_obj != NULL) && (group_obj != NULL)) {
  49423. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  49424. group_obj), 1);
  49425. if (EXPECT_SUCCESS()) {
  49426. ec_obj = NULL;
  49427. group_obj = NULL;
  49428. }
  49429. }
  49430. wolfSSL_ASN1_OBJECT_free(group_obj);
  49431. wolfSSL_ASN1_OBJECT_free(ec_obj);
  49432. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  49433. #ifdef HAVE_COMP_KEY
  49434. ExpectIntGT((len = EC_POINT_point2oct(
  49435. group, point, POINT_CONVERSION_COMPRESSED,
  49436. NULL, 0, NULL)), 0);
  49437. #else
  49438. ExpectIntGT((len = EC_POINT_point2oct(
  49439. group, point, POINT_CONVERSION_UNCOMPRESSED,
  49440. NULL, 0, NULL)), 0);
  49441. #endif
  49442. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  49443. #ifdef HAVE_COMP_KEY
  49444. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49445. der, len-1, NULL), 0);
  49446. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49447. der, len, NULL), len);
  49448. #else
  49449. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49450. der, len-1, NULL), 0);
  49451. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49452. der, len, NULL), len);
  49453. #endif
  49454. if (EXPECT_SUCCESS()) {
  49455. bootstrap->pub_key->data = der;
  49456. bootstrap->pub_key->length = (int)len;
  49457. /* Not actually used */
  49458. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49459. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49460. }
  49461. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  49462. der = NULL;
  49463. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  49464. der2 = NULL;
  49465. #ifdef WOLFSSL_ASN_TEMPLATE
  49466. tmp = der;
  49467. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  49468. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  49469. ExpectBufEQ(der, der2, 49);
  49470. #endif
  49471. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49472. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49473. EVP_PKEY_free(key);
  49474. EC_KEY_free(eckey);
  49475. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49476. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  49477. bootstrap = NULL;
  49478. DPP_BOOTSTRAPPING_KEY_free(NULL);
  49479. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  49480. * a NULL and an empty BIT_STRING. */
  49481. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49482. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  49483. if (EXPECT_SUCCESS()) {
  49484. bootstrap->alg->algorithm->obj = badObjDer;
  49485. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  49486. }
  49487. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  49488. if (EXPECT_SUCCESS()) {
  49489. bootstrap->alg->parameter->type = V_ASN1_NULL;
  49490. bootstrap->alg->parameter->value.ptr = NULL;
  49491. bootstrap->pub_key->data = NULL;
  49492. bootstrap->pub_key->length = 0;
  49493. /* Not actually used */
  49494. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49495. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49496. }
  49497. /* Encode with bad OBJECT_ID. */
  49498. der = NULL;
  49499. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49500. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  49501. if (EXPECT_SUCCESS()) {
  49502. bootstrap->alg->algorithm->obj = goodObjDer;
  49503. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  49504. bootstrap->alg->algorithm->grp = 2;
  49505. }
  49506. der = NULL;
  49507. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  49508. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  49509. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49510. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49511. /* Test integer */
  49512. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  49513. der = NULL;
  49514. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  49515. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  49516. tmp = der;
  49517. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  49518. der2 = NULL;
  49519. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  49520. ExpectBufEQ(der, der2, 5);
  49521. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49522. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49523. TEST_ASN1_free(test_asn1);
  49524. TEST_ASN1_free(test_asn1_2);
  49525. /* Test integer cases. */
  49526. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  49527. TEST_ASN1_free(NULL);
  49528. /* Test nested asn1 objects */
  49529. {
  49530. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  49531. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  49532. int i;
  49533. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  49534. /* Populate nested_asn1 with some random data */
  49535. /* nested_asn1->num */
  49536. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  49537. /* nested_asn1->key */
  49538. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49539. group_obj = OBJ_nid2obj(NID_secp256k1);
  49540. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  49541. V_ASN1_OBJECT, group_obj), 1);
  49542. ec_obj = NULL;
  49543. group_obj = NULL;
  49544. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  49545. 1);
  49546. /* nested_asn1->asn1_obj->key */
  49547. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49548. group_obj = OBJ_nid2obj(NID_secp256k1);
  49549. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  49550. V_ASN1_OBJECT, group_obj), 1);
  49551. ec_obj = NULL;
  49552. group_obj = NULL;
  49553. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  49554. 500, 1), 1);
  49555. /* nested_asn1->asn1_obj->asnNum */
  49556. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  49557. /* nested_asn1->asn1_obj->expNum */
  49558. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  49559. /* nested_asn1->asn1_obj->strList */
  49560. for (i = 10; i >= 0; i--) {
  49561. ASN1_GENERALSTRING* genStr;
  49562. char fmtStr[20];
  49563. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  49564. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  49565. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  49566. ExpectIntGT(
  49567. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  49568. genStr), 0);
  49569. }
  49570. /* nested_asn1->asn1_obj->str */
  49571. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  49572. = ASN1_BIT_STRING_new());
  49573. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  49574. 150, 1), 1);
  49575. nested_asn1->asn1_obj->str->type = 2;
  49576. der = NULL;
  49577. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  49578. #ifdef WOLFSSL_ASN_TEMPLATE
  49579. tmp = der;
  49580. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  49581. der2 = NULL;
  49582. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  49583. ExpectBufEQ(der, der2, 285);
  49584. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49585. #endif
  49586. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49587. TEST_ASN1_NEST2_free(nested_asn1);
  49588. TEST_ASN1_NEST2_free(nested_asn1_2);
  49589. }
  49590. /* Test ASN1_ITEM_TEMPLATE */
  49591. {
  49592. TEST_ASN1_ITEM* asn1_item = NULL;
  49593. TEST_ASN1_ITEM* asn1_item2 = NULL;
  49594. int i;
  49595. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  49596. for (i = 0; i < 11; i++) {
  49597. ASN1_INTEGER* asn1_num;
  49598. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  49599. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  49600. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  49601. }
  49602. der = NULL;
  49603. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  49604. tmp = der;
  49605. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  49606. der2 = NULL;
  49607. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  49608. ExpectBufEQ(der, der2, 35);
  49609. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49610. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49611. TEST_ASN1_ITEM_free(asn1_item);
  49612. TEST_ASN1_ITEM_free(asn1_item2);
  49613. }
  49614. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  49615. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49616. return EXPECT_RESULT();
  49617. }
  49618. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  49619. {
  49620. EXPECT_DECLS;
  49621. #if defined(OPENSSL_EXTRA)
  49622. /* Taken from one of sssd's certs othernames */
  49623. unsigned char str_bin[] = {
  49624. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49625. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49626. };
  49627. ASN1_TYPE* asn1type = NULL;
  49628. unsigned char* der = NULL;
  49629. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  49630. {
  49631. ASN1_STRING* str = NULL;
  49632. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49633. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49634. ExpectNotNull(asn1type = ASN1_TYPE_new());
  49635. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  49636. }
  49637. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  49638. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  49639. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  49640. ASN1_TYPE_free(asn1type);
  49641. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49642. #endif
  49643. return EXPECT_RESULT();
  49644. }
  49645. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  49646. {
  49647. EXPECT_DECLS;
  49648. #if defined(OPENSSL_EXTRA)
  49649. /* Taken from one of sssd's certs othernames */
  49650. unsigned char str_bin[] = {
  49651. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49652. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49653. };
  49654. ASN1_STRING* str = NULL;
  49655. unsigned char* der = NULL;
  49656. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49657. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49658. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  49659. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  49660. ASN1_STRING_free(str);
  49661. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49662. #endif
  49663. return EXPECT_RESULT();
  49664. }
  49665. static int test_ASN1_strings(void)
  49666. {
  49667. EXPECT_DECLS;
  49668. #if defined(OPENSSL_EXTRA)
  49669. char text[] = "\0\0test string";
  49670. unsigned char* der = NULL;
  49671. ASN1_STRING* str = NULL;
  49672. /* Set the length byte */
  49673. text[1] = XSTRLEN(text + 2);
  49674. /* GENERALSTRING */
  49675. {
  49676. const unsigned char* p = (const unsigned char*)text;
  49677. text[0] = ASN_GENERALSTRING;
  49678. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  49679. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  49680. ASN1_STRING_free(str);
  49681. str = NULL;
  49682. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49683. der = NULL;
  49684. }
  49685. /* OCTET_STRING */
  49686. {
  49687. const unsigned char* p = (const unsigned char*)text;
  49688. text[0] = ASN_OCTET_STRING;
  49689. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  49690. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  49691. ASN1_STRING_free(str);
  49692. str = NULL;
  49693. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49694. der = NULL;
  49695. }
  49696. /* UTF8STRING */
  49697. {
  49698. const unsigned char* p = (const unsigned char*)text;
  49699. text[0] = ASN_UTF8STRING;
  49700. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  49701. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  49702. ASN1_STRING_free(str);
  49703. str = NULL;
  49704. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49705. der = NULL;
  49706. }
  49707. #endif
  49708. return EXPECT_RESULT();
  49709. }
  49710. static int test_wolfSSL_lhash(void)
  49711. {
  49712. EXPECT_DECLS;
  49713. #ifdef OPENSSL_ALL
  49714. const char testStr[] = "Like a true nature's child\n"
  49715. "We were born\n"
  49716. "Born to be wild";
  49717. #ifdef NO_SHA
  49718. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  49719. #else
  49720. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  49721. #endif
  49722. #endif
  49723. return EXPECT_RESULT();
  49724. }
  49725. static int test_wolfSSL_X509_NAME(void)
  49726. {
  49727. EXPECT_DECLS;
  49728. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  49729. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  49730. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  49731. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  49732. defined(OPENSSL_EXTRA))
  49733. X509* x509 = NULL;
  49734. const unsigned char* c = NULL;
  49735. unsigned char buf[4096];
  49736. int bytes = 0;
  49737. XFILE f = XBADFILE;
  49738. const X509_NAME* a = NULL;
  49739. const X509_NAME* b = NULL;
  49740. X509_NAME* d2i_name = NULL;
  49741. int sz = 0;
  49742. unsigned char* tmp = NULL;
  49743. char file[] = "./certs/ca-cert.der";
  49744. #ifndef OPENSSL_EXTRA_X509_SMALL
  49745. byte empty[] = { /* CN=empty emailAddress= */
  49746. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  49747. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  49748. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  49749. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  49750. 0x01, 0x16, 0x00
  49751. };
  49752. #endif
  49753. #ifndef OPENSSL_EXTRA_X509_SMALL
  49754. /* test compile of deprecated function, returns 0 */
  49755. ExpectIntEQ(CRYPTO_thread_id(), 0);
  49756. #endif
  49757. ExpectNotNull(a = X509_NAME_new());
  49758. X509_NAME_free((X509_NAME*)a);
  49759. a = NULL;
  49760. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  49761. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  49762. if (f != XBADFILE)
  49763. XFCLOSE(f);
  49764. c = buf;
  49765. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  49766. /* test cmp function */
  49767. ExpectNotNull(a = X509_get_issuer_name(x509));
  49768. ExpectNotNull(b = X509_get_subject_name(x509));
  49769. #ifndef OPENSSL_EXTRA_X509_SMALL
  49770. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  49771. #endif
  49772. tmp = buf;
  49773. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  49774. if (sz > 0 && tmp == buf) {
  49775. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  49776. __LINE__);
  49777. fprintf(stderr, " Expected pointer to be incremented\n");
  49778. abort();
  49779. }
  49780. #ifndef OPENSSL_EXTRA_X509_SMALL
  49781. tmp = buf;
  49782. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  49783. #endif
  49784. /* if output parameter is NULL, should still return required size. */
  49785. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  49786. /* retry but with the function creating a buffer */
  49787. tmp = NULL;
  49788. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  49789. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  49790. tmp = NULL;
  49791. #ifdef WOLFSSL_CERT_NAME_ALL
  49792. /* test for givenName and name */
  49793. {
  49794. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  49795. const byte gName[] = "test-given-name";
  49796. const byte name[] = "test-name";
  49797. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  49798. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  49799. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  49800. 1);
  49801. wolfSSL_X509_NAME_ENTRY_free(entry);
  49802. entry = NULL;
  49803. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  49804. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  49805. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  49806. 1);
  49807. wolfSSL_X509_NAME_ENTRY_free(entry);
  49808. tmp = NULL;
  49809. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  49810. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  49811. }
  49812. #endif
  49813. b = NULL;
  49814. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  49815. #ifndef OPENSSL_EXTRA_X509_SMALL
  49816. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  49817. #endif
  49818. X509_NAME_free((X509_NAME*)b);
  49819. X509_NAME_free(d2i_name);
  49820. d2i_name = NULL;
  49821. X509_free(x509);
  49822. #ifndef OPENSSL_EXTRA_X509_SMALL
  49823. /* test with an empty domain component */
  49824. tmp = empty;
  49825. sz = sizeof(empty);
  49826. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  49827. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  49828. /* size of empty emailAddress will be 0 */
  49829. tmp = buf;
  49830. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  49831. (char*)tmp, sizeof(buf)), 0);
  49832. /* should contain no organization name */
  49833. tmp = buf;
  49834. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  49835. (char*)tmp, sizeof(buf)), -1);
  49836. X509_NAME_free(d2i_name);
  49837. #endif
  49838. #endif
  49839. return EXPECT_RESULT();
  49840. }
  49841. static int test_wolfSSL_X509_NAME_hash(void)
  49842. {
  49843. EXPECT_DECLS;
  49844. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  49845. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  49846. BIO* bio = NULL;
  49847. X509* x509 = NULL;
  49848. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  49849. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  49850. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  49851. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  49852. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  49853. X509_free(x509);
  49854. BIO_free(bio);
  49855. #endif
  49856. return EXPECT_RESULT();
  49857. }
  49858. static int test_wolfSSL_X509_NAME_print_ex(void)
  49859. {
  49860. EXPECT_DECLS;
  49861. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  49862. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  49863. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  49864. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  49865. !defined(NO_BIO) && !defined(NO_RSA)
  49866. int memSz = 0;
  49867. byte* mem = NULL;
  49868. BIO* bio = NULL;
  49869. BIO* membio = NULL;
  49870. X509* x509 = NULL;
  49871. X509_NAME* name = NULL;
  49872. const char* expNormal = "C=US, CN=wolfssl.com";
  49873. const char* expEqSpace = "C = US, CN = wolfssl.com";
  49874. const char* expReverse = "CN=wolfssl.com, C=US";
  49875. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  49876. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  49877. const char* expRFC5523 =
  49878. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  49879. /* Test with real cert (svrCertFile) first */
  49880. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  49881. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  49882. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  49883. ExpectNotNull(name = X509_get_subject_name(x509));
  49884. /* Test without flags */
  49885. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49886. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49887. BIO_free(membio);
  49888. membio = NULL;
  49889. /* Test flag: XN_FLAG_RFC2253 */
  49890. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49891. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49892. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49893. BIO_free(membio);
  49894. membio = NULL;
  49895. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  49896. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49897. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49898. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49899. BIO_free(membio);
  49900. membio = NULL;
  49901. X509_free(x509);
  49902. BIO_free(bio);
  49903. name = NULL;
  49904. /* Test normal case without escaped characters */
  49905. {
  49906. /* Create name: "/C=US/CN=wolfssl.com" */
  49907. ExpectNotNull(name = X509_NAME_new());
  49908. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  49909. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  49910. WOLFSSL_SUCCESS);
  49911. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  49912. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  49913. WOLFSSL_SUCCESS);
  49914. /* Test without flags */
  49915. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49916. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49917. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49918. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  49919. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  49920. BIO_free(membio);
  49921. membio = NULL;
  49922. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  49923. spaces aroun '=' */
  49924. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49925. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  49926. WOLFSSL_SUCCESS);
  49927. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49928. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  49929. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  49930. BIO_free(membio);
  49931. membio = NULL;
  49932. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  49933. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49934. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49935. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49936. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49937. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  49938. BIO_free(membio);
  49939. membio = NULL;
  49940. /* Test flags: XN_FLAG_DN_REV - reversed */
  49941. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49942. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49943. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49944. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49945. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  49946. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  49947. BIO_free(membio);
  49948. membio = NULL;
  49949. X509_NAME_free(name);
  49950. name = NULL;
  49951. }
  49952. /* Test RFC2253 characters are escaped with backslashes */
  49953. {
  49954. ExpectNotNull(name = X509_NAME_new());
  49955. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  49956. /* space at beginning and end, and: ,+"\ */
  49957. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  49958. WOLFSSL_SUCCESS);
  49959. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  49960. /* # at beginning, and: <>;*/
  49961. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  49962. WOLFSSL_SUCCESS);
  49963. /* Test without flags */
  49964. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49965. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  49966. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49967. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  49968. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  49969. XSTRLEN(expNotEscaped)), 0);
  49970. BIO_free(membio);
  49971. membio = NULL;
  49972. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  49973. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49974. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49975. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  49976. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49977. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  49978. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  49979. BIO_free(membio);
  49980. membio = NULL;
  49981. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  49982. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  49983. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  49984. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  49985. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  49986. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  49987. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  49988. XSTRLEN(expNotEscapedRev)), 0);
  49989. BIO_free(membio);
  49990. X509_NAME_free(name);
  49991. }
  49992. #endif
  49993. return EXPECT_RESULT();
  49994. }
  49995. #ifndef NO_BIO
  49996. static int test_wolfSSL_X509_INFO_multiple_info(void)
  49997. {
  49998. EXPECT_DECLS;
  49999. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50000. STACK_OF(X509_INFO) *info_stack = NULL;
  50001. X509_INFO *info = NULL;
  50002. int len;
  50003. int i;
  50004. const char* files[] = {
  50005. cliCertFile,
  50006. cliKeyFile,
  50007. /* This needs to be the order as svrCertFile contains the
  50008. * intermediate cert as well. */
  50009. svrKeyFile,
  50010. svrCertFile,
  50011. NULL,
  50012. };
  50013. const char** curFile;
  50014. BIO *fileBIO = NULL;
  50015. BIO *concatBIO = NULL;
  50016. byte tmp[FOURK_BUF];
  50017. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  50018. * to group objects together. */
  50019. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  50020. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  50021. int fileLen = 0;
  50022. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  50023. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  50024. if (EXPECT_SUCCESS()) {
  50025. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  50026. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  50027. fileLen -= len;
  50028. if (EXPECT_FAIL())
  50029. break;
  50030. }
  50031. /* Make sure we read the entire file */
  50032. ExpectIntEQ(fileLen, 0);
  50033. }
  50034. BIO_free(fileBIO);
  50035. fileBIO = NULL;
  50036. }
  50037. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  50038. NULL));
  50039. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  50040. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50041. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50042. ExpectNotNull(info->x509);
  50043. ExpectNull(info->crl);
  50044. if (i != 0) {
  50045. ExpectNotNull(info->x_pkey);
  50046. ExpectIntEQ(X509_check_private_key(info->x509,
  50047. info->x_pkey->dec_pkey), 1);
  50048. }
  50049. else {
  50050. ExpectNull(info->x_pkey);
  50051. }
  50052. }
  50053. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50054. BIO_free(concatBIO);
  50055. #endif
  50056. return EXPECT_RESULT();
  50057. }
  50058. #endif
  50059. #ifndef NO_BIO
  50060. static int test_wolfSSL_X509_INFO(void)
  50061. {
  50062. EXPECT_DECLS;
  50063. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50064. STACK_OF(X509_INFO) *info_stack = NULL;
  50065. X509_INFO *info = NULL;
  50066. BIO *cert = NULL;
  50067. int i;
  50068. /* PEM in hex format to avoid null terminator */
  50069. byte data[] = {
  50070. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  50071. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  50072. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  50073. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  50074. 0x2d, 0x2d, 0x2d
  50075. };
  50076. /* PEM in hex format to avoid null terminator */
  50077. byte data2[] = {
  50078. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  50079. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  50080. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  50081. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  50082. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  50083. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  50084. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  50085. };
  50086. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50087. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50088. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50089. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50090. ExpectNotNull(info->x509);
  50091. ExpectNull(info->crl);
  50092. ExpectNull(info->x_pkey);
  50093. }
  50094. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50095. info_stack = NULL;
  50096. BIO_free(cert);
  50097. cert = NULL;
  50098. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50099. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50100. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50101. info_stack = NULL;
  50102. BIO_free(cert);
  50103. cert = NULL;
  50104. /* This case should fail due to invalid input. */
  50105. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50106. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  50107. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50108. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50109. info_stack = NULL;
  50110. BIO_free(cert);
  50111. cert = NULL;
  50112. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50113. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  50114. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50115. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50116. BIO_free(cert);
  50117. #endif
  50118. return EXPECT_RESULT();
  50119. }
  50120. #endif
  50121. static int test_wolfSSL_X509_subject_name_hash(void)
  50122. {
  50123. EXPECT_DECLS;
  50124. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50125. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50126. X509* x509 = NULL;
  50127. X509_NAME* subjectName = NULL;
  50128. unsigned long ret1 = 0;
  50129. unsigned long ret2 = 0;
  50130. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50131. SSL_FILETYPE_PEM));
  50132. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  50133. /* These two
  50134. * - X509_subject_name_hash(x509)
  50135. * - X509_NAME_hash(X509_get_subject_name(x509))
  50136. * should give the same hash, if !defined(NO_SHA) is true. */
  50137. ret1 = X509_subject_name_hash(x509);
  50138. ExpectIntNE(ret1, 0);
  50139. #if !defined(NO_SHA)
  50140. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  50141. ExpectIntNE(ret2, 0);
  50142. ExpectIntEQ(ret1, ret2);
  50143. #else
  50144. (void) ret2;
  50145. #endif
  50146. X509_free(x509);
  50147. #endif
  50148. return EXPECT_RESULT();
  50149. }
  50150. static int test_wolfSSL_X509_issuer_name_hash(void)
  50151. {
  50152. EXPECT_DECLS;
  50153. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50154. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50155. X509* x509 = NULL;
  50156. X509_NAME* issuertName = NULL;
  50157. unsigned long ret1 = 0;
  50158. unsigned long ret2 = 0;
  50159. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50160. SSL_FILETYPE_PEM));
  50161. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  50162. /* These two
  50163. * - X509_issuer_name_hash(x509)
  50164. * - X509_NAME_hash(X509_get_issuer_name(x509))
  50165. * should give the same hash, if !defined(NO_SHA) is true. */
  50166. ret1 = X509_issuer_name_hash(x509);
  50167. ExpectIntNE(ret1, 0);
  50168. #if !defined(NO_SHA)
  50169. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  50170. ExpectIntNE(ret2, 0);
  50171. ExpectIntEQ(ret1, ret2);
  50172. #else
  50173. (void) ret2;
  50174. #endif
  50175. X509_free(x509);
  50176. #endif
  50177. return EXPECT_RESULT();
  50178. }
  50179. static int test_wolfSSL_X509_check_host(void)
  50180. {
  50181. EXPECT_DECLS;
  50182. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50183. && !defined(NO_SHA) && !defined(NO_RSA)
  50184. X509* x509 = NULL;
  50185. const char altName[] = "example.com";
  50186. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50187. SSL_FILETYPE_PEM));
  50188. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  50189. WOLFSSL_SUCCESS);
  50190. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  50191. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50192. X509_free(x509);
  50193. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  50194. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50195. #endif
  50196. return EXPECT_RESULT();
  50197. }
  50198. static int test_wolfSSL_X509_check_email(void)
  50199. {
  50200. EXPECT_DECLS;
  50201. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  50202. X509* x509 = NULL;
  50203. const char goodEmail[] = "info@wolfssl.com";
  50204. const char badEmail[] = "disinfo@wolfssl.com";
  50205. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50206. SSL_FILETYPE_PEM));
  50207. /* Should fail on non-matching email address */
  50208. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  50209. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50210. /* Should succeed on matching email address */
  50211. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  50212. WOLFSSL_SUCCESS);
  50213. /* Should compute length internally when not provided */
  50214. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  50215. WOLFSSL_SUCCESS);
  50216. /* Should fail when email address is NULL */
  50217. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  50218. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50219. X509_free(x509);
  50220. /* Should fail when x509 is NULL */
  50221. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  50222. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50223. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  50224. return EXPECT_RESULT();
  50225. }
  50226. static int test_wc_PemToDer(void)
  50227. {
  50228. EXPECT_DECLS;
  50229. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50230. int ret;
  50231. DerBuffer* pDer = NULL;
  50232. const char* ca_cert = "./certs/server-cert.pem";
  50233. byte* cert_buf = NULL;
  50234. size_t cert_sz = 0;
  50235. int eccKey = 0;
  50236. EncryptedInfo info;
  50237. XMEMSET(&info, 0, sizeof(info));
  50238. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50239. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  50240. &info, &eccKey), 0);
  50241. wc_FreeDer(&pDer);
  50242. pDer = NULL;
  50243. if (cert_buf != NULL) {
  50244. free(cert_buf);
  50245. cert_buf = NULL;
  50246. }
  50247. #ifdef HAVE_ECC
  50248. {
  50249. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  50250. byte key_buf[256] = {0};
  50251. /* Test fail of loading a key with cert type */
  50252. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  50253. key_buf[0] = '\n';
  50254. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  50255. ExpectIntNE((ret = wc_PemToDer(key_buf, cert_sz + 1, CERT_TYPE,
  50256. &pDer, NULL, &info, &eccKey)), 0);
  50257. #ifdef OPENSSL_EXTRA
  50258. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  50259. &pDer, NULL, &info, &eccKey)), 0);
  50260. #endif
  50261. wc_FreeDer(&pDer);
  50262. if (cert_buf != NULL)
  50263. free(cert_buf);
  50264. }
  50265. #endif
  50266. #endif
  50267. return EXPECT_RESULT();
  50268. }
  50269. static int test_wc_AllocDer(void)
  50270. {
  50271. EXPECT_DECLS;
  50272. #if !defined(NO_CERTS)
  50273. DerBuffer* pDer = NULL;
  50274. word32 testSize = 1024;
  50275. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  50276. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50277. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  50278. ExpectNotNull(pDer);
  50279. wc_FreeDer(&pDer);
  50280. #endif
  50281. return EXPECT_RESULT();
  50282. }
  50283. static int test_wc_CertPemToDer(void)
  50284. {
  50285. EXPECT_DECLS;
  50286. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50287. const char* ca_cert = "./certs/ca-cert.pem";
  50288. byte* cert_buf = NULL;
  50289. size_t cert_sz = 0;
  50290. size_t cert_dersz = 0;
  50291. byte* cert_der = NULL;
  50292. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50293. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50294. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50295. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50296. (int)cert_dersz, CERT_TYPE), 0);
  50297. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  50298. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50299. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  50300. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50301. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  50302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50303. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  50304. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50305. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  50306. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50307. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  50308. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50309. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  50310. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50311. if (cert_der != NULL)
  50312. free(cert_der);
  50313. if (cert_buf != NULL)
  50314. free(cert_buf);
  50315. #endif
  50316. return EXPECT_RESULT();
  50317. }
  50318. static int test_wc_KeyPemToDer(void)
  50319. {
  50320. EXPECT_DECLS;
  50321. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  50322. int ret = 0;
  50323. const byte cert_buf[] = \
  50324. "-----BEGIN PRIVATE KEY-----\n"
  50325. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  50326. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  50327. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  50328. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  50329. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  50330. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  50331. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  50332. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  50333. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  50334. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  50335. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  50336. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  50337. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  50338. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  50339. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  50340. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  50341. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  50342. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  50343. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  50344. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  50345. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  50346. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  50347. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  50348. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  50349. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  50350. "AQue5o6oVfhgLiJzMdo/77gw\n"
  50351. "-----END PRIVATE KEY-----\n";
  50352. const int cert_sz = sizeof(cert_buf);
  50353. const char cert_pw[] = "password";
  50354. int cert_dersz = 0;
  50355. byte* cert_der = NULL;
  50356. /* Bad arg: Cert buffer is NULL */
  50357. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  50358. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50359. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  50360. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  50361. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50362. /* Test normal operation */
  50363. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50364. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50365. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50366. cert_pw), 0);
  50367. ExpectIntLE(ret, cert_sz);
  50368. if (cert_der != NULL) {
  50369. free(cert_der);
  50370. cert_der = NULL;
  50371. }
  50372. /* Test NULL for DER buffer to return needed DER buffer size */
  50373. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  50374. ExpectIntLE(ret, cert_sz);
  50375. if (EXPECT_SUCCESS())
  50376. cert_dersz = ret;
  50377. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50378. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50379. cert_pw), 0);
  50380. ExpectIntLE(ret, cert_sz);
  50381. if (cert_der != NULL)
  50382. free(cert_der);
  50383. #endif
  50384. return EXPECT_RESULT();
  50385. }
  50386. static int test_wc_PubKeyPemToDer(void)
  50387. {
  50388. EXPECT_DECLS;
  50389. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  50390. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50391. int ret = 0;
  50392. const char* key = "./certs/ecc-client-keyPub.pem";
  50393. byte* cert_buf = NULL;
  50394. size_t cert_sz = 0, cert_dersz = 0;
  50395. byte* cert_der = NULL;
  50396. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  50397. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50398. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  50399. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50400. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50401. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50402. (int)cert_dersz), 0);
  50403. if (cert_der != NULL) {
  50404. free(cert_der);
  50405. cert_der = NULL;
  50406. }
  50407. /* Test NULL for DER buffer to return needed DER buffer size */
  50408. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  50409. ExpectIntLE(ret, cert_sz);
  50410. cert_dersz = (size_t)ret;
  50411. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50412. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50413. (int)cert_dersz), 0);
  50414. if (cert_der != NULL) {
  50415. free(cert_der);
  50416. }
  50417. if (cert_buf != NULL) {
  50418. free(cert_buf);
  50419. }
  50420. #endif
  50421. return EXPECT_RESULT();
  50422. }
  50423. static int test_wc_PemPubKeyToDer(void)
  50424. {
  50425. EXPECT_DECLS;
  50426. #if !defined(NO_FILESYSTEM) && \
  50427. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50428. const char* key = "./certs/ecc-client-keyPub.pem";
  50429. size_t cert_dersz = 1024;
  50430. byte* cert_der = NULL;
  50431. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  50432. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50433. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50434. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  50435. if (cert_der != NULL) {
  50436. free(cert_der);
  50437. }
  50438. #endif
  50439. return EXPECT_RESULT();
  50440. }
  50441. static int test_wc_GetPubKeyDerFromCert(void)
  50442. {
  50443. EXPECT_DECLS;
  50444. #if !defined(NO_RSA) || defined(HAVE_ECC)
  50445. int ret;
  50446. word32 idx = 0;
  50447. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50448. word32 keyDerSz = (word32)sizeof(keyDer);
  50449. DecodedCert decoded;
  50450. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50451. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  50452. word32 certBufSz = sizeof(certBuf);
  50453. #endif
  50454. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  50455. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  50456. XFILE fp = XBADFILE;
  50457. #endif
  50458. #ifndef NO_RSA
  50459. RsaKey rsaKey;
  50460. #if defined(USE_CERT_BUFFERS_2048)
  50461. byte* rsaCertDer = (byte*)client_cert_der_2048;
  50462. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  50463. #elif defined(USE_CERT_BUFFERS_1024)
  50464. byte* rsaCertDer = (byte*)client_cert_der_1024;
  50465. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  50466. #else
  50467. unsigned char rsaCertDer[TWOK_BUF];
  50468. word32 rsaCertDerSz;
  50469. #endif
  50470. #endif
  50471. #ifdef HAVE_ECC
  50472. ecc_key eccKey;
  50473. #if defined(USE_CERT_BUFFERS_256)
  50474. byte* eccCert = (byte*)cliecc_cert_der_256;
  50475. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  50476. #else
  50477. unsigned char eccCert[ONEK_BUF];
  50478. word32 eccCertSz;
  50479. XFILE fp2 = XBADFILE;
  50480. #endif
  50481. #endif
  50482. #ifndef NO_RSA
  50483. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  50484. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  50485. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  50486. fp), 0);
  50487. if (fp != XBADFILE) {
  50488. XFCLOSE(fp);
  50489. fp = XBADFILE;
  50490. }
  50491. #endif
  50492. /* good test case - RSA DER cert */
  50493. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  50494. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50495. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50496. ExpectIntGT(keyDerSz, 0);
  50497. /* sanity check, verify we can import DER public key */
  50498. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50499. ExpectIntEQ(ret, 0);
  50500. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50501. if (ret == 0) {
  50502. wc_FreeRsaKey(&rsaKey);
  50503. }
  50504. /* test LENGTH_ONLY_E case */
  50505. keyDerSz = 0;
  50506. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50507. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50508. ExpectIntGT(keyDerSz, 0);
  50509. /* bad args: DecodedCert NULL */
  50510. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50511. /* bad args: output key buff size */
  50512. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50513. /* bad args: zero size output key buffer */
  50514. keyDerSz = 0;
  50515. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50516. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50517. wc_FreeDecodedCert(&decoded);
  50518. /* Certificate Request Tests */
  50519. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50520. {
  50521. XMEMSET(certBuf, 0, sizeof(certBuf));
  50522. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  50523. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  50524. if (fp != XBADFILE) {
  50525. XFCLOSE(fp);
  50526. }
  50527. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  50528. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  50529. /* good test case - RSA DER certificate request */
  50530. keyDerSz = sizeof(keyDer);
  50531. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50532. 0);
  50533. ExpectIntGT(keyDerSz, 0);
  50534. /* sanity check, verify we can import DER public key */
  50535. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50536. ExpectIntEQ(ret, 0);
  50537. idx = 0;
  50538. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50539. if (ret == 0) {
  50540. wc_FreeRsaKey(&rsaKey);
  50541. }
  50542. wc_FreeDecodedCert(&decoded);
  50543. }
  50544. #endif /* WOLFSSL_CERT_REQ */
  50545. #endif /* NO_RSA */
  50546. #ifdef HAVE_ECC
  50547. #ifndef USE_CERT_BUFFERS_256
  50548. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  50549. XBADFILE);
  50550. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  50551. if (fp2 != XBADFILE) {
  50552. XFCLOSE(fp2);
  50553. }
  50554. #endif
  50555. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  50556. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50557. /* good test case - ECC */
  50558. XMEMSET(keyDer, 0, sizeof(keyDer));
  50559. keyDerSz = sizeof(keyDer);
  50560. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50561. ExpectIntGT(keyDerSz, 0);
  50562. /* sanity check, verify we can import DER public key */
  50563. ret = wc_ecc_init(&eccKey);
  50564. ExpectIntEQ(ret, 0);
  50565. idx = 0; /* reset idx to 0, used above in RSA case */
  50566. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  50567. if (ret == 0) {
  50568. wc_ecc_free(&eccKey);
  50569. }
  50570. /* test LENGTH_ONLY_E case */
  50571. keyDerSz = 0;
  50572. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50573. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50574. ExpectIntGT(keyDerSz, 0);
  50575. wc_FreeDecodedCert(&decoded);
  50576. #endif
  50577. #endif /* !NO_RSA || HAVE_ECC */
  50578. return EXPECT_RESULT();
  50579. }
  50580. static int test_wc_CheckCertSigPubKey(void)
  50581. {
  50582. EXPECT_DECLS;
  50583. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50584. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  50585. int ret = 0;
  50586. const char* ca_cert = "./certs/ca-cert.pem";
  50587. byte* cert_buf = NULL;
  50588. size_t cert_sz = 0;
  50589. byte* cert_der = NULL;
  50590. word32 cert_dersz = 0;
  50591. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50592. word32 keyDerSz = (word32)sizeof(keyDer);
  50593. DecodedCert decoded;
  50594. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50595. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  50596. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50597. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50598. (int)cert_dersz, CERT_TYPE), 0);
  50599. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  50600. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50601. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50602. ExpectIntGT(keyDerSz, 0);
  50603. /* Good test case. */
  50604. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50605. keyDerSz, RSAk), 0);
  50606. /* No certificate. */
  50607. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  50608. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50609. /* Bad cert size. */
  50610. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  50611. RSAk), 0);
  50612. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  50613. /* No public key. */
  50614. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  50615. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  50616. /* Bad public key size. */
  50617. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  50618. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50619. /* Wrong aglo. */
  50620. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50621. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  50622. wc_FreeDecodedCert(&decoded);
  50623. if (cert_der != NULL)
  50624. free(cert_der);
  50625. if (cert_buf != NULL)
  50626. free(cert_buf);
  50627. #endif
  50628. return EXPECT_RESULT();
  50629. }
  50630. static int test_wolfSSL_certs(void)
  50631. {
  50632. EXPECT_DECLS;
  50633. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50634. !defined(NO_RSA)
  50635. X509* x509ext = NULL;
  50636. X509* x509 = NULL;
  50637. #ifdef OPENSSL_ALL
  50638. WOLFSSL_X509_EXTENSION* ext = NULL;
  50639. ASN1_OBJECT* obj = NULL;
  50640. #endif
  50641. WOLFSSL* ssl = NULL;
  50642. WOLFSSL_CTX* ctx = NULL;
  50643. STACK_OF(ASN1_OBJECT)* sk = NULL;
  50644. ASN1_STRING* asn1_str = NULL;
  50645. AUTHORITY_KEYID* akey = NULL;
  50646. BASIC_CONSTRAINTS* bc = NULL;
  50647. int crit = 0;
  50648. #ifndef NO_WOLFSSL_SERVER
  50649. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  50650. #else
  50651. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  50652. #endif
  50653. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  50654. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50655. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  50656. #if !defined(NO_CHECK_PRIVATE_KEY)
  50657. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50658. #endif
  50659. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50660. #if !defined(NO_CHECK_PRIVATE_KEY)
  50661. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  50662. #endif
  50663. ExpectNotNull(ssl = SSL_new(ctx));
  50664. /* Invalid parameters. */
  50665. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50667. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50668. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50669. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  50670. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50671. #if !defined(NO_CHECK_PRIVATE_KEY)
  50672. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50673. #endif
  50674. #ifdef HAVE_PK_CALLBACKS
  50675. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  50676. #endif /* HAVE_PK_CALLBACKS */
  50677. /* Invalid parameters. */
  50678. ExpectNotNull(x509 = wolfSSL_X509_new());
  50679. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50680. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50681. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50682. /* No data in certificate. */
  50683. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50684. wolfSSL_X509_free(x509);
  50685. x509 = NULL;
  50686. /* create and use x509 */
  50687. #ifdef OPENSSL_ALL
  50688. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50689. WOLFSSL_FILETYPE_PEM));
  50690. #endif
  50691. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  50692. WOLFSSL_FILETYPE_PEM));
  50693. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  50694. #if !defined(NO_CHECK_PRIVATE_KEY)
  50695. /* with loading in a new cert the check on private key should now fail */
  50696. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50697. #endif
  50698. #if defined(USE_CERT_BUFFERS_2048)
  50699. /* Invalid parameters. */
  50700. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50701. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50702. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  50703. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50704. /* No data. */
  50705. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50706. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50707. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50708. (unsigned char*)server_cert_der_2048,
  50709. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  50710. #endif
  50711. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  50712. /************* Get Digest of Certificate ******************/
  50713. {
  50714. byte digest[64]; /* max digest size */
  50715. word32 digestSz;
  50716. XMEMSET(digest, 0, sizeof(digest));
  50717. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  50718. WOLFSSL_SUCCESS);
  50719. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  50720. WOLFSSL_SUCCESS);
  50721. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  50722. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50723. }
  50724. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  50725. /* test and checkout X509 extensions */
  50726. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  50727. NID_basic_constraints, &crit, NULL));
  50728. ExpectIntEQ(crit, 0);
  50729. #ifdef OPENSSL_ALL
  50730. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  50731. X509_EXTENSION_free(ext);
  50732. ext = NULL;
  50733. ExpectNotNull(ext = X509_EXTENSION_new());
  50734. X509_EXTENSION_set_critical(ext, 1);
  50735. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  50736. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  50737. ASN1_OBJECT_free(obj);
  50738. obj = NULL;
  50739. X509_EXTENSION_free(ext);
  50740. ext = NULL;
  50741. ExpectNotNull(ext = X509_EXTENSION_new());
  50742. X509_EXTENSION_set_critical(ext, 0);
  50743. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50744. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  50745. NULL);
  50746. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  50747. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  50748. * and X509_get_ext_d2i has created new */
  50749. asn1_str = NULL;
  50750. X509_EXTENSION_free(ext);
  50751. ext = NULL;
  50752. #endif
  50753. BASIC_CONSTRAINTS_free(bc);
  50754. bc = NULL;
  50755. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  50756. NID_key_usage, &crit, NULL));
  50757. ExpectIntEQ(crit, 1);
  50758. ExpectIntEQ(asn1_str->type, NID_key_usage);
  50759. #ifdef OPENSSL_ALL
  50760. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  50761. X509_EXTENSION_free(ext);
  50762. ext = NULL;
  50763. #endif
  50764. ASN1_STRING_free(asn1_str);
  50765. asn1_str = NULL;
  50766. #ifdef OPENSSL_ALL
  50767. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  50768. NID_ext_key_usage, &crit, NULL));
  50769. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  50770. X509_EXTENSION_free(ext);
  50771. ext = NULL;
  50772. EXTENDED_KEY_USAGE_free(sk);
  50773. sk = NULL;
  50774. #else
  50775. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  50776. &crit, NULL);
  50777. ExpectNull(sk);
  50778. #endif
  50779. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  50780. NID_authority_key_identifier, &crit, NULL));
  50781. #ifdef OPENSSL_ALL
  50782. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  50783. akey));
  50784. X509_EXTENSION_free(ext);
  50785. ext = NULL;
  50786. #endif
  50787. wolfSSL_AUTHORITY_KEYID_free(akey);
  50788. akey = NULL;
  50789. /* NID not yet supported */
  50790. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50791. NID_private_key_usage_period, &crit, NULL));
  50792. ExpectIntEQ(crit, -1);
  50793. sk_ASN1_OBJECT_free(sk);
  50794. sk = NULL;
  50795. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  50796. NID_subject_alt_name, &crit, NULL));
  50797. {
  50798. int i;
  50799. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  50800. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  50801. ExpectIntEQ(gen->type, GEN_DNS);
  50802. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  50803. }
  50804. }
  50805. sk_GENERAL_NAME_free(sk);
  50806. sk = NULL;
  50807. /* NID not yet supported */
  50808. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50809. NID_issuer_alt_name, &crit, NULL));
  50810. ExpectIntEQ(crit, -1);
  50811. sk_ASN1_OBJECT_free(sk);
  50812. sk = NULL;
  50813. /* NID not yet supported */
  50814. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50815. NID_info_access, &crit, NULL));
  50816. sk_ASN1_OBJECT_free(sk);
  50817. sk = NULL;
  50818. /* NID not yet supported */
  50819. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50820. NID_sinfo_access, &crit, NULL));
  50821. ExpectIntEQ(crit, -1);
  50822. sk_ASN1_OBJECT_free(sk);
  50823. sk = NULL;
  50824. /* NID not yet supported */
  50825. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50826. NID_name_constraints, &crit, NULL));
  50827. ExpectIntEQ(crit, -1);
  50828. sk_ASN1_OBJECT_free(sk);
  50829. sk = NULL;
  50830. /* no cert policy set */
  50831. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50832. NID_certificate_policies, &crit, NULL));
  50833. sk_ASN1_OBJECT_free(sk);
  50834. sk = NULL;
  50835. /* NID not yet supported */
  50836. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50837. NID_policy_mappings, &crit, NULL));
  50838. ExpectIntEQ(crit, -1);
  50839. sk_ASN1_OBJECT_free(sk);
  50840. sk = NULL;
  50841. /* NID not yet supported */
  50842. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50843. NID_policy_constraints, &crit, NULL));
  50844. ExpectIntEQ(crit, -1);
  50845. sk_ASN1_OBJECT_free(sk);
  50846. sk = NULL;
  50847. /* NID not yet supported */
  50848. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50849. NID_inhibit_any_policy, &crit, NULL));
  50850. ExpectIntEQ(crit, -1);
  50851. sk_ASN1_OBJECT_free(sk);
  50852. sk = NULL;
  50853. /* NID not yet supported */
  50854. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  50855. NID_tlsfeature, &crit, NULL));
  50856. ExpectIntEQ(crit, -1);
  50857. sk_ASN1_OBJECT_free(sk);
  50858. sk = NULL;
  50859. /* test invalid cases */
  50860. crit = 0;
  50861. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  50862. NULL));
  50863. ExpectIntEQ(crit, -1);
  50864. /* NULL passed for criticality. */
  50865. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  50866. NID_tlsfeature, NULL, NULL));
  50867. ExpectIntEQ(SSL_get_hit(ssl), 0);
  50868. #ifdef OPENSSL_ALL
  50869. X509_free(x509);
  50870. #endif
  50871. X509_free(x509ext);
  50872. SSL_free(ssl);
  50873. SSL_CTX_free(ctx);
  50874. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  50875. return EXPECT_RESULT();
  50876. }
  50877. static int test_wolfSSL_X509_check_private_key(void)
  50878. {
  50879. EXPECT_DECLS;
  50880. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  50881. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  50882. X509* x509 = NULL;
  50883. EVP_PKEY* pkey = NULL;
  50884. const byte* key;
  50885. /* Check with correct key */
  50886. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  50887. SSL_FILETYPE_PEM)));
  50888. key = client_key_der_2048;
  50889. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  50890. (long)sizeof_client_key_der_2048));
  50891. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  50892. EVP_PKEY_free(pkey);
  50893. pkey = NULL;
  50894. /* Check with wrong key */
  50895. key = server_key_der_2048;
  50896. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  50897. (long)sizeof_server_key_der_2048));
  50898. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  50899. /* test for incorrect parameter */
  50900. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  50901. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  50902. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  50903. EVP_PKEY_free(pkey);
  50904. X509_free(x509);
  50905. #endif
  50906. return EXPECT_RESULT();
  50907. }
  50908. static int test_wolfSSL_private_keys(void)
  50909. {
  50910. EXPECT_DECLS;
  50911. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  50912. !defined(NO_FILESYSTEM)
  50913. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  50914. WOLFSSL* ssl = NULL;
  50915. WOLFSSL_CTX* ctx = NULL;
  50916. EVP_PKEY* pkey = NULL;
  50917. OpenSSL_add_all_digests();
  50918. OpenSSL_add_all_algorithms();
  50919. #ifndef NO_RSA
  50920. #ifndef NO_WOLFSSL_SERVER
  50921. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  50922. #else
  50923. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  50924. #endif
  50925. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  50926. WOLFSSL_FILETYPE_PEM));
  50927. /* Have to load a cert before you can check the private key against that
  50928. * certificates public key! */
  50929. #if !defined(NO_CHECK_PRIVATE_KEY)
  50930. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50931. #endif
  50932. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  50933. WOLFSSL_FILETYPE_PEM));
  50934. #if !defined(NO_CHECK_PRIVATE_KEY)
  50935. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50936. #endif
  50937. ExpectNotNull(ssl = SSL_new(ctx));
  50938. #if !defined(NO_CHECK_PRIVATE_KEY)
  50939. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50940. #endif
  50941. /* Invalid parameters. */
  50942. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50943. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50944. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  50945. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50946. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50947. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50948. #ifdef USE_CERT_BUFFERS_2048
  50949. {
  50950. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  50951. unsigned char buf[FOURK_BUF];
  50952. word32 bufSz;
  50953. /* Invalid parameters. */
  50954. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50955. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50956. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  50957. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50958. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50959. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50960. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  50961. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50962. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50963. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50964. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  50965. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50966. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  50967. (unsigned char*)client_key_der_2048,
  50968. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  50969. #if !defined(NO_CHECK_PRIVATE_KEY)
  50970. /* Should mismatch now that a different private key loaded */
  50971. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50972. #endif
  50973. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  50974. (unsigned char*)server_key,
  50975. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  50976. #if !defined(NO_CHECK_PRIVATE_KEY)
  50977. /* After loading back in DER format of original key, should match */
  50978. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50979. #endif
  50980. /* test loading private key to the WOLFSSL_CTX */
  50981. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  50982. (unsigned char*)client_key_der_2048,
  50983. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  50984. #if !defined(NO_CHECK_PRIVATE_KEY)
  50985. /* Should mismatch now that a different private key loaded */
  50986. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50987. #endif
  50988. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  50989. (unsigned char*)server_key,
  50990. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  50991. #if !defined(NO_CHECK_PRIVATE_KEY)
  50992. /* After loading back in DER format of original key, should match */
  50993. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  50994. #endif
  50995. /* Invalid parameters. */
  50996. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  50997. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50998. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50999. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51000. /* pkey is empty - no key data to use. */
  51001. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  51002. wolfSSL_EVP_PKEY_free(pkey);
  51003. pkey = NULL;
  51004. /* set PKEY and test again */
  51005. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51006. &server_key, (long)sizeof_server_key_der_2048));
  51007. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51008. /* reuse PKEY structure and test
  51009. * this should be checked with a memory management sanity checker */
  51010. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  51011. server_key = (const unsigned char*)server_key_der_2048;
  51012. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51013. &server_key, (long)sizeof_server_key_der_2048));
  51014. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51015. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  51016. bufSz = FOURK_BUF;
  51017. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  51018. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  51019. RSAk, NULL, 0)), 0);
  51020. server_key = (const unsigned char*)buf;
  51021. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51022. (long)bufSz));
  51023. }
  51024. #endif
  51025. EVP_PKEY_free(pkey);
  51026. pkey = NULL;
  51027. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  51028. ssl = NULL;
  51029. SSL_CTX_free(ctx);
  51030. ctx = NULL;
  51031. #endif /* end of RSA private key match tests */
  51032. #ifdef HAVE_ECC
  51033. #ifndef NO_WOLFSSL_SERVER
  51034. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51035. #else
  51036. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51037. #endif
  51038. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  51039. WOLFSSL_FILETYPE_PEM));
  51040. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  51041. WOLFSSL_FILETYPE_PEM));
  51042. ExpectNotNull(ssl = SSL_new(ctx));
  51043. #if !defined(NO_CHECK_PRIVATE_KEY)
  51044. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51045. #endif
  51046. SSL_free(ssl);
  51047. ssl = NULL;
  51048. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  51049. WOLFSSL_FILETYPE_PEM));
  51050. ExpectNotNull(ssl = SSL_new(ctx));
  51051. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  51052. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51053. #endif
  51054. SSL_free(ssl);
  51055. ssl = NULL;
  51056. SSL_CTX_free(ctx);
  51057. ctx = NULL;
  51058. #endif /* end of ECC private key match tests */
  51059. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  51060. #ifndef NO_WOLFSSL_SERVER
  51061. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51062. #else
  51063. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51064. #endif
  51065. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  51066. WOLFSSL_FILETYPE_PEM));
  51067. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  51068. WOLFSSL_FILETYPE_PEM));
  51069. ExpectNotNull(ssl = SSL_new(ctx));
  51070. #if !defined(NO_CHECK_PRIVATE_KEY)
  51071. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51072. #endif
  51073. SSL_free(ssl);
  51074. ssl = NULL;
  51075. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  51076. WOLFSSL_FILETYPE_PEM));
  51077. ExpectNotNull(ssl = SSL_new(ctx));
  51078. #if !defined(NO_CHECK_PRIVATE_KEY)
  51079. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51080. #endif
  51081. SSL_free(ssl);
  51082. ssl = NULL;
  51083. SSL_CTX_free(ctx);
  51084. ctx = NULL;
  51085. #endif /* end of Ed25519 private key match tests */
  51086. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  51087. #ifndef NO_WOLFSSL_SERVER
  51088. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51089. #else
  51090. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51091. #endif
  51092. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  51093. WOLFSSL_FILETYPE_PEM));
  51094. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  51095. WOLFSSL_FILETYPE_PEM));
  51096. ExpectNotNull(ssl = SSL_new(ctx));
  51097. #if !defined(NO_CHECK_PRIVATE_KEY)
  51098. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51099. #endif
  51100. SSL_free(ssl);
  51101. ssl = NULL;
  51102. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  51103. WOLFSSL_FILETYPE_PEM));
  51104. ExpectNotNull(ssl = SSL_new(ctx));
  51105. #if !defined(NO_CHECK_PRIVATE_KEY)
  51106. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51107. #endif
  51108. SSL_free(ssl);
  51109. ssl = NULL;
  51110. SSL_CTX_free(ctx);
  51111. ctx = NULL;
  51112. #endif /* end of Ed448 private key match tests */
  51113. EVP_cleanup();
  51114. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  51115. CONF_modules_free();
  51116. ENGINE_cleanup();
  51117. CONF_modules_unload();
  51118. (void)ssl;
  51119. (void)ctx;
  51120. (void)pkey;
  51121. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  51122. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51123. return EXPECT_RESULT();
  51124. }
  51125. static int test_wolfSSL_PEM_def_callback(void)
  51126. {
  51127. EXPECT_DECLS;
  51128. #ifdef OPENSSL_EXTRA
  51129. char buf[10];
  51130. const char* defpwd = "DEF PWD";
  51131. int defpwdLen = (int)XSTRLEN(defpwd);
  51132. int smallLen = 1;
  51133. /* Bad parameters. */
  51134. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  51135. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  51136. 0);
  51137. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  51138. XMEMSET(buf, 0, sizeof(buf));
  51139. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  51140. defpwdLen);
  51141. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  51142. ExpectIntEQ(buf[defpwdLen], 0);
  51143. /* Size of buffer is smaller than default password. */
  51144. XMEMSET(buf, 0, sizeof(buf));
  51145. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  51146. smallLen);
  51147. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  51148. ExpectIntEQ(buf[smallLen], 0);
  51149. #endif /* OPENSSL_EXTRA */
  51150. return EXPECT_RESULT();
  51151. }
  51152. static int test_wolfSSL_PEM_read_PrivateKey(void)
  51153. {
  51154. EXPECT_DECLS;
  51155. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  51156. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  51157. XFILE file = XBADFILE;
  51158. #if !defined(NO_RSA)
  51159. const char* fname_rsa = "./certs/server-key.pem";
  51160. RSA* rsa = NULL;
  51161. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  51162. unsigned char* sig = NULL;
  51163. size_t sigLen = 0;
  51164. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  51165. size_t tbsLen = sizeof(tbs);
  51166. #endif
  51167. #if !defined(NO_DSA)
  51168. const char* fname_dsa = "./certs/dsa2048.pem";
  51169. #endif
  51170. #if defined(HAVE_ECC)
  51171. const char* fname_ec = "./certs/ecc-key.pem";
  51172. #endif
  51173. #if !defined(NO_DH)
  51174. const char* fname_dh = "./certs/dh-priv-2048.pem";
  51175. #endif
  51176. EVP_PKEY* pkey = NULL;
  51177. /* Check error case. */
  51178. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  51179. /* not a PEM key. */
  51180. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51181. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51182. if (file != XBADFILE)
  51183. XFCLOSE(file);
  51184. file = XBADFILE;
  51185. #ifndef NO_RSA
  51186. /* Read in an RSA key. */
  51187. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  51188. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51189. if (file != XBADFILE)
  51190. XFCLOSE(file);
  51191. file = XBADFILE;
  51192. /* Make sure the key is usable by signing some data with it. */
  51193. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  51194. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  51195. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  51196. DYNAMIC_TYPE_TMP_BUFFER));
  51197. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  51198. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  51199. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  51200. WOLFSSL_SUCCESS);
  51201. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51202. EVP_PKEY_CTX_free(ctx);
  51203. EVP_PKEY_free(pkey);
  51204. pkey = NULL;
  51205. #endif
  51206. #ifndef NO_DSA
  51207. /* Read in a DSA key. */
  51208. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  51209. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  51210. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51211. EVP_PKEY_free(pkey);
  51212. pkey = NULL;
  51213. #else
  51214. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51215. #endif
  51216. if (file != XBADFILE)
  51217. XFCLOSE(file);
  51218. file = XBADFILE;
  51219. #endif
  51220. #ifdef HAVE_ECC
  51221. /* Read in an EC key. */
  51222. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  51223. ExpectNotNull(pkey = EVP_PKEY_new());
  51224. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  51225. if (file != XBADFILE)
  51226. XFCLOSE(file);
  51227. file = XBADFILE;
  51228. EVP_PKEY_free(pkey);
  51229. pkey = NULL;
  51230. #endif
  51231. #ifndef NO_DH
  51232. /* Read in a DH key. */
  51233. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  51234. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51235. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51236. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51237. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51238. EVP_PKEY_free(pkey);
  51239. pkey = NULL;
  51240. #else
  51241. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51242. #endif
  51243. if (file != XBADFILE)
  51244. XFCLOSE(file);
  51245. file = XBADFILE;
  51246. #endif
  51247. #endif
  51248. return EXPECT_RESULT();
  51249. }
  51250. static int test_wolfSSL_PEM_read_PUBKEY(void)
  51251. {
  51252. EXPECT_DECLS;
  51253. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  51254. && !defined(NO_FILESYSTEM)
  51255. XFILE file = XBADFILE;
  51256. const char* fname = "./certs/client-keyPub.pem";
  51257. EVP_PKEY* pkey = NULL;
  51258. /* Check error case. */
  51259. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  51260. /* Read in an RSA key. */
  51261. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51262. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  51263. EVP_PKEY_free(pkey);
  51264. pkey = NULL;
  51265. if (file != XBADFILE)
  51266. XFCLOSE(file);
  51267. file = XBADFILE;
  51268. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51269. ExpectNotNull(pkey = EVP_PKEY_new());
  51270. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  51271. EVP_PKEY_free(pkey);
  51272. if (file != XBADFILE)
  51273. XFCLOSE(file);
  51274. #endif
  51275. return EXPECT_RESULT();
  51276. }
  51277. /* test loading RSA key using BIO */
  51278. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  51279. {
  51280. EXPECT_DECLS;
  51281. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51282. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  51283. !defined(NO_BIO)
  51284. BIO* bio = NULL;
  51285. XFILE file = XBADFILE;
  51286. const char* fname = "./certs/server-key.pem";
  51287. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  51288. EVP_PKEY* pkey = NULL;
  51289. size_t sz = 0;
  51290. byte* buf = NULL;
  51291. EVP_PKEY* pkey2 = NULL;
  51292. EVP_PKEY* pkey3 = NULL;
  51293. RSA* rsa_key = NULL;
  51294. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51295. unsigned char extra[10];
  51296. int i;
  51297. BIO* pub_bio = NULL;
  51298. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51299. #endif
  51300. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51301. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51302. ExpectIntGT(sz = XFTELL(file), 0);
  51303. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51304. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51305. if (buf != NULL) {
  51306. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51307. }
  51308. if (file != XBADFILE) {
  51309. XFCLOSE(file);
  51310. file = XBADFILE;
  51311. }
  51312. /* Test using BIO new mem and loading PEM private key */
  51313. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51314. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51315. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51316. buf = NULL;
  51317. BIO_free(bio);
  51318. bio = NULL;
  51319. /* New empty EVP_PKEY */
  51320. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51321. if (pkey2 != NULL) {
  51322. pkey2->type = EVP_PKEY_RSA;
  51323. }
  51324. /* Test parameter copy */
  51325. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  51326. EVP_PKEY_free(pkey2);
  51327. EVP_PKEY_free(pkey);
  51328. pkey = NULL;
  51329. /* Qt unit test case : rsa pkcs8 key */
  51330. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  51331. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51332. ExpectIntGT(sz = XFTELL(file), 0);
  51333. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51334. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51335. if (buf) {
  51336. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51337. }
  51338. if (file != XBADFILE) {
  51339. XFCLOSE(file);
  51340. file = XBADFILE;
  51341. }
  51342. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51343. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51344. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51345. buf = NULL;
  51346. BIO_free(bio);
  51347. bio = NULL;
  51348. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51349. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  51350. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  51351. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51352. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51353. #else
  51354. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51355. #endif
  51356. RSA_free(rsa_key);
  51357. EVP_PKEY_free(pkey3);
  51358. EVP_PKEY_free(pkey);
  51359. pkey = NULL;
  51360. pkey2 = NULL;
  51361. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51362. #define BIO_PEM_TEST_CHAR 'a'
  51363. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  51364. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51365. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51366. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51367. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51368. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  51369. (long)sizeof_server_key_der_2048));
  51370. ExpectNull(pkey);
  51371. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51372. (long)sizeof_server_key_der_2048));
  51373. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  51374. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51375. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  51376. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51377. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51378. WOLFSSL_SUCCESS);
  51379. ExpectIntGT(BIO_pending(bio), 0);
  51380. ExpectIntEQ(BIO_pending(bio), 1679);
  51381. /* Check if the pubkey API writes only the public key */
  51382. #ifdef WOLFSSL_KEY_GEN
  51383. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51384. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51385. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51386. ExpectIntGT(BIO_pending(pub_bio), 0);
  51387. /* Previously both the private key and the pubkey calls would write
  51388. * out the private key and the PEM header was the only difference.
  51389. * The public PEM should be significantly shorter than the
  51390. * private key versison. */
  51391. ExpectIntEQ(BIO_pending(pub_bio), 451);
  51392. #else
  51393. /* Not supported. */
  51394. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  51395. #endif
  51396. /* test creating new EVP_PKEY with good args */
  51397. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51398. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51399. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51400. pkey->pkey_sz), 0);
  51401. }
  51402. /* test of reuse of EVP_PKEY */
  51403. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51404. ExpectIntEQ(BIO_pending(bio), 0);
  51405. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51406. SSL_SUCCESS);
  51407. /* add 10 extra bytes after PEM */
  51408. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  51409. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51410. ExpectNotNull(pkey);
  51411. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51412. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51413. pkey->pkey_sz), 0);
  51414. }
  51415. /* check 10 extra bytes still there */
  51416. ExpectIntEQ(BIO_pending(bio), 10);
  51417. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  51418. for (i = 0; i < 10; i++) {
  51419. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  51420. }
  51421. BIO_free(pub_bio);
  51422. BIO_free(bio);
  51423. bio = NULL;
  51424. EVP_PKEY_free(pkey);
  51425. pkey = NULL;
  51426. EVP_PKEY_free(pkey2);
  51427. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  51428. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  51429. * !NO_FILESYSTEM && !NO_BIO */
  51430. return EXPECT_RESULT();
  51431. }
  51432. /* test loading ECC key using BIO */
  51433. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  51434. {
  51435. EXPECT_DECLS;
  51436. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  51437. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51438. BIO* bio = NULL;
  51439. EVP_PKEY* pkey = NULL;
  51440. XFILE file = XBADFILE;
  51441. const char* fname = "./certs/ecc-key.pem";
  51442. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  51443. size_t sz = 0;
  51444. byte* buf = NULL;
  51445. EVP_PKEY* pkey2 = NULL;
  51446. EVP_PKEY* pkey3 = NULL;
  51447. EC_KEY* ec_key = NULL;
  51448. int nid = 0;
  51449. BIO* pub_bio = NULL;
  51450. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51451. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51452. ExpectIntGT(sz = XFTELL(file), 0);
  51453. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51454. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51455. if (buf) {
  51456. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51457. }
  51458. if (file != XBADFILE) {
  51459. XFCLOSE(file);
  51460. file = XBADFILE;
  51461. }
  51462. /* Test using BIO new mem and loading PEM private key */
  51463. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51464. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51465. BIO_free(bio);
  51466. bio = NULL;
  51467. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51468. buf = NULL;
  51469. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51470. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51471. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51472. WOLFSSL_SUCCESS);
  51473. ExpectIntGT(BIO_pending(bio), 0);
  51474. /* No parameters. */
  51475. ExpectIntEQ(BIO_pending(bio), 227);
  51476. /* Check if the pubkey API writes only the public key */
  51477. #ifdef WOLFSSL_KEY_GEN
  51478. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51479. ExpectIntGT(BIO_pending(pub_bio), 0);
  51480. /* Previously both the private key and the pubkey calls would write
  51481. * out the private key and the PEM header was the only difference.
  51482. * The public PEM should be significantly shorter than the
  51483. * private key versison. */
  51484. ExpectIntEQ(BIO_pending(pub_bio), 178);
  51485. #endif
  51486. BIO_free(pub_bio);
  51487. BIO_free(bio);
  51488. bio = NULL;
  51489. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51490. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51491. if (pkey2 != NULL) {
  51492. pkey2->type = EVP_PKEY_EC;
  51493. }
  51494. /* Test parameter copy */
  51495. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  51496. /* Qt unit test case 1*/
  51497. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51498. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51499. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51500. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51501. #else
  51502. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51503. #endif
  51504. /* Test default digest */
  51505. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  51506. ExpectIntEQ(nid, NID_sha256);
  51507. EC_KEY_free(ec_key);
  51508. ec_key = NULL;
  51509. EVP_PKEY_free(pkey3);
  51510. pkey3 = NULL;
  51511. EVP_PKEY_free(pkey2);
  51512. pkey2 = NULL;
  51513. EVP_PKEY_free(pkey);
  51514. pkey = NULL;
  51515. /* Qt unit test case ec pkcs8 key */
  51516. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  51517. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51518. ExpectIntGT(sz = XFTELL(file), 0);
  51519. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51520. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51521. if (buf) {
  51522. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51523. }
  51524. if (file != XBADFILE) {
  51525. XFCLOSE(file);
  51526. file = XBADFILE;
  51527. }
  51528. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51529. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51530. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51531. buf = NULL;
  51532. BIO_free(bio);
  51533. bio = NULL;
  51534. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51535. /* Qt unit test case */
  51536. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51537. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51538. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51539. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51540. #else
  51541. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51542. #endif
  51543. EC_KEY_free(ec_key);
  51544. EVP_PKEY_free(pkey3);
  51545. EVP_PKEY_free(pkey);
  51546. pkey = NULL;
  51547. #endif
  51548. return EXPECT_RESULT();
  51549. }
  51550. /* test loading DSA key using BIO */
  51551. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  51552. {
  51553. EXPECT_DECLS;
  51554. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  51555. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51556. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  51557. BIO* bio = NULL;
  51558. EVP_PKEY* pkey = NULL;
  51559. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  51560. /* Private DSA EVP_PKEY */
  51561. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51562. NULL));
  51563. BIO_free(bio);
  51564. bio = NULL;
  51565. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51566. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51567. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51568. NULL), 0);
  51569. #endif
  51570. #ifdef WOLFSSL_KEY_GEN
  51571. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  51572. ExpectIntEQ(BIO_pending(bio), 1178);
  51573. BIO_reset(bio);
  51574. #endif
  51575. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51576. 1);
  51577. ExpectIntEQ(BIO_pending(bio), 1196);
  51578. BIO_free(bio);
  51579. bio = NULL;
  51580. EVP_PKEY_free(pkey);
  51581. pkey = NULL;
  51582. #endif
  51583. #endif
  51584. return EXPECT_RESULT();
  51585. }
  51586. /* test loading DH key using BIO */
  51587. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  51588. {
  51589. EXPECT_DECLS;
  51590. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  51591. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51592. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51593. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51594. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51595. BIO* bio = NULL;
  51596. EVP_PKEY* pkey = NULL;
  51597. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  51598. /* Private DH EVP_PKEY */
  51599. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51600. NULL));
  51601. BIO_free(bio);
  51602. bio = NULL;
  51603. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51604. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51605. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51606. NULL), 0);
  51607. #endif
  51608. #ifdef WOLFSSL_KEY_GEN
  51609. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  51610. #endif
  51611. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51612. 1);
  51613. ExpectIntEQ(BIO_pending(bio), 806);
  51614. BIO_free(bio);
  51615. bio = NULL;
  51616. EVP_PKEY_free(pkey);
  51617. pkey = NULL;
  51618. #endif
  51619. #endif
  51620. return EXPECT_RESULT();
  51621. }
  51622. static int test_wolfSSL_PEM_PrivateKey(void)
  51623. {
  51624. EXPECT_DECLS;
  51625. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51626. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  51627. #ifndef NO_BIO
  51628. BIO* bio = NULL;
  51629. #endif
  51630. EVP_PKEY* pkey = NULL;
  51631. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51632. #ifndef NO_BIO
  51633. /* test creating new EVP_PKEY with bad arg */
  51634. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  51635. /* Test bad EVP_PKEY type. */
  51636. /* New HMAC EVP_PKEY */
  51637. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  51638. ExpectNotNull(pkey = EVP_PKEY_new());
  51639. if (pkey != NULL) {
  51640. pkey->type = EVP_PKEY_HMAC;
  51641. }
  51642. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51643. 0);
  51644. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51645. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51646. NULL), 0);
  51647. #endif
  51648. #ifdef WOLFSSL_KEY_GEN
  51649. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51650. #endif
  51651. EVP_PKEY_free(pkey);
  51652. pkey = NULL;
  51653. BIO_free(bio);
  51654. bio = NULL;
  51655. /* key is DES encrypted */
  51656. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  51657. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  51658. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51659. {
  51660. XFILE f = XBADFILE;
  51661. wc_pem_password_cb* passwd_cb = NULL;
  51662. void* passwd_cb_userdata;
  51663. SSL_CTX* ctx = NULL;
  51664. char passwd[] = "bad password";
  51665. #ifndef WOLFSSL_NO_TLS12
  51666. #ifndef NO_WOLFSSL_SERVER
  51667. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51668. #else
  51669. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51670. #endif
  51671. #else
  51672. #ifndef NO_WOLFSSL_SERVER
  51673. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51674. #else
  51675. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51676. #endif
  51677. #endif
  51678. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51679. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  51680. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  51681. ExpectNull(passwd_cb_userdata =
  51682. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  51683. /* fail case with password call back */
  51684. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51685. (void*)passwd));
  51686. BIO_free(bio);
  51687. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51688. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51689. (void*)passwd));
  51690. BIO_free(bio);
  51691. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  51692. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  51693. if ((bio == NULL) && (f != XBADFILE)) {
  51694. XFCLOSE(f);
  51695. }
  51696. /* use callback that works */
  51697. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51698. (void*)"yassl123"));
  51699. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51700. EVP_PKEY_free(pkey);
  51701. pkey = NULL;
  51702. BIO_free(bio);
  51703. bio = NULL;
  51704. SSL_CTX_free(ctx);
  51705. }
  51706. #endif /* !defined(NO_DES3) */
  51707. #endif /* !NO_BIO */
  51708. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  51709. {
  51710. unsigned char buf[2048];
  51711. size_t bytes = 0;
  51712. XFILE f = XBADFILE;
  51713. SSL_CTX* ctx = NULL;
  51714. #ifndef WOLFSSL_NO_TLS12
  51715. #ifndef NO_WOLFSSL_SERVER
  51716. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51717. #else
  51718. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51719. #endif
  51720. #else
  51721. #ifndef NO_WOLFSSL_SERVER
  51722. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51723. #else
  51724. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51725. #endif
  51726. #endif
  51727. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51728. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  51729. if (f != XBADFILE)
  51730. XFCLOSE(f);
  51731. server_key = buf;
  51732. pkey = NULL;
  51733. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  51734. ExpectNull(pkey);
  51735. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  51736. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51737. EVP_PKEY_free(pkey);
  51738. pkey = NULL;
  51739. SSL_CTX_free(ctx);
  51740. server_key = NULL;
  51741. }
  51742. #endif
  51743. #ifndef NO_BIO
  51744. (void)bio;
  51745. #endif
  51746. (void)pkey;
  51747. (void)server_key;
  51748. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  51749. return EXPECT_RESULT();
  51750. }
  51751. static int test_wolfSSL_PEM_file_RSAKey(void)
  51752. {
  51753. EXPECT_DECLS;
  51754. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51755. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  51756. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  51757. RSA* rsa = NULL;
  51758. XFILE fp = XBADFILE;
  51759. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  51760. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  51761. if (fp != XBADFILE)
  51762. XFCLOSE(fp);
  51763. ExpectIntEQ(RSA_size(rsa), 256);
  51764. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51765. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51766. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  51767. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51768. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51769. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  51770. RSA_free(rsa);
  51771. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51772. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  51773. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  51774. return EXPECT_RESULT();
  51775. }
  51776. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  51777. {
  51778. EXPECT_DECLS;
  51779. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  51780. !defined(NO_FILESYSTEM) && \
  51781. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  51782. RSA* rsa = NULL;
  51783. XFILE f = NULL;
  51784. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  51785. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  51786. ExpectIntEQ(RSA_size(rsa), 256);
  51787. if (f != XBADFILE) {
  51788. XFCLOSE(f);
  51789. f = XBADFILE;
  51790. }
  51791. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  51792. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51793. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  51794. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51795. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  51796. WOLFSSL_SUCCESS);
  51797. RSA_free(rsa);
  51798. #ifdef HAVE_ECC
  51799. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  51800. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  51801. if (f != XBADFILE)
  51802. XFCLOSE(f);
  51803. #endif /* HAVE_ECC */
  51804. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51805. return EXPECT_RESULT();
  51806. }
  51807. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  51808. {
  51809. EXPECT_DECLS;
  51810. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51811. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51812. XFILE file = XBADFILE;
  51813. const char* fname = "./certs/client-keyPub.pem";
  51814. RSA *rsa = NULL;
  51815. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  51816. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51817. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  51818. ExpectIntEQ(RSA_size(rsa), 256);
  51819. RSA_free(rsa);
  51820. if (file != XBADFILE)
  51821. XFCLOSE(file);
  51822. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51823. return EXPECT_RESULT();
  51824. }
  51825. #ifndef NO_BIO
  51826. static int test_wolfSSL_PEM_bio_RSAKey(void)
  51827. {
  51828. EXPECT_DECLS;
  51829. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51830. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  51831. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  51832. RSA* rsa = NULL;
  51833. BIO* bio = NULL;
  51834. /* PrivateKey */
  51835. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  51836. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  51837. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  51838. ExpectNotNull(rsa);
  51839. ExpectIntEQ(RSA_size(rsa), 256);
  51840. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  51841. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51842. BIO_free(bio);
  51843. bio = NULL;
  51844. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51845. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  51846. NULL), WOLFSSL_SUCCESS);
  51847. BIO_free(bio);
  51848. bio = NULL;
  51849. RSA_free(rsa);
  51850. rsa = NULL;
  51851. /* PUBKEY */
  51852. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  51853. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  51854. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51855. ExpectIntEQ(RSA_size(rsa), 256);
  51856. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51857. BIO_free(bio);
  51858. bio = NULL;
  51859. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51860. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  51861. BIO_free(bio);
  51862. bio = NULL;
  51863. RSA_free(rsa);
  51864. rsa = NULL;
  51865. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  51866. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  51867. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51868. BIO_free(bio);
  51869. bio = NULL;
  51870. RSA_free(rsa);
  51871. rsa = NULL;
  51872. #ifdef HAVE_ECC
  51873. /* ensure that non-rsa keys do not work */
  51874. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  51875. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51876. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  51877. BIO_free(bio);
  51878. bio = NULL;
  51879. RSA_free(rsa);
  51880. rsa = NULL;
  51881. #endif /* HAVE_ECC */
  51882. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51883. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  51884. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  51885. return EXPECT_RESULT();
  51886. }
  51887. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  51888. {
  51889. EXPECT_DECLS;
  51890. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51891. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51892. RSA* rsa = NULL;
  51893. RSA* rsa_dup = NULL;
  51894. BIO* bio = NULL;
  51895. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  51896. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51897. ExpectIntEQ(RSA_size(rsa), 256);
  51898. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51899. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  51900. /* Test duplicating empty key. */
  51901. ExpectNotNull(rsa_dup = RSA_new());
  51902. ExpectNull(RSAPublicKey_dup(rsa_dup));
  51903. RSA_free(rsa_dup);
  51904. rsa_dup = NULL;
  51905. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  51906. ExpectPtrNE(rsa_dup, rsa);
  51907. #endif
  51908. /* test if valgrind complains about unreleased memory */
  51909. RSA_up_ref(rsa);
  51910. RSA_free(rsa);
  51911. BIO_free(bio);
  51912. bio = NULL;
  51913. RSA_free(rsa);
  51914. rsa = NULL;
  51915. RSA_free(rsa_dup);
  51916. rsa_dup = NULL;
  51917. #ifdef HAVE_ECC
  51918. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  51919. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  51920. BIO_free(bio);
  51921. #endif /* HAVE_ECC */
  51922. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51923. return EXPECT_RESULT();
  51924. }
  51925. static int test_wolfSSL_PEM_bio_DSAKey(void)
  51926. {
  51927. EXPECT_DECLS;
  51928. #ifndef HAVE_SELFTEST
  51929. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  51930. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  51931. DSA* dsa = NULL;
  51932. BIO* bio = NULL;
  51933. /* PrivateKey */
  51934. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  51935. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  51936. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  51937. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  51938. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  51939. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51940. BIO_free(bio);
  51941. bio = NULL;
  51942. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51943. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  51944. NULL), WOLFSSL_SUCCESS);
  51945. BIO_free(bio);
  51946. bio = NULL;
  51947. DSA_free(dsa);
  51948. dsa = NULL;
  51949. /* PUBKEY */
  51950. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  51951. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  51952. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  51953. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  51954. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51955. BIO_free(bio);
  51956. bio = NULL;
  51957. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51958. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  51959. BIO_free(bio);
  51960. bio = NULL;
  51961. DSA_free(dsa);
  51962. dsa = NULL;
  51963. #ifdef HAVE_ECC
  51964. /* ensure that non-dsa keys do not work */
  51965. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  51966. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  51967. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  51968. BIO_free(bio);
  51969. bio = NULL;
  51970. DSA_free(dsa);
  51971. dsa = NULL;
  51972. #endif /* HAVE_ECC */
  51973. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  51974. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  51975. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  51976. #endif /* HAVE_SELFTEST */
  51977. return EXPECT_RESULT();
  51978. }
  51979. static int test_wolfSSL_PEM_bio_ECKey(void)
  51980. {
  51981. EXPECT_DECLS;
  51982. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  51983. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  51984. EC_KEY* ec = NULL;
  51985. EC_KEY* ec2;
  51986. BIO* bio = NULL;
  51987. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  51988. unsigned char* pem = NULL;
  51989. int pLen;
  51990. #endif
  51991. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  51992. "MAA=\n"
  51993. "-----END PUBLIC KEY-----";
  51994. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  51995. "MAA=\n"
  51996. "-----END EC PRIVATE KEY-----";
  51997. /* PrivateKey */
  51998. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  51999. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  52000. ec2 = NULL;
  52001. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  52002. ExpectIntEQ(ec == ec2, 1);
  52003. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52004. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  52005. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52006. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  52007. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52008. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  52009. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52010. BIO_free(bio);
  52011. bio = NULL;
  52012. /* Public key data - fail. */
  52013. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52014. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52015. BIO_free(bio);
  52016. bio = NULL;
  52017. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52018. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  52019. NULL), WOLFSSL_SUCCESS);
  52020. BIO_free(bio);
  52021. bio = NULL;
  52022. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  52023. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52024. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  52025. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52026. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  52027. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52028. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  52029. WOLFSSL_SUCCESS);
  52030. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52031. NULL), 0);
  52032. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  52033. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52034. NULL), 0);
  52035. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52036. NULL), 0);
  52037. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52038. &pLen), 0);
  52039. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52040. &pLen), 0);
  52041. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52042. &pLen), 0);
  52043. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52044. NULL), 0);
  52045. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52046. &pLen), 1);
  52047. ExpectIntGT(pLen, 0);
  52048. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  52049. #endif
  52050. EC_KEY_free(ec);
  52051. ec = NULL;
  52052. /* PUBKEY */
  52053. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52054. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  52055. ec2 = NULL;
  52056. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  52057. ExpectIntEQ(ec == ec2, 1);
  52058. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52059. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52060. BIO_free(bio);
  52061. bio = NULL;
  52062. /* Test 0x30, 0x00 fails. */
  52063. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  52064. sizeof(ec_key_bad_1)));
  52065. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52066. BIO_free(bio);
  52067. bio = NULL;
  52068. /* Private key data - fail. */
  52069. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  52070. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52071. BIO_free(bio);
  52072. bio = NULL;
  52073. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52074. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  52075. BIO_free(bio);
  52076. bio = NULL;
  52077. /* Same test as above, but with a file pointer rather than a BIO. */
  52078. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52079. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52080. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52081. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  52082. EC_KEY_free(ec);
  52083. ec = NULL;
  52084. #ifndef NO_RSA
  52085. /* ensure that non-ec keys do not work */
  52086. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  52087. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  52088. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  52089. BIO_free(bio);
  52090. bio = NULL;
  52091. EC_KEY_free(ec);
  52092. ec = NULL;
  52093. #endif /* !NO_RSA */
  52094. /* Test 0x30, 0x00 fails. */
  52095. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  52096. sizeof(ec_priv_key_bad_1)));
  52097. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52098. BIO_free(bio);
  52099. bio = NULL;
  52100. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52101. return EXPECT_RESULT();
  52102. }
  52103. static int test_wolfSSL_PEM_PUBKEY(void)
  52104. {
  52105. EXPECT_DECLS;
  52106. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  52107. BIO* bio = NULL;
  52108. EVP_PKEY* pkey = NULL;
  52109. /* test creating new EVP_PKEY with bad arg */
  52110. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  52111. /* test loading ECC key using BIO */
  52112. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  52113. {
  52114. XFILE file = XBADFILE;
  52115. const char* fname = "./certs/ecc-client-keyPub.pem";
  52116. size_t sz = 0;
  52117. byte* buf = NULL;
  52118. EVP_PKEY* pkey2 = NULL;
  52119. EC_KEY* ec_key = NULL;
  52120. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52121. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  52122. ExpectIntGT(sz = XFTELL(file), 0);
  52123. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  52124. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52125. if (buf != NULL) {
  52126. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52127. }
  52128. if (file != XBADFILE) {
  52129. XFCLOSE(file);
  52130. }
  52131. /* Test using BIO new mem and loading PEM private key */
  52132. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52133. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  52134. BIO_free(bio);
  52135. bio = NULL;
  52136. EVP_PKEY_free(pkey);
  52137. pkey = NULL;
  52138. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52139. ExpectNotNull(pkey = EVP_PKEY_new());
  52140. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  52141. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52142. BIO_free(bio);
  52143. bio = NULL;
  52144. /* Qt unit test case*/
  52145. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52146. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52147. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  52148. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52149. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  52150. #else
  52151. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  52152. #endif
  52153. EC_KEY_free(ec_key);
  52154. EVP_PKEY_free(pkey2);
  52155. EVP_PKEY_free(pkey);
  52156. pkey = NULL;
  52157. }
  52158. #endif
  52159. (void)bio;
  52160. (void)pkey;
  52161. #endif
  52162. return EXPECT_RESULT();
  52163. }
  52164. #endif /* !NO_BIO */
  52165. static int test_DSA_do_sign_verify(void)
  52166. {
  52167. EXPECT_DECLS;
  52168. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  52169. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  52170. !defined(NO_DSA)
  52171. unsigned char digest[WC_SHA_DIGEST_SIZE];
  52172. DSA_SIG* sig = NULL;
  52173. DSA* dsa = NULL;
  52174. word32 bytes;
  52175. byte sigBin[DSA_SIG_SIZE];
  52176. int dsacheck;
  52177. #ifdef USE_CERT_BUFFERS_1024
  52178. byte tmp[ONEK_BUF];
  52179. XMEMSET(tmp, 0, sizeof(tmp));
  52180. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  52181. bytes = sizeof_dsa_key_der_1024;
  52182. #elif defined(USE_CERT_BUFFERS_2048)
  52183. byte tmp[TWOK_BUF];
  52184. XMEMSET(tmp, 0, sizeof(tmp));
  52185. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  52186. bytes = sizeof_dsa_key_der_2048;
  52187. #else
  52188. byte tmp[TWOK_BUF];
  52189. XFILE fp = XBADFILE;
  52190. XMEMSET(tmp, 0, sizeof(tmp));
  52191. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  52192. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  52193. if (fp != XBADFILE)
  52194. XFCLOSE(fp);
  52195. #endif /* END USE_CERT_BUFFERS_1024 */
  52196. XMEMSET(digest, 202, sizeof(digest));
  52197. ExpectNotNull(dsa = DSA_new());
  52198. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  52199. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  52200. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  52201. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  52202. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  52203. DSA_SIG_free(sig);
  52204. DSA_free(dsa);
  52205. #endif
  52206. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  52207. return EXPECT_RESULT();
  52208. }
  52209. static int test_wolfSSL_tmp_dh(void)
  52210. {
  52211. EXPECT_DECLS;
  52212. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  52213. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  52214. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  52215. byte buff[6000];
  52216. static const unsigned char p[] = {
  52217. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52218. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52219. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52220. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52221. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52222. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52223. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52224. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52225. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52226. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52227. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52228. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52229. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52230. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52231. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52232. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52233. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52234. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52235. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52236. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52237. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52238. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52239. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52240. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52241. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52242. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52243. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52244. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52245. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52246. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52247. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52248. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  52249. };
  52250. int pSz = (int)sizeof(p);
  52251. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52252. !defined(HAVE_SELFTEST)
  52253. static const unsigned char bad_p[] = {
  52254. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52255. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52256. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52257. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52258. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52259. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52260. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52261. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52262. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52263. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52264. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52265. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52266. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52267. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52268. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52269. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52270. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52271. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52272. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52273. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52274. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52275. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52276. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52277. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52278. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52279. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52280. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52281. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52282. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52283. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52284. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52285. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  52286. };
  52287. #endif
  52288. static const unsigned char g[] = { 0x02 };
  52289. int gSz = (int)sizeof(g);
  52290. #if !defined(NO_DSA)
  52291. char file[] = "./certs/dsaparams.pem";
  52292. DSA* dsa = NULL;
  52293. #else
  52294. char file[] = "./certs/dh2048.pem";
  52295. #endif
  52296. XFILE f = XBADFILE;
  52297. int bytes = 0;
  52298. DH* dh = NULL;
  52299. DH* dh2 = NULL;
  52300. BIO* bio = NULL;
  52301. SSL* ssl = NULL;
  52302. SSL_CTX* ctx = NULL;
  52303. #ifndef NO_WOLFSSL_CLIENT
  52304. SSL* ssl_c = NULL;
  52305. SSL_CTX* ctx_c = NULL;
  52306. #endif
  52307. #ifndef NO_WOLFSSL_SERVER
  52308. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52309. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  52310. WOLFSSL_FILETYPE_PEM));
  52311. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  52312. WOLFSSL_FILETYPE_PEM));
  52313. ExpectNotNull(ssl = SSL_new(ctx));
  52314. #endif
  52315. #ifndef NO_WOLFSSL_CLIENT
  52316. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  52317. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  52318. WOLFSSL_FILETYPE_PEM));
  52319. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  52320. WOLFSSL_FILETYPE_PEM));
  52321. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  52322. #ifdef NO_WOLFSSL_SERVER
  52323. ctx = ctx_c;
  52324. ssl = ssl_c;
  52325. #endif
  52326. #endif
  52327. XMEMSET(buff, 0, sizeof(buff));
  52328. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  52329. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  52330. if (f != XBADFILE)
  52331. XFCLOSE(f);
  52332. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52333. #if !defined(NO_DSA)
  52334. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  52335. ExpectNotNull(dsa);
  52336. dh = wolfSSL_DSA_dup_DH(dsa);
  52337. #else
  52338. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  52339. #endif
  52340. ExpectNotNull(dh);
  52341. #if defined(WOLFSSL_DH_EXTRA) && \
  52342. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  52343. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  52344. DH_free(dh2);
  52345. dh2 = NULL;
  52346. #endif
  52347. /* Failure cases */
  52348. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52349. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52350. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  52351. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52352. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  52353. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52354. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  52355. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52356. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  52357. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52358. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  52359. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52360. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  52361. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52362. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  52363. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52364. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  52365. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52366. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52367. !defined(HAVE_SELFTEST)
  52368. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  52369. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  52370. #endif
  52371. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52372. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52373. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  52374. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52375. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  52376. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52377. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  52378. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52379. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  52380. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52381. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  52382. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52383. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  52384. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52385. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  52386. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52387. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  52388. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52389. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52390. !defined(HAVE_SELFTEST)
  52391. #ifndef NO_WOLFSSL_SERVER
  52392. /* Parameters will be tested later so it passes now. */
  52393. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  52394. WOLFSSL_SUCCESS);
  52395. #endif
  52396. #endif
  52397. #ifndef NO_WOLFSSL_CLIENT
  52398. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  52399. WC_NO_ERR_TRACE(SIDE_ERROR));
  52400. #endif
  52401. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52402. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52403. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52404. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52405. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52406. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52407. /* No p/g to use. */
  52408. dh2 = wolfSSL_DH_new();
  52409. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52410. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52411. DH_free(dh2);
  52412. dh2 = NULL;
  52413. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  52414. WOLFSSL_SUCCESS);
  52415. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  52416. #ifndef NO_WOLFSSL_SERVER
  52417. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  52418. #else
  52419. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  52420. #endif
  52421. BIO_free(bio);
  52422. #if !defined(NO_DSA)
  52423. DSA_free(dsa);
  52424. #endif
  52425. DH_free(dh);
  52426. dh = NULL;
  52427. #ifndef NO_WOLFSSL_CLIENT
  52428. if (ssl != ssl_c) {
  52429. SSL_free(ssl_c);
  52430. }
  52431. #endif
  52432. SSL_free(ssl);
  52433. #ifndef NO_WOLFSSL_CLIENT
  52434. if (ctx != ctx_c) {
  52435. SSL_CTX_free(ctx_c);
  52436. }
  52437. #endif
  52438. SSL_CTX_free(ctx);
  52439. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52440. #endif
  52441. return EXPECT_RESULT();
  52442. }
  52443. static int test_wolfSSL_ctrl(void)
  52444. {
  52445. EXPECT_DECLS;
  52446. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  52447. byte buff[6000];
  52448. BIO* bio = NULL;
  52449. int bytes;
  52450. BUF_MEM* ptr = NULL;
  52451. XMEMSET(buff, 0, sizeof(buff));
  52452. bytes = sizeof(buff);
  52453. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52454. ExpectNotNull(BIO_s_socket());
  52455. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  52456. /* needs tested after stubs filled out @TODO
  52457. SSL_ctrl
  52458. SSL_CTX_ctrl
  52459. */
  52460. BIO_free(bio);
  52461. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  52462. return EXPECT_RESULT();
  52463. }
  52464. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  52465. {
  52466. EXPECT_DECLS;
  52467. #ifdef OPENSSL_EXTRA
  52468. static const unsigned char pw[] = "password";
  52469. static const int pwSz = sizeof(pw) - 1;
  52470. size_t checkPwSz = 0;
  52471. const unsigned char* checkPw = NULL;
  52472. WOLFSSL_EVP_PKEY* key = NULL;
  52473. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  52474. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  52475. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52476. pwSz));
  52477. if (key != NULL) {
  52478. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  52479. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  52480. ExpectIntEQ(key->pkey_sz, pwSz);
  52481. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  52482. }
  52483. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  52484. ExpectIntEQ((int)checkPwSz, pwSz);
  52485. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  52486. wolfSSL_EVP_PKEY_free(key);
  52487. key = NULL;
  52488. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52489. 0));
  52490. ExpectIntEQ(key->pkey_sz, 0);
  52491. if (EXPECT_SUCCESS()) {
  52492. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52493. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52494. }
  52495. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52496. ExpectIntEQ((int)checkPwSz, 0);
  52497. wolfSSL_EVP_PKEY_free(key);
  52498. key = NULL;
  52499. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  52500. 0));
  52501. ExpectIntEQ(key->pkey_sz, 0);
  52502. if (EXPECT_SUCCESS()) {
  52503. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52504. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52505. }
  52506. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52507. ExpectIntEQ((int)checkPwSz, 0);
  52508. wolfSSL_EVP_PKEY_free(key);
  52509. key = NULL;
  52510. #endif /* OPENSSL_EXTRA */
  52511. return EXPECT_RESULT();
  52512. }
  52513. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  52514. {
  52515. EXPECT_DECLS;
  52516. #ifdef OPENSSL_EXTRA
  52517. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  52518. const char *priv = "ABCDEFGHIJKLMNOP";
  52519. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  52520. WOLFSSL_EVP_PKEY* key = NULL;
  52521. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52522. NULL, NULL, AES_128_KEY_SIZE, cipher));
  52523. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52524. NULL, (const unsigned char *)priv, 0, cipher));
  52525. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52526. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  52527. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52528. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  52529. wolfSSL_EVP_PKEY_free(key);
  52530. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  52531. #endif /* OPENSSL_EXTRA */
  52532. return EXPECT_RESULT();
  52533. }
  52534. static int test_wolfSSL_EVP_Digest(void)
  52535. {
  52536. EXPECT_DECLS;
  52537. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  52538. const char* in = "abc";
  52539. int inLen = (int)XSTRLEN(in);
  52540. byte out[WC_SHA256_DIGEST_SIZE];
  52541. unsigned int outLen;
  52542. const char* expOut =
  52543. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  52544. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  52545. "\x15\xAD";
  52546. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  52547. "SHA256", NULL), 1);
  52548. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  52549. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  52550. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  52551. return EXPECT_RESULT();
  52552. }
  52553. static int test_wolfSSL_EVP_Digest_all(void)
  52554. {
  52555. EXPECT_DECLS;
  52556. #ifdef OPENSSL_EXTRA
  52557. const char* digests[] = {
  52558. #ifndef NO_MD5
  52559. "MD5",
  52560. #endif
  52561. #ifndef NO_SHA
  52562. "SHA",
  52563. #endif
  52564. #ifdef WOLFSSL_SHA224
  52565. "SHA224",
  52566. #endif
  52567. #ifndef NO_SHA256
  52568. "SHA256",
  52569. #endif
  52570. #ifdef WOLFSSL_SHA384
  52571. "SHA384",
  52572. #endif
  52573. #ifdef WOLFSSL_SHA512
  52574. "SHA512",
  52575. #endif
  52576. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  52577. "SHA512_224",
  52578. #endif
  52579. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  52580. "SHA512_256",
  52581. #endif
  52582. #ifdef WOLFSSL_SHA3
  52583. #ifndef WOLFSSL_NOSHA3_224
  52584. "SHA3_224",
  52585. #endif
  52586. #ifndef WOLFSSL_NOSHA3_256
  52587. "SHA3_256",
  52588. #endif
  52589. "SHA3_384",
  52590. #ifndef WOLFSSL_NOSHA3_512
  52591. "SHA3_512",
  52592. #endif
  52593. #endif /* WOLFSSL_SHA3 */
  52594. NULL
  52595. };
  52596. const char** d;
  52597. const unsigned char in[] = "abc";
  52598. int inLen = XSTR_SIZEOF(in);
  52599. byte out[WC_MAX_DIGEST_SIZE];
  52600. unsigned int outLen;
  52601. for (d = digests; *d != NULL; d++) {
  52602. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  52603. ExpectIntGT(outLen, 0);
  52604. ExpectIntEQ(EVP_MD_size(*d), outLen);
  52605. }
  52606. #endif
  52607. return EXPECT_RESULT();
  52608. }
  52609. static int test_wolfSSL_EVP_MD_size(void)
  52610. {
  52611. EXPECT_DECLS;
  52612. #ifdef OPENSSL_EXTRA
  52613. WOLFSSL_EVP_MD_CTX mdCtx;
  52614. #ifdef WOLFSSL_SHA3
  52615. #ifndef WOLFSSL_NOSHA3_224
  52616. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52617. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  52618. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  52619. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  52620. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52621. #endif
  52622. #ifndef WOLFSSL_NOSHA3_256
  52623. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52624. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  52625. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  52626. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  52627. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52628. #endif
  52629. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52630. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  52631. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  52632. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  52633. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52634. #ifndef WOLFSSL_NOSHA3_512
  52635. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52636. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  52637. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  52638. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  52639. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52640. #endif
  52641. #endif /* WOLFSSL_SHA3 */
  52642. #ifndef NO_SHA256
  52643. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52644. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  52645. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52646. WC_SHA256_DIGEST_SIZE);
  52647. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52648. WC_SHA256_BLOCK_SIZE);
  52649. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  52650. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  52651. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52652. #endif
  52653. #ifndef NO_MD5
  52654. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52655. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  52656. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52657. WC_MD5_DIGEST_SIZE);
  52658. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52659. WC_MD5_BLOCK_SIZE);
  52660. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  52661. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  52662. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52663. #endif
  52664. #ifdef WOLFSSL_SHA224
  52665. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52666. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  52667. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52668. WC_SHA224_DIGEST_SIZE);
  52669. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52670. WC_SHA224_BLOCK_SIZE);
  52671. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  52672. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  52673. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52674. #endif
  52675. #ifdef WOLFSSL_SHA384
  52676. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52677. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  52678. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52679. WC_SHA384_DIGEST_SIZE);
  52680. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52681. WC_SHA384_BLOCK_SIZE);
  52682. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  52683. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  52684. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52685. #endif
  52686. #ifdef WOLFSSL_SHA512
  52687. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52688. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  52689. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52690. WC_SHA512_DIGEST_SIZE);
  52691. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52692. WC_SHA512_BLOCK_SIZE);
  52693. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  52694. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  52695. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52696. #endif
  52697. #ifndef NO_SHA
  52698. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52699. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  52700. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52701. WC_SHA_DIGEST_SIZE);
  52702. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52703. WC_SHA_BLOCK_SIZE);
  52704. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52705. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52706. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52707. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52708. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  52709. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52710. WC_SHA_DIGEST_SIZE);
  52711. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52712. WC_SHA_BLOCK_SIZE);
  52713. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52714. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52715. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52716. #endif
  52717. /* error case */
  52718. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52719. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  52720. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  52721. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  52722. /* Cleanup is valid on uninit'ed struct */
  52723. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52724. #endif /* OPENSSL_EXTRA */
  52725. return EXPECT_RESULT();
  52726. }
  52727. static int test_wolfSSL_EVP_MD_pkey_type(void)
  52728. {
  52729. EXPECT_DECLS;
  52730. #ifdef OPENSSL_EXTRA
  52731. const WOLFSSL_EVP_MD* md;
  52732. #ifndef NO_MD5
  52733. ExpectNotNull(md = EVP_md5());
  52734. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  52735. #endif
  52736. #ifndef NO_SHA
  52737. ExpectNotNull(md = EVP_sha1());
  52738. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  52739. #endif
  52740. #ifdef WOLFSSL_SHA224
  52741. ExpectNotNull(md = EVP_sha224());
  52742. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  52743. #endif
  52744. ExpectNotNull(md = EVP_sha256());
  52745. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  52746. #ifdef WOLFSSL_SHA384
  52747. ExpectNotNull(md = EVP_sha384());
  52748. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  52749. #endif
  52750. #ifdef WOLFSSL_SHA512
  52751. ExpectNotNull(md = EVP_sha512());
  52752. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  52753. #endif
  52754. #endif
  52755. return EXPECT_RESULT();
  52756. }
  52757. #ifdef OPENSSL_EXTRA
  52758. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  52759. size_t testKeySz, const char* testData, size_t testDataSz,
  52760. const byte* testResult, size_t testResultSz)
  52761. {
  52762. EXPECT_DECLS;
  52763. unsigned char check[WC_MAX_DIGEST_SIZE];
  52764. size_t checkSz = -1;
  52765. WOLFSSL_EVP_PKEY* key = NULL;
  52766. WOLFSSL_EVP_MD_CTX mdCtx;
  52767. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  52768. testKey, (int)testKeySz));
  52769. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52770. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  52771. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52772. (unsigned int)testDataSz), 1);
  52773. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52774. ExpectIntEQ((int)checkSz, (int)testResultSz);
  52775. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52776. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52777. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  52778. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52779. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  52780. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52781. (unsigned int)testDataSz), 1);
  52782. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  52783. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52784. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52785. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  52786. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  52787. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52788. ExpectIntEQ((int)checkSz, (int)testResultSz);
  52789. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52790. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52791. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  52792. (unsigned int)testDataSz - 4), 1);
  52793. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52794. ExpectIntEQ((int)checkSz,(int)testResultSz);
  52795. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  52796. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52797. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  52798. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  52799. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  52800. (unsigned int)testDataSz - 4), 1);
  52801. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  52802. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52803. wolfSSL_EVP_PKEY_free(key);
  52804. return EXPECT_RESULT();
  52805. }
  52806. #endif
  52807. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  52808. {
  52809. EXPECT_DECLS;
  52810. #ifdef OPENSSL_EXTRA
  52811. static const unsigned char testKey[] =
  52812. {
  52813. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  52814. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  52815. 0x0b, 0x0b, 0x0b, 0x0b
  52816. };
  52817. static const char testData[] = "Hi There";
  52818. #ifdef WOLFSSL_SHA224
  52819. static const unsigned char testResultSha224[] =
  52820. {
  52821. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  52822. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  52823. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  52824. 0x53, 0x68, 0x4b, 0x22
  52825. };
  52826. #endif
  52827. #ifndef NO_SHA256
  52828. static const unsigned char testResultSha256[] =
  52829. {
  52830. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  52831. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  52832. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  52833. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  52834. };
  52835. #endif
  52836. #ifdef WOLFSSL_SHA384
  52837. static const unsigned char testResultSha384[] =
  52838. {
  52839. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  52840. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  52841. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  52842. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  52843. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  52844. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  52845. };
  52846. #endif
  52847. #ifdef WOLFSSL_SHA512
  52848. static const unsigned char testResultSha512[] =
  52849. {
  52850. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  52851. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  52852. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  52853. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  52854. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  52855. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  52856. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  52857. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  52858. };
  52859. #endif
  52860. #ifdef WOLFSSL_SHA3
  52861. #ifndef WOLFSSL_NOSHA3_224
  52862. static const unsigned char testResultSha3_224[] =
  52863. {
  52864. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  52865. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  52866. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  52867. 0xf3, 0xc8, 0x60, 0xf7
  52868. };
  52869. #endif
  52870. #ifndef WOLFSSL_NOSHA3_256
  52871. static const unsigned char testResultSha3_256[] =
  52872. {
  52873. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  52874. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  52875. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  52876. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  52877. };
  52878. #endif
  52879. #ifndef WOLFSSL_NOSHA3_384
  52880. static const unsigned char testResultSha3_384[] =
  52881. {
  52882. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  52883. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  52884. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  52885. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  52886. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  52887. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  52888. };
  52889. #endif
  52890. #ifndef WOLFSSL_NOSHA3_512
  52891. static const unsigned char testResultSha3_512[] =
  52892. {
  52893. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  52894. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  52895. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  52896. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  52897. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  52898. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  52899. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  52900. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  52901. };
  52902. #endif
  52903. #endif
  52904. #ifndef NO_SHA256
  52905. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  52906. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  52907. sizeof(testResultSha256)), TEST_SUCCESS);
  52908. #endif
  52909. #ifdef WOLFSSL_SHA224
  52910. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  52911. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  52912. sizeof(testResultSha224)), TEST_SUCCESS);
  52913. #endif
  52914. #ifdef WOLFSSL_SHA384
  52915. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  52916. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  52917. sizeof(testResultSha384)), TEST_SUCCESS);
  52918. #endif
  52919. #ifdef WOLFSSL_SHA512
  52920. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  52921. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  52922. sizeof(testResultSha512)), TEST_SUCCESS);
  52923. #endif
  52924. #ifdef WOLFSSL_SHA3
  52925. #ifndef WOLFSSL_NOSHA3_224
  52926. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  52927. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  52928. sizeof(testResultSha3_224)), TEST_SUCCESS);
  52929. #endif
  52930. #ifndef WOLFSSL_NOSHA3_256
  52931. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  52932. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  52933. sizeof(testResultSha3_256)), TEST_SUCCESS);
  52934. #endif
  52935. #ifndef WOLFSSL_NOSHA3_384
  52936. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  52937. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  52938. sizeof(testResultSha3_384)), TEST_SUCCESS);
  52939. #endif
  52940. #ifndef WOLFSSL_NOSHA3_512
  52941. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  52942. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  52943. sizeof(testResultSha3_512)), TEST_SUCCESS);
  52944. #endif
  52945. #endif
  52946. #endif /* OPENSSL_EXTRA */
  52947. return EXPECT_RESULT();
  52948. }
  52949. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  52950. {
  52951. EXPECT_DECLS;
  52952. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  52953. WOLFSSL_EVP_PKEY* privKey = NULL;
  52954. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52955. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  52956. const char testData[] = "Hi There";
  52957. WOLFSSL_EVP_MD_CTX mdCtx;
  52958. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  52959. int ret;
  52960. size_t checkSz = -1;
  52961. int sz = 2048 / 8;
  52962. const unsigned char* cp;
  52963. const unsigned char* p;
  52964. unsigned char check[2048/8];
  52965. size_t i;
  52966. int paddings[] = {
  52967. RSA_PKCS1_PADDING,
  52968. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  52969. RSA_PKCS1_PSS_PADDING,
  52970. #endif
  52971. };
  52972. cp = client_key_der_2048;
  52973. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  52974. sizeof_client_key_der_2048)));
  52975. p = client_keypub_der_2048;
  52976. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  52977. sizeof_client_keypub_der_2048)));
  52978. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52979. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  52980. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52981. NULL, privKey), 1);
  52982. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  52983. (unsigned int)XSTRLEN(testData)), 1);
  52984. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  52985. ExpectIntEQ((int)checkSz, sz);
  52986. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  52987. ExpectIntEQ((int)checkSz,sz);
  52988. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  52989. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  52990. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  52991. ExpectIntEQ(ret, 1);
  52992. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52993. ExpectIntEQ(ret, 1);
  52994. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52995. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  52996. NULL, pubKey), 1);
  52997. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  52998. (unsigned int)XSTRLEN(testData)),
  52999. 1);
  53000. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53001. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53002. ExpectIntEQ(ret, 1);
  53003. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53004. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53005. NULL, privKey), 1);
  53006. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53007. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53008. ExpectIntEQ((int)checkSz, sz);
  53009. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53010. ExpectIntEQ((int)checkSz, sz);
  53011. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53012. (unsigned int)XSTRLEN(testData) - 4), 1);
  53013. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53014. ExpectIntEQ((int)checkSz, sz);
  53015. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53016. ExpectIntEQ(ret, 1);
  53017. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53018. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53019. NULL, pubKey), 1);
  53020. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53021. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53022. (unsigned int)XSTRLEN(testData) - 4),
  53023. 1);
  53024. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53025. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53026. ExpectIntEQ(ret, 1);
  53027. /* Check all signing padding types */
  53028. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  53029. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53030. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  53031. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  53032. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53033. paddings[i]), 1);
  53034. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53035. (unsigned int)XSTRLEN(testData)), 1);
  53036. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53037. ExpectIntEQ((int)checkSz, sz);
  53038. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53039. ExpectIntEQ((int)checkSz,sz);
  53040. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53041. ExpectIntEQ(ret, 1);
  53042. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53043. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  53044. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  53045. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53046. paddings[i]), 1);
  53047. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53048. (unsigned int)XSTRLEN(testData)), 1);
  53049. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53050. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53051. ExpectIntEQ(ret, 1);
  53052. }
  53053. wolfSSL_EVP_PKEY_free(pubKey);
  53054. wolfSSL_EVP_PKEY_free(privKey);
  53055. #endif
  53056. return EXPECT_RESULT();
  53057. }
  53058. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  53059. {
  53060. EXPECT_DECLS;
  53061. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  53062. WOLFSSL_EVP_PKEY* privKey = NULL;
  53063. WOLFSSL_EVP_PKEY* pubKey = NULL;
  53064. const char testData[] = "Hi There";
  53065. WOLFSSL_EVP_MD_CTX mdCtx;
  53066. int ret;
  53067. size_t checkSz = -1;
  53068. const unsigned char* cp;
  53069. const unsigned char* p;
  53070. unsigned char check[2048/8];
  53071. cp = ecc_clikey_der_256;
  53072. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  53073. sizeof_ecc_clikey_der_256));
  53074. p = ecc_clikeypub_der_256;
  53075. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  53076. sizeof_ecc_clikeypub_der_256)));
  53077. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53078. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53079. NULL, privKey), 1);
  53080. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53081. (unsigned int)XSTRLEN(testData)), 1);
  53082. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53083. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53084. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53085. ExpectIntEQ(ret, 1);
  53086. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53087. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53088. NULL, pubKey), 1);
  53089. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53090. (unsigned int)XSTRLEN(testData)),
  53091. 1);
  53092. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53093. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53094. ExpectIntEQ(ret, 1);
  53095. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53096. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53097. NULL, privKey), 1);
  53098. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53099. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53100. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53101. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53102. (unsigned int)XSTRLEN(testData) - 4), 1);
  53103. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53104. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53105. ExpectIntEQ(ret, 1);
  53106. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53107. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53108. NULL, pubKey), 1);
  53109. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53110. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53111. (unsigned int)XSTRLEN(testData) - 4),
  53112. 1);
  53113. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53114. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53115. ExpectIntEQ(ret, 1);
  53116. wolfSSL_EVP_PKEY_free(pubKey);
  53117. wolfSSL_EVP_PKEY_free(privKey);
  53118. #endif
  53119. return EXPECT_RESULT();
  53120. }
  53121. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  53122. {
  53123. EXPECT_DECLS;
  53124. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53125. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  53126. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53127. char caFile[] = "./certs/client-ca.pem";
  53128. char clientFile[] = "./certs/client-cert.pem";
  53129. SSL_CTX* ctx = NULL;
  53130. X509* x509 = NULL;
  53131. BIO *bio = NULL;
  53132. X509 *cert = NULL;
  53133. X509 *ca = NULL;
  53134. STACK_OF(X509) *chain = NULL;
  53135. STACK_OF(X509) *chain2 = NULL;
  53136. #ifndef NO_WOLFSSL_SERVER
  53137. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53138. #else
  53139. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53140. #endif
  53141. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  53142. WOLFSSL_FILETYPE_PEM));
  53143. /* Negative tests. */
  53144. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53145. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53146. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53147. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  53148. ExpectNotNull(x509 = wolfSSL_X509_new());
  53149. /* Empty certificate. */
  53150. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53151. wolfSSL_X509_free(x509);
  53152. x509 = NULL;
  53153. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  53154. WOLFSSL_FILETYPE_PEM));
  53155. /* additional test of getting EVP_PKEY key size from X509
  53156. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  53157. * allowed with user RSA */
  53158. {
  53159. EVP_PKEY* pkey = NULL;
  53160. #if defined(HAVE_ECC)
  53161. X509* ecX509 = NULL;
  53162. #endif /* HAVE_ECC */
  53163. ExpectNotNull(pkey = X509_get_pubkey(x509));
  53164. /* current RSA key is 2048 bit (256 bytes) */
  53165. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  53166. EVP_PKEY_free(pkey);
  53167. pkey = NULL;
  53168. #if defined(HAVE_ECC)
  53169. #if defined(USE_CERT_BUFFERS_256)
  53170. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  53171. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  53172. SSL_FILETYPE_ASN1));
  53173. #else
  53174. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  53175. cliEccCertFile, SSL_FILETYPE_PEM));
  53176. #endif
  53177. pkey = X509_get_pubkey(ecX509);
  53178. ExpectNotNull(pkey);
  53179. /* current ECC key is 256 bit (32 bytes) */
  53180. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  53181. X509_free(ecX509);
  53182. ecX509 = NULL;
  53183. EVP_PKEY_free(pkey);
  53184. pkey = NULL;
  53185. #endif /* HAVE_ECC */
  53186. }
  53187. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  53188. if (EXPECT_SUCCESS()) {
  53189. x509 = NULL;
  53190. }
  53191. #ifdef WOLFSSL_ENCRYPTED_KEYS
  53192. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  53193. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  53194. #endif
  53195. SSL_CTX_free(ctx);
  53196. ctx = NULL;
  53197. #ifndef NO_WOLFSSL_SERVER
  53198. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53199. #else
  53200. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53201. #endif
  53202. /* Test haproxy use case */
  53203. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  53204. /* Read Certificate */
  53205. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  53206. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  53207. ExpectNotNull(chain = sk_X509_new_null());
  53208. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  53209. if (EXPECT_SUCCESS()) {
  53210. ca = NULL;
  53211. }
  53212. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  53213. ExpectNotNull(ca = sk_X509_shift(chain2));
  53214. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  53215. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  53216. if (EXPECT_SUCCESS()) {
  53217. ca = NULL;
  53218. }
  53219. BIO_free(bio);
  53220. X509_free(cert);
  53221. X509_free(ca);
  53222. X509_free(x509);
  53223. sk_X509_pop_free(chain, X509_free);
  53224. sk_X509_pop_free(chain2, X509_free);
  53225. SSL_CTX_free(ctx);
  53226. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53227. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53228. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  53229. return EXPECT_RESULT();
  53230. }
  53231. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  53232. static int test_wolfSSL_ERR_peek_last_error_line(void)
  53233. {
  53234. EXPECT_DECLS;
  53235. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53236. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  53237. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  53238. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  53239. callback_functions client_cb;
  53240. callback_functions server_cb;
  53241. int line = 0;
  53242. int flag = ERR_TXT_STRING;
  53243. const char* file = NULL;
  53244. const char* data = NULL;
  53245. /* create a failed connection and inspect the error */
  53246. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53247. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53248. client_cb.method = wolfTLSv1_1_client_method;
  53249. server_cb.method = wolfTLSv1_2_server_method;
  53250. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53251. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  53252. ExpectNotNull(data);
  53253. /* check clearing error state */
  53254. ERR_remove_state(0);
  53255. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53256. ERR_peek_last_error_line(NULL, &line);
  53257. ExpectIntEQ(line, 0);
  53258. ERR_peek_last_error_line(&file, NULL);
  53259. ExpectNull(file);
  53260. /* retry connection to fill error queue */
  53261. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53262. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53263. client_cb.method = wolfTLSv1_1_client_method;
  53264. server_cb.method = wolfTLSv1_2_server_method;
  53265. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53266. /* check that error code was stored */
  53267. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53268. ERR_peek_last_error_line(NULL, &line);
  53269. ExpectIntNE(line, 0);
  53270. ERR_peek_last_error_line(&file, NULL);
  53271. ExpectNotNull(file);
  53272. fprintf(stderr, "\nTesting error print out\n");
  53273. ERR_print_errors_fp(stderr);
  53274. fprintf(stderr, "Done testing print out\n\n");
  53275. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53276. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  53277. return EXPECT_RESULT();
  53278. }
  53279. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  53280. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53281. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53282. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  53283. {
  53284. (void) ok;
  53285. (void) ctx;
  53286. fprintf(stderr, "ENTER verify_cb\n");
  53287. return SSL_SUCCESS;
  53288. }
  53289. #endif
  53290. static int test_wolfSSL_X509_Name_canon(void)
  53291. {
  53292. EXPECT_DECLS;
  53293. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53294. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  53295. defined(WOLFSSL_CERT_GEN) && \
  53296. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  53297. const long ex_hash1 = 0x0fdb2da4;
  53298. const long ex_hash2 = 0x9f3e8c9e;
  53299. X509_NAME *name = NULL;
  53300. X509 *x509 = NULL;
  53301. XFILE file = XBADFILE;
  53302. unsigned long hash = 0;
  53303. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  53304. byte *pbuf = NULL;
  53305. word32 len = 0;
  53306. (void) ex_hash2;
  53307. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  53308. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53309. ExpectNotNull(name = X509_get_issuer_name(x509));
  53310. /* When output buffer is NULL, should return necessary output buffer
  53311. * length.*/
  53312. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  53313. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53314. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53315. hash = (((unsigned long)digest[3] << 24) |
  53316. ((unsigned long)digest[2] << 16) |
  53317. ((unsigned long)digest[1] << 8) |
  53318. ((unsigned long)digest[0]));
  53319. ExpectIntEQ(hash, ex_hash1);
  53320. if (file != XBADFILE) {
  53321. XFCLOSE(file);
  53322. file = XBADFILE;
  53323. }
  53324. X509_free(x509);
  53325. x509 = NULL;
  53326. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53327. pbuf = NULL;
  53328. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  53329. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53330. ExpectNotNull(name = X509_get_issuer_name(x509));
  53331. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53332. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53333. hash = (((unsigned long)digest[3] << 24) |
  53334. ((unsigned long)digest[2] << 16) |
  53335. ((unsigned long)digest[1] << 8) |
  53336. ((unsigned long)digest[0]));
  53337. ExpectIntEQ(hash, ex_hash2);
  53338. if (file != XBADFILE)
  53339. XFCLOSE(file);
  53340. X509_free(x509);
  53341. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53342. #endif
  53343. return EXPECT_RESULT();
  53344. }
  53345. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  53346. {
  53347. EXPECT_DECLS;
  53348. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  53349. const int MAX_DIR = 4;
  53350. const char paths[][32] = {
  53351. "./certs/ed25519",
  53352. "./certs/ecc",
  53353. "./certs/crl",
  53354. "./certs/",
  53355. };
  53356. char CertCrl_path[MAX_FILENAME_SZ];
  53357. char *p;
  53358. X509_STORE* str = NULL;
  53359. X509_LOOKUP* lookup = NULL;
  53360. WOLFSSL_STACK* sk = NULL;
  53361. int len, total_len, i;
  53362. (void)sk;
  53363. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  53364. /* illegal string */
  53365. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53366. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53367. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  53368. SSL_FILETYPE_PEM,NULL), 0);
  53369. /* free store */
  53370. X509_STORE_free(str);
  53371. str = NULL;
  53372. /* short folder string */
  53373. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53374. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53375. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  53376. SSL_FILETYPE_PEM,NULL), 1);
  53377. #if defined(WOLFSSL_INT_H)
  53378. /* only available when including internal.h */
  53379. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53380. #endif
  53381. /* free store */
  53382. X509_STORE_free(str);
  53383. str = NULL;
  53384. /* typical function check */
  53385. p = &CertCrl_path[0];
  53386. total_len = 0;
  53387. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  53388. len = (int)XSTRLEN((const char*)&paths[i]);
  53389. total_len += len;
  53390. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  53391. p += len;
  53392. if (i != 0) *(p++) = SEPARATOR_CHAR;
  53393. }
  53394. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53395. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53396. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  53397. SSL_FILETYPE_PEM,NULL), 1);
  53398. #if defined(WOLFSSL_INT_H)
  53399. /* only available when including internal.h */
  53400. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53401. #endif
  53402. X509_STORE_free(str);
  53403. #endif
  53404. return EXPECT_RESULT();
  53405. }
  53406. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  53407. {
  53408. EXPECT_DECLS;
  53409. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53410. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53411. defined(WOLFSSL_SIGNER_DER_CERT)
  53412. X509_STORE_CTX* ctx = NULL;
  53413. X509_STORE* str = NULL;
  53414. X509_LOOKUP* lookup = NULL;
  53415. X509* cert1 = NULL;
  53416. X509* x509Ca = NULL;
  53417. X509* x509Svr = NULL;
  53418. X509* issuer = NULL;
  53419. WOLFSSL_STACK* sk = NULL;
  53420. X509_NAME* caName = NULL;
  53421. X509_NAME* issuerName = NULL;
  53422. XFILE file1 = XBADFILE;
  53423. int i;
  53424. int cert_count = 0;
  53425. int cmp;
  53426. char der[] = "certs/ca-cert.der";
  53427. #ifdef HAVE_CRL
  53428. char pem[][100] = {
  53429. "./certs/crl/crl.pem",
  53430. "./certs/crl/crl2.pem",
  53431. "./certs/crl/caEccCrl.pem",
  53432. "./certs/crl/eccCliCRL.pem",
  53433. "./certs/crl/eccSrvCRL.pem",
  53434. ""
  53435. };
  53436. #endif
  53437. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  53438. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  53439. if (file1 != XBADFILE)
  53440. XFCLOSE(file1);
  53441. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53442. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53443. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53444. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53445. SSL_FILETYPE_PEM,NULL), 1);
  53446. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53447. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53448. /* check if CA cert is loaded into the store */
  53449. for (i = 0; i < cert_count; i++) {
  53450. x509Ca = sk_X509_value(sk, i);
  53451. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53452. }
  53453. ExpectNotNull((x509Svr =
  53454. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53455. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53456. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53457. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  53458. ExpectNotNull(issuer);
  53459. caName = X509_get_subject_name(x509Ca);
  53460. ExpectNotNull(caName);
  53461. issuerName = X509_get_subject_name(issuer);
  53462. ExpectNotNull(issuerName);
  53463. cmp = X509_NAME_cmp(caName, issuerName);
  53464. ExpectIntEQ(cmp, 0);
  53465. /* load der format */
  53466. X509_free(issuer);
  53467. issuer = NULL;
  53468. X509_STORE_CTX_free(ctx);
  53469. ctx = NULL;
  53470. X509_STORE_free(str);
  53471. str = NULL;
  53472. sk_X509_pop_free(sk, NULL);
  53473. sk = NULL;
  53474. X509_free(x509Svr);
  53475. x509Svr = NULL;
  53476. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53477. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53478. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  53479. SSL_FILETYPE_ASN1,NULL), 1);
  53480. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53481. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53482. /* check if CA cert is loaded into the store */
  53483. for (i = 0; i < cert_count; i++) {
  53484. x509Ca = sk_X509_value(sk, i);
  53485. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53486. }
  53487. X509_STORE_free(str);
  53488. str = NULL;
  53489. sk_X509_pop_free(sk, NULL);
  53490. sk = NULL;
  53491. X509_free(cert1);
  53492. cert1 = NULL;
  53493. #ifdef HAVE_CRL
  53494. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  53495. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53496. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53497. SSL_FILETYPE_PEM,NULL), 1);
  53498. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  53499. "certs/server-revoked-cert.pem",
  53500. SSL_FILETYPE_PEM,NULL), 1);
  53501. if (str) {
  53502. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  53503. WOLFSSL_FILETYPE_PEM), 1);
  53504. /* since store hasn't yet known the revoked cert*/
  53505. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53506. "certs/server-revoked-cert.pem",
  53507. WOLFSSL_FILETYPE_PEM), 1);
  53508. }
  53509. for (i = 0; pem[i][0] != '\0'; i++)
  53510. {
  53511. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  53512. SSL_FILETYPE_PEM, NULL), 1);
  53513. }
  53514. if (str) {
  53515. /* since store knows crl list */
  53516. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53517. "certs/server-revoked-cert.pem",
  53518. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  53519. }
  53520. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  53521. X509_STORE_free(str);
  53522. #endif
  53523. #endif
  53524. return EXPECT_RESULT();
  53525. }
  53526. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  53527. {
  53528. int res = TEST_SKIPPED;
  53529. #if defined(OPENSSL_EXTRA)
  53530. X509_STORE_CTX_cleanup(NULL);
  53531. X509_STORE_CTX_trusted_stack(NULL, NULL);
  53532. res = TEST_SUCCESS;
  53533. #endif
  53534. return res;
  53535. }
  53536. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  53537. {
  53538. EXPECT_DECLS;
  53539. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53540. X509_STORE_CTX* ctx = NULL;
  53541. X509_STORE* str = NULL;
  53542. X509* x509Ca = NULL;
  53543. X509* x509Svr = NULL;
  53544. X509* issuer = NULL;
  53545. X509_NAME* caName = NULL;
  53546. X509_NAME* issuerName = NULL;
  53547. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53548. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53549. ExpectNotNull((x509Ca =
  53550. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  53551. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  53552. ExpectNotNull((x509Svr =
  53553. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53554. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53555. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53556. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  53557. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  53558. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  53559. #ifdef WOLFSSL_SIGNER_DER_CERT
  53560. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  53561. #endif
  53562. X509_free(issuer);
  53563. X509_STORE_CTX_free(ctx);
  53564. X509_free(x509Svr);
  53565. X509_STORE_free(str);
  53566. X509_free(x509Ca);
  53567. #endif
  53568. return EXPECT_RESULT();
  53569. }
  53570. static int test_wolfSSL_PKCS7_certs(void)
  53571. {
  53572. EXPECT_DECLS;
  53573. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  53574. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  53575. STACK_OF(X509)* sk = NULL;
  53576. STACK_OF(X509_INFO)* info_sk = NULL;
  53577. PKCS7 *p7 = NULL;
  53578. BIO* bio = NULL;
  53579. const byte* p = NULL;
  53580. int buflen = 0;
  53581. int i;
  53582. /* Test twice. Once with d2i and once without to test
  53583. * that everything is free'd correctly. */
  53584. for (i = 0; i < 2; i++) {
  53585. ExpectNotNull(p7 = PKCS7_new());
  53586. if (p7 != NULL) {
  53587. p7->version = 1;
  53588. #ifdef NO_SHA
  53589. p7->hashOID = SHA256h;
  53590. #else
  53591. p7->hashOID = SHAh;
  53592. #endif
  53593. }
  53594. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  53595. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  53596. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  53597. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  53598. ExpectNotNull(sk = sk_X509_new_null());
  53599. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  53600. X509_INFO* info = NULL;
  53601. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  53602. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  53603. if (EXPECT_SUCCESS() && (info != NULL)) {
  53604. info->x509 = NULL;
  53605. }
  53606. X509_INFO_free(info);
  53607. }
  53608. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  53609. info_sk = NULL;
  53610. BIO_free(bio);
  53611. bio = NULL;
  53612. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  53613. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  53614. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  53615. sk_X509_pop_free(sk, X509_free);
  53616. }
  53617. sk = NULL;
  53618. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  53619. if (i == 0) {
  53620. PKCS7_free(p7);
  53621. p7 = NULL;
  53622. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  53623. if (p7 != NULL) {
  53624. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  53625. * them */
  53626. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  53627. }
  53628. /* PKCS7_free free's the certs */
  53629. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  53630. }
  53631. BIO_free(bio);
  53632. bio = NULL;
  53633. PKCS7_free(p7);
  53634. p7 = NULL;
  53635. }
  53636. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53637. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  53638. return EXPECT_RESULT();
  53639. }
  53640. static int test_wolfSSL_X509_STORE_CTX(void)
  53641. {
  53642. EXPECT_DECLS;
  53643. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53644. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53645. X509_STORE_CTX* ctx = NULL;
  53646. X509_STORE* str = NULL;
  53647. X509* x509 = NULL;
  53648. #ifdef OPENSSL_ALL
  53649. X509* x5092 = NULL;
  53650. STACK_OF(X509) *sk = NULL;
  53651. STACK_OF(X509) *sk2 = NULL;
  53652. STACK_OF(X509) *sk3 = NULL;
  53653. #endif
  53654. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53655. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53656. ExpectNotNull((x509 =
  53657. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53658. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  53659. #ifdef OPENSSL_ALL
  53660. /* sk_X509_new only in OPENSSL_ALL */
  53661. sk = sk_X509_new_null();
  53662. ExpectNotNull(sk);
  53663. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  53664. #else
  53665. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  53666. #endif
  53667. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  53668. X509_STORE_CTX_set_error(ctx, -5);
  53669. X509_STORE_CTX_set_error(NULL, -5);
  53670. X509_STORE_CTX_free(ctx);
  53671. ctx = NULL;
  53672. #ifdef OPENSSL_ALL
  53673. sk_X509_pop_free(sk, NULL);
  53674. sk = NULL;
  53675. #endif
  53676. X509_STORE_free(str);
  53677. str = NULL;
  53678. X509_free(x509);
  53679. x509 = NULL;
  53680. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53681. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  53682. X509_STORE_CTX_free(ctx);
  53683. ctx = NULL;
  53684. #ifdef OPENSSL_ALL
  53685. /* test X509_STORE_CTX_get(1)_chain */
  53686. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  53687. SSL_FILETYPE_PEM)));
  53688. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  53689. SSL_FILETYPE_PEM)));
  53690. ExpectNotNull((sk = sk_X509_new_null()));
  53691. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  53692. if (EXPECT_FAIL()) {
  53693. X509_free(x509);
  53694. x509 = NULL;
  53695. }
  53696. ExpectNotNull((str = X509_STORE_new()));
  53697. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  53698. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  53699. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  53700. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  53701. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  53702. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  53703. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  53704. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  53705. X509_STORE_CTX_free(ctx);
  53706. ctx = NULL;
  53707. X509_STORE_free(str);
  53708. str = NULL;
  53709. /* CTX certs not freed yet */
  53710. X509_free(x5092);
  53711. x5092 = NULL;
  53712. sk_X509_pop_free(sk, NULL);
  53713. sk = NULL;
  53714. /* sk3 is dup so free here */
  53715. sk_X509_pop_free(sk3, NULL);
  53716. sk3 = NULL;
  53717. #endif
  53718. /* test X509_STORE_CTX_get/set_ex_data */
  53719. {
  53720. int i = 0, tmpData = 5;
  53721. void* tmpDataRet;
  53722. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53723. #ifdef HAVE_EX_DATA
  53724. for (i = 0; i < MAX_EX_DATA; i++) {
  53725. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53726. WOLFSSL_SUCCESS);
  53727. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53728. ExpectNotNull(tmpDataRet);
  53729. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53730. }
  53731. #else
  53732. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53733. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53734. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53735. ExpectNull(tmpDataRet);
  53736. #endif
  53737. X509_STORE_CTX_free(ctx);
  53738. ctx = NULL;
  53739. }
  53740. /* test X509_STORE_get/set_ex_data */
  53741. {
  53742. int i = 0, tmpData = 99;
  53743. void* tmpDataRet;
  53744. ExpectNotNull(str = X509_STORE_new());
  53745. #ifdef HAVE_EX_DATA
  53746. for (i = 0; i < MAX_EX_DATA; i++) {
  53747. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  53748. WOLFSSL_SUCCESS);
  53749. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  53750. ExpectNotNull(tmpDataRet);
  53751. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53752. }
  53753. #else
  53754. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  53755. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53756. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  53757. ExpectNull(tmpDataRet);
  53758. #endif
  53759. X509_STORE_free(str);
  53760. str = NULL;
  53761. }
  53762. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53763. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53764. return EXPECT_RESULT();
  53765. }
  53766. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53767. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  53768. STACK_OF(X509)* chain)
  53769. {
  53770. EXPECT_DECLS;
  53771. XFILE fp = XBADFILE;
  53772. X509* cert = NULL;
  53773. ExpectTrue((fp = XFOPEN(filename, "rb"))
  53774. != XBADFILE);
  53775. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  53776. if (fp != XBADFILE) {
  53777. XFCLOSE(fp);
  53778. fp = XBADFILE;
  53779. }
  53780. ExpectIntGT(sk_X509_push(chain, cert), 0);
  53781. if (EXPECT_FAIL())
  53782. X509_free(cert);
  53783. return EXPECT_RESULT();
  53784. }
  53785. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  53786. int err, int loadCA)
  53787. {
  53788. EXPECT_DECLS;
  53789. X509_STORE_CTX* ctx = NULL;
  53790. X509_STORE* str = NULL;
  53791. XFILE fp = XBADFILE;
  53792. X509* cert = NULL;
  53793. STACK_OF(X509)* untrusted = NULL;
  53794. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  53795. != XBADFILE);
  53796. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  53797. if (fp != XBADFILE) {
  53798. XFCLOSE(fp);
  53799. fp = XBADFILE;
  53800. }
  53801. ExpectNotNull(str = X509_STORE_new());
  53802. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53803. ExpectNotNull(untrusted = sk_X509_new_null());
  53804. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  53805. if (loadCA) {
  53806. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  53807. 1);
  53808. }
  53809. for (; *filenames; filenames++) {
  53810. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  53811. untrusted), TEST_SUCCESS);
  53812. }
  53813. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  53814. ExpectIntEQ(X509_verify_cert(ctx), ret);
  53815. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  53816. X509_free(cert);
  53817. X509_STORE_free(str);
  53818. X509_STORE_CTX_free(ctx);
  53819. sk_X509_pop_free(untrusted, NULL);
  53820. return EXPECT_RESULT();
  53821. }
  53822. #endif
  53823. static int test_X509_STORE_untrusted(void)
  53824. {
  53825. EXPECT_DECLS;
  53826. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53827. const char* untrusted1[] = {
  53828. "./certs/intermediate/ca-int2-cert.pem",
  53829. NULL
  53830. };
  53831. const char* untrusted2[] = {
  53832. "./certs/intermediate/ca-int-cert.pem",
  53833. "./certs/intermediate/ca-int2-cert.pem",
  53834. NULL
  53835. };
  53836. const char* untrusted3[] = {
  53837. "./certs/intermediate/ca-int-cert.pem",
  53838. "./certs/intermediate/ca-int2-cert.pem",
  53839. "./certs/ca-cert.pem",
  53840. NULL
  53841. };
  53842. /* Adding unrelated certs that should be ignored */
  53843. const char* untrusted4[] = {
  53844. "./certs/client-ca.pem",
  53845. "./certs/intermediate/ca-int-cert.pem",
  53846. "./certs/server-cert.pem",
  53847. "./certs/intermediate/ca-int2-cert.pem",
  53848. NULL
  53849. };
  53850. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  53851. * to loaded CA. */
  53852. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  53853. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  53854. /* Succeeds because path to loaded CA is available. */
  53855. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  53856. TEST_SUCCESS);
  53857. /* Fails because root CA is in the untrusted stack */
  53858. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  53859. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  53860. /* Succeeds because path to loaded CA is available. */
  53861. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  53862. TEST_SUCCESS);
  53863. #endif
  53864. return EXPECT_RESULT();
  53865. }
  53866. static int test_wolfSSL_X509_STORE_set_flags(void)
  53867. {
  53868. EXPECT_DECLS;
  53869. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53870. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53871. X509_STORE* store = NULL;
  53872. X509* x509 = NULL;
  53873. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  53874. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  53875. WOLFSSL_FILETYPE_PEM)));
  53876. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  53877. #ifdef HAVE_CRL
  53878. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  53879. WOLFSSL_SUCCESS);
  53880. #else
  53881. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  53882. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  53883. #endif
  53884. wolfSSL_X509_free(x509);
  53885. wolfSSL_X509_STORE_free(store);
  53886. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53887. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53888. return EXPECT_RESULT();
  53889. }
  53890. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  53891. {
  53892. EXPECT_DECLS;
  53893. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  53894. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53895. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  53896. WOLFSSL_X509_STORE* store = NULL;
  53897. WOLFSSL_X509_LOOKUP* lookup = NULL;
  53898. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  53899. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  53900. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  53901. X509_FILETYPE_PEM), 1);
  53902. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  53903. X509_FILETYPE_PEM), 1);
  53904. if (store != NULL) {
  53905. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  53906. WOLFSSL_FILETYPE_PEM), 1);
  53907. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  53908. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  53909. }
  53910. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  53911. X509_FILETYPE_PEM), 1);
  53912. if (store != NULL) {
  53913. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  53914. WOLFSSL_FILETYPE_PEM), 1);
  53915. }
  53916. wolfSSL_X509_STORE_free(store);
  53917. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  53918. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  53919. return EXPECT_RESULT();
  53920. }
  53921. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  53922. {
  53923. EXPECT_DECLS;
  53924. #if defined(OPENSSL_EXTRA)
  53925. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  53926. time_t c_time;
  53927. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  53928. c_time = 365*24*60*60;
  53929. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  53930. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  53931. WOLFSSL_USE_CHECK_TIME);
  53932. ExpectTrue(ctx->param->check_time == c_time);
  53933. wolfSSL_X509_STORE_CTX_free(ctx);
  53934. #endif /* OPENSSL_EXTRA */
  53935. return EXPECT_RESULT();
  53936. }
  53937. static int test_wolfSSL_CTX_get0_set1_param(void)
  53938. {
  53939. EXPECT_DECLS;
  53940. #if defined(OPENSSL_EXTRA)
  53941. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53942. SSL_CTX* ctx = NULL;
  53943. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  53944. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  53945. char testIPv4[] = "127.0.0.1";
  53946. char testhostName[] = "foo.hoge.com";
  53947. #ifndef NO_WOLFSSL_SERVER
  53948. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53949. #else
  53950. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53951. #endif
  53952. ExpectNull(SSL_CTX_get0_param(NULL));
  53953. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  53954. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  53955. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  53956. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  53957. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  53958. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  53959. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  53960. WOLFSSL_SUCCESS);
  53961. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  53962. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  53963. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  53964. (int)XSTRLEN(testhostName)));
  53965. ExpectIntEQ(0x01, pParam->hostFlags);
  53966. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  53967. /* test for incorrect parameter */
  53968. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  53969. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  53970. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  53971. SSL_CTX_free(ctx);
  53972. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  53973. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53974. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  53975. return EXPECT_RESULT();
  53976. }
  53977. static int test_wolfSSL_get0_param(void)
  53978. {
  53979. EXPECT_DECLS;
  53980. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53981. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53982. SSL_CTX* ctx = NULL;
  53983. SSL* ssl = NULL;
  53984. #ifndef NO_WOLFSSL_SERVER
  53985. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53986. #else
  53987. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53988. #endif
  53989. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53990. SSL_FILETYPE_PEM));
  53991. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  53992. ExpectNotNull(ssl = SSL_new(ctx));
  53993. ExpectNotNull(SSL_get0_param(ssl));
  53994. SSL_free(ssl);
  53995. SSL_CTX_free(ctx);
  53996. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53997. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  53998. return EXPECT_RESULT();
  53999. }
  54000. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  54001. {
  54002. EXPECT_DECLS;
  54003. #if defined(OPENSSL_EXTRA)
  54004. const char host[] = "www.example.com";
  54005. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54006. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  54007. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  54008. if (pParam != NULL) {
  54009. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54010. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  54011. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54012. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54013. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54014. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54015. }
  54016. #endif /* OPENSSL_EXTRA */
  54017. return EXPECT_RESULT();
  54018. }
  54019. static int test_wolfSSL_set1_host(void)
  54020. {
  54021. EXPECT_DECLS;
  54022. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54023. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54024. const char host[] = "www.test_wolfSSL_set1_host.com";
  54025. const char emptyStr[] = "";
  54026. SSL_CTX* ctx = NULL;
  54027. SSL* ssl = NULL;
  54028. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54029. #ifndef NO_WOLFSSL_SERVER
  54030. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54031. #else
  54032. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54033. #endif
  54034. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54035. SSL_FILETYPE_PEM));
  54036. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54037. ExpectNotNull(ssl = SSL_new(ctx));
  54038. pParam = SSL_get0_param(ssl);
  54039. /* we should get back host string */
  54040. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54041. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54042. /* we should get back empty string */
  54043. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  54044. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54045. /* we should get back host string */
  54046. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54047. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54048. /* we should get back empty string */
  54049. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  54050. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54051. SSL_free(ssl);
  54052. SSL_CTX_free(ctx);
  54053. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54054. #endif /* OPENSSL_EXTRA */
  54055. return EXPECT_RESULT();
  54056. }
  54057. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  54058. {
  54059. EXPECT_DECLS;
  54060. #if defined(OPENSSL_EXTRA)
  54061. unsigned char buf[16] = {0};
  54062. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  54063. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  54064. /* test 127.0.0.1 */
  54065. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  54066. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  54067. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  54068. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  54069. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54070. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  54071. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  54072. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  54073. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54074. ExpectIntEQ(XSTRNCMP(param->ipasc,
  54075. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  54076. /* test 2001:db8:: */
  54077. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54078. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54079. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54080. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  54081. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54082. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  54083. /* test ::1234:5678 */
  54084. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  54085. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54086. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54087. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54088. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54089. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  54090. /* test 2001:db8::1234:5678 */
  54091. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54092. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54093. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54094. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54095. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54096. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  54097. sizeof(param->ipasc)), 0);
  54098. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  54099. /* 2001:db8:1::ab9:c0a8:102 */
  54100. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54101. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  54102. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  54103. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  54104. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54105. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  54106. sizeof(param->ipasc)), 0);
  54107. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54108. #endif /* OPENSSL_EXTRA */
  54109. return EXPECT_RESULT();
  54110. }
  54111. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  54112. {
  54113. EXPECT_DECLS;
  54114. #if defined(OPENSSL_EXTRA)
  54115. X509_STORE* store = NULL;
  54116. X509_STORE_CTX* ctx = NULL;
  54117. X509_STORE_CTX* ctx_no_init = NULL;
  54118. ExpectNotNull((store = X509_STORE_new()));
  54119. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54120. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  54121. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  54122. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  54123. /* should return NULL if ctx has not bee initialized */
  54124. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  54125. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  54126. wolfSSL_X509_STORE_CTX_free(ctx);
  54127. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  54128. X509_STORE_free(store);
  54129. #endif /* OPENSSL_EXTRA */
  54130. return EXPECT_RESULT();
  54131. }
  54132. static int test_wolfSSL_CTX_set_client_CA_list(void)
  54133. {
  54134. EXPECT_DECLS;
  54135. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54136. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  54137. WOLFSSL_CTX* ctx = NULL;
  54138. WOLFSSL* ssl = NULL;
  54139. X509_NAME* name = NULL;
  54140. STACK_OF(X509_NAME)* names = NULL;
  54141. STACK_OF(X509_NAME)* ca_list = NULL;
  54142. int names_len = 0;
  54143. int i;
  54144. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  54145. /* Send two X501 names in cert request */
  54146. names = SSL_load_client_CA_file(cliCertFile);
  54147. ExpectNotNull(names);
  54148. ca_list = SSL_load_client_CA_file(caCertFile);
  54149. ExpectNotNull(ca_list);
  54150. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  54151. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  54152. if (EXPECT_FAIL()) {
  54153. wolfSSL_X509_NAME_free(name);
  54154. name = NULL;
  54155. }
  54156. SSL_CTX_set_client_CA_list(ctx, names);
  54157. /* This should only free the stack structure */
  54158. sk_X509_NAME_free(ca_list);
  54159. ca_list = NULL;
  54160. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54161. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54162. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54163. for (i = 0; i < names_len; i++) {
  54164. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54165. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54166. }
  54167. /* Needed to be able to create ssl object */
  54168. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54169. SSL_FILETYPE_PEM));
  54170. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54171. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54172. /* load again as old names are responsibility of ctx to free*/
  54173. names = SSL_load_client_CA_file(cliCertFile);
  54174. ExpectNotNull(names);
  54175. SSL_set_client_CA_list(ssl, names);
  54176. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  54177. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54178. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54179. for (i = 0; i < names_len; i++) {
  54180. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54181. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54182. }
  54183. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  54184. {
  54185. tcp_ready ready;
  54186. func_args server_args;
  54187. callback_functions server_cb;
  54188. THREAD_TYPE serverThread;
  54189. WOLFSSL* ssl_client = NULL;
  54190. WOLFSSL_CTX* ctx_client = NULL;
  54191. SOCKET_T sockfd = 0;
  54192. /* wolfSSL_get_client_CA_list() with handshake */
  54193. StartTCP();
  54194. InitTcpReady(&ready);
  54195. XMEMSET(&server_args, 0, sizeof(func_args));
  54196. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54197. server_args.signal = &ready;
  54198. server_args.callbacks = &server_cb;
  54199. /* we are responsible for free'ing WOLFSSL_CTX */
  54200. server_cb.ctx = ctx;
  54201. server_cb.isSharedCtx = 1;
  54202. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  54203. cliCertFile, 0));
  54204. start_thread(test_server_nofail, &server_args, &serverThread);
  54205. wait_tcp_ready(&server_args);
  54206. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54207. ExpectNotNull(ctx_client =
  54208. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  54209. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  54210. ctx_client, caCertFile, 0));
  54211. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  54212. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  54213. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  54214. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  54215. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  54216. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  54217. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  54218. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  54219. /* We are expecting two cert names to be sent */
  54220. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  54221. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  54222. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  54223. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  54224. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  54225. }
  54226. wolfSSL_shutdown(ssl_client);
  54227. wolfSSL_free(ssl_client);
  54228. wolfSSL_CTX_free(ctx_client);
  54229. CloseSocket(sockfd);
  54230. join_thread(serverThread);
  54231. FreeTcpReady(&ready);
  54232. }
  54233. #endif
  54234. wolfSSL_free(ssl);
  54235. wolfSSL_CTX_free(ctx);
  54236. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  54237. * !NO_BIO */
  54238. return EXPECT_RESULT();
  54239. }
  54240. static int test_wolfSSL_CTX_add_client_CA(void)
  54241. {
  54242. EXPECT_DECLS;
  54243. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54244. !defined(NO_WOLFSSL_CLIENT)
  54245. WOLFSSL_CTX* ctx = NULL;
  54246. WOLFSSL_X509* x509 = NULL;
  54247. WOLFSSL_X509* x509_a = NULL;
  54248. STACK_OF(X509_NAME)* ca_list = NULL;
  54249. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54250. /* Add client cert */
  54251. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  54252. SSL_FILETYPE_PEM));
  54253. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  54254. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54255. /* Add another client cert */
  54256. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  54257. SSL_FILETYPE_PEM));
  54258. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  54259. /* test for incorrect parameter */
  54260. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  54261. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  54262. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  54263. X509_free(x509);
  54264. X509_free(x509_a);
  54265. SSL_CTX_free(ctx);
  54266. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  54267. return EXPECT_RESULT();
  54268. }
  54269. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54270. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54271. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  54272. {
  54273. callback_functions* callbacks = ((func_args*)args)->callbacks;
  54274. WOLFSSL_CTX* ctx = callbacks->ctx;
  54275. WOLFSSL* ssl = NULL;
  54276. SOCKET_T sfd = 0;
  54277. SOCKET_T cfd = 0;
  54278. word16 port;
  54279. char input[1024];
  54280. int idx;
  54281. int ret, err = 0;
  54282. const char* privateName = "ech-private-name.com";
  54283. int privateNameLen = (int)XSTRLEN(privateName);
  54284. ((func_args*)args)->return_code = TEST_FAIL;
  54285. port = ((func_args*)args)->signal->port;
  54286. AssertIntEQ(WOLFSSL_SUCCESS,
  54287. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  54288. AssertIntEQ(WOLFSSL_SUCCESS,
  54289. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  54290. WOLFSSL_FILETYPE_PEM));
  54291. AssertIntEQ(WOLFSSL_SUCCESS,
  54292. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54293. WOLFSSL_FILETYPE_PEM));
  54294. if (callbacks->ctx_ready)
  54295. callbacks->ctx_ready(ctx);
  54296. ssl = wolfSSL_new(ctx);
  54297. /* set the sni for the server */
  54298. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  54299. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  54300. CloseSocket(sfd);
  54301. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  54302. if (callbacks->ssl_ready)
  54303. callbacks->ssl_ready(ssl);
  54304. do {
  54305. err = 0; /* Reset error */
  54306. ret = wolfSSL_accept(ssl);
  54307. if (ret != WOLFSSL_SUCCESS) {
  54308. err = wolfSSL_get_error(ssl, 0);
  54309. }
  54310. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  54311. if (ret != WOLFSSL_SUCCESS) {
  54312. char buff[WOLFSSL_MAX_ERROR_SZ];
  54313. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  54314. }
  54315. else {
  54316. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  54317. input[idx] = 0;
  54318. fprintf(stderr, "Client message: %s\n", input);
  54319. }
  54320. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  54321. privateNameLen));
  54322. ((func_args*)args)->return_code = TEST_SUCCESS;
  54323. }
  54324. if (callbacks->on_result)
  54325. callbacks->on_result(ssl);
  54326. wolfSSL_shutdown(ssl);
  54327. wolfSSL_free(ssl);
  54328. wolfSSL_CTX_free(ctx);
  54329. CloseSocket(cfd);
  54330. #ifdef FP_ECC
  54331. wc_ecc_fp_free();
  54332. #endif
  54333. WOLFSSL_RETURN_FROM_THREAD(0);
  54334. }
  54335. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54336. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54337. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  54338. {
  54339. XFILE fp;
  54340. const byte lf = '\n';
  54341. AssertNotNull(ssl);
  54342. AssertNotNull(line);
  54343. fp = XFOPEN("./MyKeyLog.txt", "a");
  54344. XFWRITE(line, 1, XSTRLEN(line), fp);
  54345. XFWRITE((void*)&lf, 1, 1, fp);
  54346. XFFLUSH(fp);
  54347. XFCLOSE(fp);
  54348. }
  54349. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54350. static int test_wolfSSL_CTX_set_keylog_callback(void)
  54351. {
  54352. EXPECT_DECLS;
  54353. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54354. !defined(NO_WOLFSSL_CLIENT)
  54355. SSL_CTX* ctx = NULL;
  54356. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54357. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54358. SSL_CTX_free(ctx);
  54359. SSL_CTX_set_keylog_callback(NULL, NULL);
  54360. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54361. return EXPECT_RESULT();
  54362. }
  54363. static int test_wolfSSL_CTX_get_keylog_callback(void)
  54364. {
  54365. EXPECT_DECLS;
  54366. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54367. !defined(NO_WOLFSSL_CLIENT)
  54368. SSL_CTX* ctx = NULL;
  54369. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54370. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54371. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54372. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  54373. SSL_CTX_set_keylog_callback(ctx, NULL );
  54374. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54375. SSL_CTX_free(ctx);
  54376. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54377. return EXPECT_RESULT();
  54378. }
  54379. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54380. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54381. {
  54382. /* set keylog callback */
  54383. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54384. return TEST_SUCCESS;
  54385. }
  54386. #endif
  54387. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  54388. {
  54389. EXPECT_DECLS;
  54390. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54391. /* This test is intended for checking whether keylog callback is called
  54392. * in client during TLS handshake between the client and a server.
  54393. */
  54394. test_ssl_cbf server_cbf;
  54395. test_ssl_cbf client_cbf;
  54396. XFILE fp = XBADFILE;
  54397. char buff[500];
  54398. int found = 0;
  54399. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54400. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54401. server_cbf.method = wolfTLSv1_2_server_method;
  54402. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  54403. /* clean up keylog file */
  54404. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54405. if (fp != XBADFILE) {
  54406. XFFLUSH(fp);
  54407. XFCLOSE(fp);
  54408. fp = XBADFILE;
  54409. }
  54410. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54411. &server_cbf, NULL), TEST_SUCCESS);
  54412. /* check if the keylog file exists */
  54413. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54414. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  54415. XMEMSET(buff, 0, sizeof(buff));
  54416. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54417. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  54418. found = 1;
  54419. break;
  54420. }
  54421. }
  54422. if (fp != XBADFILE) {
  54423. XFCLOSE(fp);
  54424. }
  54425. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  54426. ExpectIntEQ(found, 1);
  54427. /* clean up */
  54428. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  54429. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54430. return EXPECT_RESULT();
  54431. }
  54432. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54433. defined(HAVE_SECRET_CALLBACK)
  54434. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54435. {
  54436. /* set keylog callback */
  54437. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54438. return TEST_SUCCESS;
  54439. }
  54440. #endif
  54441. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  54442. {
  54443. EXPECT_DECLS;
  54444. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54445. defined(HAVE_SECRET_CALLBACK)
  54446. /* This test is intended for checking whether keylog callback is called
  54447. * in client during TLS handshake between the client and a server.
  54448. */
  54449. test_ssl_cbf server_cbf;
  54450. test_ssl_cbf client_cbf;
  54451. XFILE fp = XBADFILE;
  54452. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54453. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54454. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54455. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  54456. /* clean up keylog file */
  54457. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54458. if (fp != XBADFILE) {
  54459. XFCLOSE(fp);
  54460. fp = XBADFILE;
  54461. }
  54462. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54463. &server_cbf, NULL), TEST_SUCCESS);
  54464. /* check if the keylog file exists */
  54465. {
  54466. char buff[300] = {0};
  54467. int found[4] = {0};
  54468. int numfnd = 0;
  54469. int i;
  54470. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54471. while (EXPECT_SUCCESS() &&
  54472. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54473. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  54474. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54475. found[0] = 1;
  54476. continue;
  54477. }
  54478. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  54479. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54480. found[1] = 1;
  54481. continue;
  54482. }
  54483. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  54484. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  54485. found[2] = 1;
  54486. continue;
  54487. }
  54488. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  54489. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  54490. found[3] = 1;
  54491. continue;
  54492. }
  54493. }
  54494. if (fp != XBADFILE)
  54495. XFCLOSE(fp);
  54496. for (i = 0; i < 4; i++) {
  54497. if (found[i] != 0)
  54498. numfnd++;
  54499. }
  54500. ExpectIntEQ(numfnd, 4);
  54501. }
  54502. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  54503. return EXPECT_RESULT();
  54504. }
  54505. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54506. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54507. static int test_wolfSSL_Tls13_ECH_params(void)
  54508. {
  54509. EXPECT_DECLS;
  54510. #if !defined(NO_WOLFSSL_CLIENT)
  54511. word32 outputLen = 0;
  54512. byte testBuf[72];
  54513. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  54514. WOLFSSL *ssl = wolfSSL_new(ctx);
  54515. ExpectNotNull(ctx);
  54516. ExpectNotNull(ssl);
  54517. /* invalid ctx */
  54518. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  54519. "ech-public-name.com", 0, 0, 0));
  54520. /* invalid public name */
  54521. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  54522. 0, 0));
  54523. /* invalid algorithms */
  54524. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  54525. "ech-public-name.com", 1000, 1000, 1000));
  54526. /* invalid ctx */
  54527. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  54528. &outputLen));
  54529. /* invalid output len */
  54530. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  54531. /* invalid ssl */
  54532. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  54533. (char*)testBuf, sizeof(testBuf)));
  54534. /* invalid configs64 */
  54535. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  54536. sizeof(testBuf)));
  54537. /* invalid size */
  54538. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  54539. (char*)testBuf, 0));
  54540. /* invalid ssl */
  54541. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  54542. sizeof(testBuf)));
  54543. /* invalid configs */
  54544. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  54545. sizeof(testBuf)));
  54546. /* invalid size */
  54547. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  54548. /* invalid ssl */
  54549. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  54550. /* invalid size */
  54551. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  54552. wolfSSL_free(ssl);
  54553. wolfSSL_CTX_free(ctx);
  54554. #endif /* !NO_WOLFSSL_CLIENT */
  54555. return EXPECT_RESULT();
  54556. }
  54557. static int test_wolfSSL_Tls13_ECH(void)
  54558. {
  54559. EXPECT_DECLS;
  54560. tcp_ready ready;
  54561. func_args client_args;
  54562. func_args server_args;
  54563. THREAD_TYPE serverThread;
  54564. callback_functions server_cbf;
  54565. callback_functions client_cbf;
  54566. SOCKET_T sockfd = 0;
  54567. WOLFSSL_CTX* ctx = NULL;
  54568. WOLFSSL* ssl = NULL;
  54569. const char* publicName = "ech-public-name.com";
  54570. const char* privateName = "ech-private-name.com";
  54571. int privateNameLen = 20;
  54572. char reply[1024];
  54573. int replyLen = 0;
  54574. byte rawEchConfig[128];
  54575. word32 rawEchConfigLen = sizeof(rawEchConfig);
  54576. InitTcpReady(&ready);
  54577. ready.port = 22222;
  54578. XMEMSET(&client_args, 0, sizeof(func_args));
  54579. XMEMSET(&server_args, 0, sizeof(func_args));
  54580. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  54581. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  54582. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54583. /* create the server context here so we can get the ech config */
  54584. ExpectNotNull(server_cbf.ctx =
  54585. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  54586. /* generate ech config */
  54587. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  54588. publicName, 0, 0, 0));
  54589. /* get the config for the client to use */
  54590. ExpectIntEQ(WOLFSSL_SUCCESS,
  54591. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  54592. &rawEchConfigLen));
  54593. server_args.callbacks = &server_cbf;
  54594. server_args.signal = &ready;
  54595. /* start server task */
  54596. start_thread(server_task_ech, &server_args, &serverThread);
  54597. wait_tcp_ready(&server_args);
  54598. /* run as a TLS1.3 client */
  54599. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  54600. ExpectIntEQ(WOLFSSL_SUCCESS,
  54601. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  54602. ExpectIntEQ(WOLFSSL_SUCCESS,
  54603. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  54604. ExpectIntEQ(WOLFSSL_SUCCESS,
  54605. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  54606. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54607. /* get connected the server task */
  54608. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54609. /* set the ech configs for the client */
  54610. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  54611. rawEchConfigLen));
  54612. /* set the sni for the client */
  54613. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  54614. privateName, privateNameLen));
  54615. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  54616. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54617. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  54618. privateNameLen);
  54619. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  54620. /* add th null terminator for string compare */
  54621. reply[replyLen] = 0;
  54622. /* check that the server replied with the private name */
  54623. ExpectStrEQ(privateName, reply);
  54624. wolfSSL_free(ssl);
  54625. wolfSSL_CTX_free(ctx);
  54626. CloseSocket(sockfd);
  54627. join_thread(serverThread);
  54628. FreeTcpReady(&ready);
  54629. return EXPECT_RESULT();
  54630. }
  54631. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54632. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54633. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54634. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54635. static int post_auth_version_cb(WOLFSSL* ssl)
  54636. {
  54637. EXPECT_DECLS;
  54638. /* do handshake and then test version error */
  54639. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54640. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54641. return EXPECT_RESULT();
  54642. }
  54643. static int post_auth_version_client_cb(WOLFSSL* ssl)
  54644. {
  54645. EXPECT_DECLS;
  54646. /* do handshake and then test version error */
  54647. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54648. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54649. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54650. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  54651. /* check was added to error queue */
  54652. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  54653. /* check the string matches expected string */
  54654. #ifndef NO_ERROR_STRINGS
  54655. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  54656. "WRONG_SSL_VERSION");
  54657. #endif
  54658. #endif
  54659. return EXPECT_RESULT();
  54660. }
  54661. static int post_auth_cb(WOLFSSL* ssl)
  54662. {
  54663. EXPECT_DECLS;
  54664. WOLFSSL_X509* x509 = NULL;
  54665. /* do handshake and then test version error */
  54666. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54667. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  54668. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  54669. wolfSSL_X509_free(x509);
  54670. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  54671. return EXPECT_RESULT();
  54672. }
  54673. static int set_post_auth_cb(WOLFSSL* ssl)
  54674. {
  54675. if (!wolfSSL_is_server(ssl)) {
  54676. EXPECT_DECLS;
  54677. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  54678. return EXPECT_RESULT();
  54679. }
  54680. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  54681. return TEST_SUCCESS;
  54682. }
  54683. #endif
  54684. static int test_wolfSSL_Tls13_postauth(void)
  54685. {
  54686. EXPECT_DECLS;
  54687. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54688. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54689. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54690. test_ssl_cbf server_cbf;
  54691. test_ssl_cbf client_cbf;
  54692. /* test version failure doing post auth with TLS 1.2 connection */
  54693. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54694. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54695. server_cbf.method = wolfTLSv1_2_server_method;
  54696. server_cbf.ssl_ready = set_post_auth_cb;
  54697. server_cbf.on_result = post_auth_version_cb;
  54698. client_cbf.ssl_ready = set_post_auth_cb;
  54699. client_cbf.on_result = post_auth_version_client_cb;
  54700. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54701. &server_cbf, NULL), TEST_SUCCESS);
  54702. /* tests on post auth with TLS 1.3 */
  54703. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54704. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54705. server_cbf.method = wolfTLSv1_3_server_method;
  54706. server_cbf.ssl_ready = set_post_auth_cb;
  54707. client_cbf.ssl_ready = set_post_auth_cb;
  54708. server_cbf.on_result = post_auth_cb;
  54709. client_cbf.on_result = NULL;
  54710. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54711. &server_cbf, NULL), TEST_SUCCESS);
  54712. #endif
  54713. return EXPECT_RESULT();
  54714. }
  54715. static int test_wolfSSL_X509_NID(void)
  54716. {
  54717. EXPECT_DECLS;
  54718. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  54719. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  54720. int sigType;
  54721. int nameSz;
  54722. X509* cert = NULL;
  54723. EVP_PKEY* pubKeyTmp = NULL;
  54724. X509_NAME* name = NULL;
  54725. char commonName[80];
  54726. char countryName[80];
  54727. char localityName[80];
  54728. char stateName[80];
  54729. char orgName[80];
  54730. char orgUnit[80];
  54731. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  54732. /* convert cert from DER to internal WOLFSSL_X509 struct */
  54733. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  54734. sizeof_client_cert_der_2048, HEAP_HINT));
  54735. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  54736. /* extract PUBLIC KEY from cert */
  54737. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  54738. /* extract signatureType */
  54739. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  54740. /* extract subjectName info */
  54741. ExpectNotNull(name = X509_get_subject_name(cert));
  54742. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  54743. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54744. NULL, 0)), 0);
  54745. ExpectIntEQ(nameSz, 15);
  54746. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54747. commonName, sizeof(commonName))), 0);
  54748. ExpectIntEQ(nameSz, 15);
  54749. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  54750. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  54751. commonName, 9)), 0);
  54752. ExpectIntEQ(nameSz, 8);
  54753. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  54754. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  54755. countryName, sizeof(countryName))), 0);
  54756. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  54757. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  54758. localityName, sizeof(localityName))), 0);
  54759. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  54760. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  54761. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  54762. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  54763. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  54764. orgName, sizeof(orgName))), 0);
  54765. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  54766. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  54767. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  54768. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  54769. EVP_PKEY_free(pubKeyTmp);
  54770. X509_free(cert);
  54771. #endif
  54772. return EXPECT_RESULT();
  54773. }
  54774. static int test_wolfSSL_CTX_set_srp_username(void)
  54775. {
  54776. EXPECT_DECLS;
  54777. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  54778. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  54779. WOLFSSL_CTX* ctx = NULL;
  54780. WOLFSSL* ssl = NULL;
  54781. const char *username = "TESTUSER";
  54782. const char *password = "TESTPASSWORD";
  54783. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54784. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54785. SSL_SUCCESS);
  54786. wolfSSL_CTX_free(ctx);
  54787. ctx = NULL;
  54788. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54789. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54790. SSL_SUCCESS);
  54791. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54792. SSL_SUCCESS);
  54793. ExpectNotNull(ssl = SSL_new(ctx));
  54794. ExpectNotNull(SSL_get_srp_username(ssl));
  54795. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  54796. wolfSSL_free(ssl);
  54797. wolfSSL_CTX_free(ctx);
  54798. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  54799. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  54800. return EXPECT_RESULT();
  54801. }
  54802. static int test_wolfSSL_CTX_set_srp_password(void)
  54803. {
  54804. EXPECT_DECLS;
  54805. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  54806. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  54807. WOLFSSL_CTX* ctx = NULL;
  54808. const char *username = "TESTUSER";
  54809. const char *password = "TESTPASSWORD";
  54810. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54811. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54812. SSL_SUCCESS);
  54813. wolfSSL_CTX_free(ctx);
  54814. ctx = NULL;
  54815. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  54816. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  54817. SSL_SUCCESS);
  54818. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  54819. SSL_SUCCESS);
  54820. wolfSSL_CTX_free(ctx);
  54821. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  54822. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  54823. return EXPECT_RESULT();
  54824. }
  54825. static int test_wolfSSL_X509_STORE(void)
  54826. {
  54827. EXPECT_DECLS;
  54828. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54829. X509_STORE *store = NULL;
  54830. #ifdef HAVE_CRL
  54831. X509_STORE_CTX *storeCtx = NULL;
  54832. X509 *ca = NULL;
  54833. X509 *cert = NULL;
  54834. const char srvCert[] = "./certs/server-revoked-cert.pem";
  54835. const char caCert[] = "./certs/ca-cert.pem";
  54836. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  54837. X509_CRL *crl = NULL;
  54838. const char crlPem[] = "./certs/crl/crl.revoked";
  54839. XFILE fp = XBADFILE;
  54840. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  54841. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54842. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  54843. SSL_FILETYPE_PEM)));
  54844. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  54845. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  54846. SSL_FILETYPE_PEM)));
  54847. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  54848. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  54849. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  54850. X509_STORE_free(store);
  54851. store = NULL;
  54852. X509_STORE_CTX_free(storeCtx);
  54853. storeCtx = NULL;
  54854. X509_free(cert);
  54855. cert = NULL;
  54856. X509_free(ca);
  54857. ca = NULL;
  54858. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  54859. /* should fail to verify now after adding in CRL */
  54860. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54861. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  54862. SSL_FILETYPE_PEM)));
  54863. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  54864. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  54865. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  54866. NULL, NULL));
  54867. if (fp != XBADFILE)
  54868. XFCLOSE(fp);
  54869. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  54870. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  54871. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  54872. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  54873. SSL_FILETYPE_PEM)));
  54874. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  54875. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  54876. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  54877. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  54878. X509_CRL_free(crl);
  54879. crl = NULL;
  54880. X509_STORE_free(store);
  54881. store = NULL;
  54882. X509_STORE_CTX_free(storeCtx);
  54883. storeCtx = NULL;
  54884. X509_free(cert);
  54885. cert = NULL;
  54886. X509_free(ca);
  54887. ca = NULL;
  54888. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  54889. #endif /* HAVE_CRL */
  54890. #ifndef WOLFCRYPT_ONLY
  54891. {
  54892. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54893. SSL_CTX* ctx = NULL;
  54894. SSL* ssl = NULL;
  54895. int i;
  54896. for (i = 0; i < 2; i++) {
  54897. #ifndef NO_WOLFSSL_SERVER
  54898. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54899. #else
  54900. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54901. #endif
  54902. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54903. SSL_CTX_set_cert_store(ctx, store);
  54904. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54905. SSL_CTX_set_cert_store(ctx, store);
  54906. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  54907. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54908. SSL_FILETYPE_PEM), SSL_SUCCESS);
  54909. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54910. SSL_FILETYPE_PEM), SSL_SUCCESS);
  54911. ExpectNotNull(ssl = SSL_new(ctx));
  54912. if (i == 0) {
  54913. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  54914. SSL_SUCCESS);
  54915. }
  54916. else {
  54917. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  54918. #ifdef OPENSSL_ALL
  54919. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  54920. #endif
  54921. }
  54922. if (EXPECT_FAIL() || (i == 1)) {
  54923. X509_STORE_free(store);
  54924. store = NULL;
  54925. }
  54926. SSL_free(ssl);
  54927. ssl = NULL;
  54928. SSL_CTX_free(ctx);
  54929. ctx = NULL;
  54930. }
  54931. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54932. }
  54933. #endif
  54934. #endif
  54935. return EXPECT_RESULT();
  54936. }
  54937. static int test_wolfSSL_X509_STORE_load_locations(void)
  54938. {
  54939. EXPECT_DECLS;
  54940. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  54941. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  54942. SSL_CTX *ctx = NULL;
  54943. X509_STORE *store = NULL;
  54944. const char ca_file[] = "./certs/ca-cert.pem";
  54945. const char client_pem_file[] = "./certs/client-cert.pem";
  54946. const char client_der_file[] = "./certs/client-cert.der";
  54947. const char ecc_file[] = "./certs/ecc-key.pem";
  54948. const char certs_path[] = "./certs/";
  54949. const char bad_path[] = "./bad-path/";
  54950. #ifdef HAVE_CRL
  54951. const char crl_path[] = "./certs/crl/";
  54952. const char crl_file[] = "./certs/crl/crl.pem";
  54953. #endif
  54954. #ifndef NO_WOLFSSL_SERVER
  54955. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  54956. #else
  54957. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  54958. #endif
  54959. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  54960. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  54961. WOLFSSL_SUCCESS);
  54962. /* Test bad arguments */
  54963. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  54964. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54965. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54966. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  54967. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54968. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  54969. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54970. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  54971. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54972. #ifdef HAVE_CRL
  54973. /* Test with CRL */
  54974. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  54975. WOLFSSL_SUCCESS);
  54976. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  54977. WOLFSSL_SUCCESS);
  54978. #endif
  54979. /* Test with CA */
  54980. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  54981. WOLFSSL_SUCCESS);
  54982. /* Test with client_cert and certs path */
  54983. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  54984. WOLFSSL_SUCCESS);
  54985. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  54986. WOLFSSL_SUCCESS);
  54987. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  54988. /* Clear nodes */
  54989. ERR_clear_error();
  54990. #endif
  54991. SSL_CTX_free(ctx);
  54992. #endif
  54993. return EXPECT_RESULT();
  54994. }
  54995. static int test_X509_STORE_get0_objects(void)
  54996. {
  54997. EXPECT_DECLS;
  54998. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  54999. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  55000. X509_STORE *store = NULL;
  55001. X509_STORE *store_cpy = NULL;
  55002. SSL_CTX *ctx = NULL;
  55003. X509_OBJECT *obj = NULL;
  55004. STACK_OF(X509_OBJECT) *objs = NULL;
  55005. int i;
  55006. /* Setup store */
  55007. #ifndef NO_WOLFSSL_SERVER
  55008. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  55009. #else
  55010. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  55011. #endif
  55012. ExpectNotNull(store_cpy = X509_STORE_new());
  55013. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  55014. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  55015. WOLFSSL_SUCCESS);
  55016. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  55017. WOLFSSL_SUCCESS);
  55018. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  55019. WOLFSSL_SUCCESS);
  55020. #ifdef HAVE_CRL
  55021. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  55022. WOLFSSL_SUCCESS);
  55023. #endif
  55024. /* Store ready */
  55025. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  55026. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  55027. #ifdef HAVE_CRL
  55028. #ifdef WOLFSSL_SIGNER_DER_CERT
  55029. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  55030. #else
  55031. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  55032. #endif
  55033. #else
  55034. #ifdef WOLFSSL_SIGNER_DER_CERT
  55035. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  55036. #else
  55037. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  55038. #endif
  55039. #endif
  55040. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  55041. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  55042. switch (X509_OBJECT_get_type(obj)) {
  55043. case X509_LU_X509:
  55044. {
  55045. X509* x509 = NULL;
  55046. X509_NAME *subj_name = NULL;
  55047. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  55048. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  55049. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  55050. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  55051. subj_name));
  55052. break;
  55053. }
  55054. case X509_LU_CRL:
  55055. #ifdef HAVE_CRL
  55056. {
  55057. X509_CRL* crl = NULL;
  55058. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  55059. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  55060. break;
  55061. }
  55062. #endif
  55063. case X509_LU_NONE:
  55064. default:
  55065. Fail(("X509_OBJECT_get_type should return x509 or crl "
  55066. "(when built with crl support)"),
  55067. ("Unrecognized X509_OBJECT type or none"));
  55068. }
  55069. }
  55070. X509_STORE_free(store_cpy);
  55071. SSL_CTX_free(ctx);
  55072. #endif
  55073. return EXPECT_RESULT();
  55074. }
  55075. static int test_wolfSSL_BN_CTX(void)
  55076. {
  55077. EXPECT_DECLS;
  55078. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55079. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55080. WOLFSSL_BN_CTX* bn_ctx = NULL;
  55081. WOLFSSL_BIGNUM* t = NULL;
  55082. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  55083. /* No implementation. */
  55084. BN_CTX_init(NULL);
  55085. ExpectNotNull(t = BN_CTX_get(NULL));
  55086. BN_free(t);
  55087. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  55088. BN_free(t);
  55089. #ifndef NO_WOLFSSL_STUB
  55090. /* No implementation. */
  55091. BN_CTX_start(NULL);
  55092. BN_CTX_start(bn_ctx);
  55093. #endif
  55094. BN_CTX_free(NULL);
  55095. BN_CTX_free(bn_ctx);
  55096. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55097. return EXPECT_RESULT();
  55098. }
  55099. static int test_wolfSSL_BN(void)
  55100. {
  55101. EXPECT_DECLS;
  55102. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55103. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55104. BIGNUM* a = NULL;
  55105. BIGNUM* b = NULL;
  55106. BIGNUM* c = NULL;
  55107. BIGNUM* d = NULL;
  55108. BIGNUM emptyBN;
  55109. /* Setup */
  55110. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55111. /* internal not set emptyBN. */
  55112. ExpectNotNull(a = BN_new());
  55113. ExpectNotNull(b = BN_new());
  55114. ExpectNotNull(c = BN_dup(b));
  55115. ExpectNotNull(d = BN_new());
  55116. /* Invalid parameter testing. */
  55117. BN_free(NULL);
  55118. ExpectNull(BN_dup(NULL));
  55119. ExpectNull(BN_dup(&emptyBN));
  55120. ExpectNull(BN_copy(NULL, NULL));
  55121. ExpectNull(BN_copy(b, NULL));
  55122. ExpectNull(BN_copy(NULL, c));
  55123. ExpectNull(BN_copy(b, &emptyBN));
  55124. ExpectNull(BN_copy(&emptyBN, c));
  55125. BN_clear(NULL);
  55126. BN_clear(&emptyBN);
  55127. ExpectIntEQ(BN_num_bytes(NULL), 0);
  55128. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  55129. ExpectIntEQ(BN_num_bits(NULL), 0);
  55130. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  55131. ExpectIntEQ(BN_is_negative(NULL), 0);
  55132. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  55133. /* END Invalid Parameters */
  55134. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  55135. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  55136. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  55137. ExpectIntEQ(BN_num_bits(a), 2);
  55138. ExpectIntEQ(BN_num_bytes(a), 1);
  55139. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  55140. defined(WOLFSSL_SP_INT_NEGATIVE))
  55141. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  55142. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  55143. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  55144. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55145. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  55146. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55147. {
  55148. /* Do additional tests on negative BN conversions. */
  55149. char* ret = NULL;
  55150. ASN1_INTEGER* asn1 = NULL;
  55151. BIGNUM* tmp = NULL;
  55152. /* Sanity check we have a negative BN. */
  55153. ExpectIntEQ(BN_is_negative(c), 1);
  55154. ExpectNotNull(ret = BN_bn2dec(c));
  55155. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55156. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55157. ret = NULL;
  55158. /* Convert to ASN1_INTEGER and back to BN. */
  55159. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  55160. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  55161. /* After converting back BN should be negative and correct. */
  55162. ExpectIntEQ(BN_is_negative(tmp), 1);
  55163. ExpectNotNull(ret = BN_bn2dec(tmp));
  55164. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55165. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55166. ASN1_INTEGER_free(asn1);
  55167. BN_free(tmp);
  55168. }
  55169. #endif
  55170. ExpectIntEQ(BN_get_word(c), 4);
  55171. #endif
  55172. ExpectIntEQ(BN_set_word(a, 3), 1);
  55173. ExpectIntEQ(BN_set_word(b, 3), 1);
  55174. ExpectIntEQ(BN_set_word(c, 4), 1);
  55175. /* NULL == NULL, NULL < num, num > NULL */
  55176. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  55177. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  55178. ExpectIntLT(BN_cmp(NULL, b), 0);
  55179. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  55180. ExpectIntGT(BN_cmp(a, NULL), 0);
  55181. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  55182. ExpectIntEQ(BN_cmp(a, b), 0);
  55183. ExpectIntLT(BN_cmp(a, c), 0);
  55184. ExpectIntGT(BN_cmp(c, b), 0);
  55185. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  55186. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  55187. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  55188. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  55189. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  55190. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  55191. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  55192. #endif
  55193. BN_clear(a);
  55194. BN_free(a);
  55195. BN_free(b);
  55196. BN_free(c);
  55197. BN_clear_free(d);
  55198. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55199. return EXPECT_RESULT();
  55200. }
  55201. static int test_wolfSSL_BN_init(void)
  55202. {
  55203. EXPECT_DECLS;
  55204. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55205. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55206. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  55207. BIGNUM* ap = NULL;
  55208. BIGNUM bv;
  55209. BIGNUM cv;
  55210. BIGNUM dv;
  55211. ExpectNotNull(ap = BN_new());
  55212. BN_init(NULL);
  55213. XMEMSET(&bv, 0, sizeof(bv));
  55214. ExpectNull(BN_dup(&bv));
  55215. BN_init(&bv);
  55216. BN_init(&cv);
  55217. BN_init(&dv);
  55218. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  55219. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  55220. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  55221. /* a^b mod c = */
  55222. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55223. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  55224. /* check result 3^2 mod 5 */
  55225. ExpectIntEQ(BN_get_word(&dv), 4);
  55226. /* a*b mod c = */
  55227. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55228. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  55229. /* check result 3*2 mod 5 */
  55230. ExpectIntEQ(BN_get_word(&dv), 1);
  55231. BN_free(ap);
  55232. #endif
  55233. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55234. return EXPECT_RESULT();
  55235. }
  55236. static int test_wolfSSL_BN_enc_dec(void)
  55237. {
  55238. EXPECT_DECLS;
  55239. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55240. BIGNUM* a = NULL;
  55241. BIGNUM* b = NULL;
  55242. BIGNUM* c = NULL;
  55243. BIGNUM emptyBN;
  55244. char* str = NULL;
  55245. const char* emptyStr = "";
  55246. const char* numberStr = "12345";
  55247. const char* badStr = "g12345";
  55248. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55249. const char* twoStr = "2";
  55250. #endif
  55251. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  55252. unsigned char outNum[5];
  55253. /* Setup */
  55254. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55255. ExpectNotNull(a = BN_new());
  55256. ExpectNotNull(b = BN_new());
  55257. /* Invalid parameters */
  55258. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  55259. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  55260. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  55261. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  55262. ExpectNull(BN_bn2hex(NULL));
  55263. ExpectNull(BN_bn2hex(&emptyBN));
  55264. ExpectNull(BN_bn2dec(NULL));
  55265. ExpectNull(BN_bn2dec(&emptyBN));
  55266. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  55267. BN_free(a);
  55268. ExpectNotNull(a = BN_new());
  55269. ExpectIntEQ(BN_set_word(a, 2), 1);
  55270. ExpectNull(BN_bin2bn(binNum, -1, a));
  55271. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  55272. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  55273. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  55274. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  55275. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  55276. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  55277. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  55278. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  55279. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  55280. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  55281. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  55282. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  55283. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  55284. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  55285. ExpectIntEQ(BN_set_word(a, 2), 1);
  55286. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  55287. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  55288. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  55289. ExpectIntEQ(BN_cmp(a, b), 0);
  55290. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  55291. ExpectIntEQ(BN_cmp(a, b), -1);
  55292. ExpectNotNull(str = BN_bn2hex(a));
  55293. ExpectNotNull(BN_hex2bn(&b, str));
  55294. ExpectIntEQ(BN_cmp(a, b), 0);
  55295. ExpectNotNull(BN_hex2bn(&b, numberStr));
  55296. ExpectIntEQ(BN_cmp(a, b), -1);
  55297. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55298. str = NULL;
  55299. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55300. ExpectNotNull(str = BN_bn2dec(a));
  55301. ExpectStrEQ(str, twoStr);
  55302. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55303. str = NULL;
  55304. #ifndef NO_RSA
  55305. ExpectNotNull(str = BN_bn2dec(a));
  55306. ExpectNotNull(BN_dec2bn(&b, str));
  55307. ExpectIntEQ(BN_cmp(a, b), 0);
  55308. ExpectNotNull(BN_dec2bn(&b, numberStr));
  55309. ExpectIntEQ(BN_cmp(a, b), -1);
  55310. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55311. str = NULL;
  55312. #else
  55313. /* No implementation - fail with good parameters. */
  55314. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  55315. #endif
  55316. #endif
  55317. BN_free(b);
  55318. BN_free(a);
  55319. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55320. return EXPECT_RESULT();
  55321. }
  55322. static int test_wolfSSL_BN_word(void)
  55323. {
  55324. EXPECT_DECLS;
  55325. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55326. BIGNUM* a = NULL;
  55327. BIGNUM* b = NULL;
  55328. BIGNUM* c = NULL;
  55329. BIGNUM av;
  55330. ExpectNotNull(a = BN_new());
  55331. ExpectNotNull(b = BN_new());
  55332. ExpectNotNull(c = BN_new());
  55333. XMEMSET(&av, 0, sizeof(av));
  55334. /* Invalid parameter. */
  55335. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  55336. ExpectIntEQ(BN_add_word(&av, 3), 0);
  55337. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  55338. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  55339. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  55340. ExpectIntEQ(BN_set_word(&av, 3), 0);
  55341. ExpectIntEQ(BN_get_word(NULL), 0);
  55342. ExpectIntEQ(BN_get_word(&av), 0);
  55343. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  55344. ExpectIntEQ(BN_is_word(&av, 3), 0);
  55345. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55346. !defined(NO_DSA))
  55347. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  55348. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  55349. #endif
  55350. ExpectIntEQ(BN_one(NULL), 0);
  55351. ExpectIntEQ(BN_one(&av), 0);
  55352. BN_zero(NULL);
  55353. BN_zero(&av);
  55354. ExpectIntEQ(BN_is_one(NULL), 0);
  55355. ExpectIntEQ(BN_is_one(&av), 0);
  55356. ExpectIntEQ(BN_is_zero(NULL), 0);
  55357. ExpectIntEQ(BN_is_zero(&av), 0);
  55358. ExpectIntEQ(BN_set_word(a, 3), 1);
  55359. ExpectIntEQ(BN_set_word(b, 2), 1);
  55360. ExpectIntEQ(BN_set_word(c, 5), 1);
  55361. /* a + 3 = */
  55362. ExpectIntEQ(BN_add_word(a, 3), 1);
  55363. /* check result 3 + 3*/
  55364. ExpectIntEQ(BN_get_word(a), 6);
  55365. ExpectIntEQ(BN_is_word(a, 6), 1);
  55366. ExpectIntEQ(BN_is_word(a, 5), 0);
  55367. /* set a back to 3 */
  55368. ExpectIntEQ(BN_set_word(a, 3), 1);
  55369. /* a - 3 = */
  55370. ExpectIntEQ(BN_sub_word(a, 3), 1);
  55371. /* check result 3 - 3*/
  55372. ExpectIntEQ(BN_get_word(a), 0);
  55373. ExpectIntEQ(BN_one(a), 1);
  55374. ExpectIntEQ(BN_is_word(a, 1), 1);
  55375. ExpectIntEQ(BN_is_word(a, 0), 0);
  55376. ExpectIntEQ(BN_is_one(a), 1);
  55377. ExpectIntEQ(BN_is_zero(a), 0);
  55378. BN_zero(a);
  55379. ExpectIntEQ(BN_is_word(a, 0), 1);
  55380. ExpectIntEQ(BN_is_word(a, 1), 0);
  55381. ExpectIntEQ(BN_is_zero(a), 1);
  55382. ExpectIntEQ(BN_is_one(a), 0);
  55383. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55384. !defined(NO_DSA))
  55385. ExpectIntEQ(BN_set_word(a, 5), 1);
  55386. ExpectIntEQ(BN_mod_word(a, 3), 2);
  55387. ExpectIntEQ(BN_mod_word(a, 0), -1);
  55388. #endif
  55389. BN_free(c);
  55390. BN_free(b);
  55391. BN_free(a);
  55392. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55393. return EXPECT_RESULT();
  55394. }
  55395. static int test_wolfSSL_BN_bits(void)
  55396. {
  55397. EXPECT_DECLS;
  55398. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55399. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55400. BIGNUM* a = NULL;
  55401. BIGNUM emptyBN;
  55402. /* Setup */
  55403. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55404. ExpectNotNull(a = BN_new());
  55405. /* Invalid parameters. */
  55406. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  55407. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  55408. ExpectIntEQ(BN_set_bit(a, -1), 0);
  55409. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  55410. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  55411. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  55412. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  55413. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  55414. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  55415. ExpectIntEQ(BN_is_odd(NULL), 0);
  55416. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  55417. ExpectIntEQ(BN_set_word(a, 0), 1);
  55418. ExpectIntEQ(BN_is_zero(a), 1);
  55419. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  55420. ExpectIntEQ(BN_is_zero(a), 0);
  55421. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  55422. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  55423. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  55424. ExpectIntEQ(BN_is_zero(a), 1);
  55425. ExpectIntEQ(BN_set_bit(a, 0), 1);
  55426. ExpectIntEQ(BN_is_odd(a), 1);
  55427. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55428. ExpectIntEQ(BN_is_odd(a), 0);
  55429. ExpectIntEQ(BN_set_bit(a, 1), 1);
  55430. ExpectIntEQ(BN_is_odd(a), 0);
  55431. ExpectIntEQ(BN_set_bit(a, 129), 1);
  55432. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  55433. #ifndef NO_WOLFSSL_STUB
  55434. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  55435. #endif
  55436. BN_free(a);
  55437. #endif
  55438. return EXPECT_RESULT();
  55439. }
  55440. static int test_wolfSSL_BN_shift(void)
  55441. {
  55442. EXPECT_DECLS;
  55443. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55444. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55445. BIGNUM* a = NULL;
  55446. BIGNUM* b = NULL;
  55447. BIGNUM emptyBN;
  55448. /* Setup */
  55449. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55450. ExpectNotNull(a = BN_new());
  55451. ExpectNotNull(b = BN_new());
  55452. /* Invalid parameters. */
  55453. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  55454. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  55455. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  55456. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  55457. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  55458. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  55459. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  55460. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  55461. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  55462. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  55463. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  55464. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  55465. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  55466. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  55467. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  55468. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  55469. ExpectIntEQ(BN_set_word(a, 1), 1);
  55470. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  55471. ExpectIntEQ(BN_is_word(b, 2), 1);
  55472. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  55473. ExpectIntEQ(BN_is_word(a, 2), 1);
  55474. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  55475. ExpectIntEQ(BN_is_word(b, 1), 1);
  55476. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  55477. ExpectIntEQ(BN_is_word(a, 1), 1);
  55478. BN_free(b);
  55479. BN_free(a);
  55480. #endif
  55481. return EXPECT_RESULT();
  55482. }
  55483. static int test_wolfSSL_BN_math(void)
  55484. {
  55485. EXPECT_DECLS;
  55486. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55487. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55488. BIGNUM* a = NULL;
  55489. BIGNUM* b = NULL;
  55490. BIGNUM* r = NULL;
  55491. BIGNUM* rem = NULL;
  55492. BIGNUM emptyBN;
  55493. BN_ULONG val1;
  55494. BN_ULONG val2;
  55495. /* Setup */
  55496. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55497. ExpectNotNull(a = BN_new());
  55498. ExpectNotNull(b = BN_new());
  55499. ExpectNotNull(r = BN_new());
  55500. ExpectNotNull(rem = BN_new());
  55501. /* Invalid parameters. */
  55502. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  55503. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  55504. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  55505. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  55506. ExpectIntEQ(BN_add(r, a, NULL), 0);
  55507. ExpectIntEQ(BN_add(r, NULL, b), 0);
  55508. ExpectIntEQ(BN_add(NULL, a, b), 0);
  55509. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  55510. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  55511. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  55512. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  55513. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  55514. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  55515. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  55516. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  55517. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  55518. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  55519. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  55520. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  55521. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  55522. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  55523. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  55524. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  55525. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  55526. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  55527. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  55528. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  55529. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  55530. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  55531. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  55532. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  55533. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  55534. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  55535. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  55536. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  55537. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55538. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  55539. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  55540. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  55541. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  55542. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  55543. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  55544. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  55545. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  55546. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  55547. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  55548. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  55549. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  55550. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  55551. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  55552. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  55553. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55554. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55555. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  55556. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  55557. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  55558. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  55559. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  55560. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  55561. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  55562. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  55563. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  55564. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  55565. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  55566. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  55567. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  55568. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  55569. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55570. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  55571. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  55572. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  55573. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  55574. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  55575. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  55576. /* END Invalid parameters. */
  55577. val1 = 8;
  55578. val2 = 3;
  55579. ExpectIntEQ(BN_set_word(a, val1), 1);
  55580. ExpectIntEQ(BN_set_word(b, val2), 1);
  55581. ExpectIntEQ(BN_add(r, a, b), 1);
  55582. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  55583. ExpectIntEQ(BN_sub(r, a, b), 1);
  55584. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  55585. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  55586. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  55587. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  55588. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  55589. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  55590. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  55591. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  55592. BN_free(rem);
  55593. BN_free(r);
  55594. BN_free(b);
  55595. BN_free(a);
  55596. #endif
  55597. return EXPECT_RESULT();
  55598. }
  55599. static int test_wolfSSL_BN_math_mod(void)
  55600. {
  55601. EXPECT_DECLS;
  55602. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55603. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55604. BIGNUM* a = NULL;
  55605. BIGNUM* b = NULL;
  55606. BIGNUM* m = NULL;
  55607. BIGNUM* r = NULL;
  55608. BIGNUM* t = NULL;
  55609. BIGNUM emptyBN;
  55610. BN_ULONG val1;
  55611. BN_ULONG val2;
  55612. BN_ULONG val3;
  55613. /* Setup */
  55614. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55615. ExpectNotNull(a = BN_new());
  55616. ExpectNotNull(b = BN_new());
  55617. ExpectNotNull(m = BN_new());
  55618. ExpectNotNull(r = BN_new());
  55619. /* Invalid parameters. */
  55620. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  55621. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  55622. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  55623. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  55624. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  55625. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  55626. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  55627. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  55628. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  55629. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55630. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55631. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55632. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55633. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55634. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  55635. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  55636. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  55637. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  55638. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  55639. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  55640. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  55641. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  55642. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  55643. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  55644. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  55645. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  55646. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  55647. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55648. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55649. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55650. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55651. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55652. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  55653. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  55654. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  55655. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  55656. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  55657. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  55658. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  55659. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  55660. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  55661. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  55662. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  55663. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  55664. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  55665. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55666. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55667. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55668. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55669. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55670. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  55671. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  55672. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  55673. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  55674. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  55675. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55676. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55677. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55678. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55679. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  55680. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  55681. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  55682. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  55683. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  55684. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  55685. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  55686. /* END Invalid parameters. */
  55687. val1 = 9;
  55688. val2 = 13;
  55689. val3 = 5;
  55690. ExpectIntEQ(BN_set_word(a, val1), 1);
  55691. ExpectIntEQ(BN_set_word(b, val2), 1);
  55692. ExpectIntEQ(BN_set_word(m, val3), 1);
  55693. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  55694. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  55695. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  55696. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  55697. ExpectIntEQ(BN_set_word(a, 2), 1);
  55698. ExpectIntEQ(BN_set_word(b, 3), 1);
  55699. ExpectIntEQ(BN_set_word(m, 5), 1);
  55700. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  55701. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  55702. ExpectIntEQ(BN_is_word(r, 3), 1);
  55703. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  55704. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  55705. ExpectIntEQ(BN_is_word(r, 3), 1);
  55706. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  55707. ExpectIntEQ(BN_is_word(t, 3), 1);
  55708. BN_free(t);
  55709. /* No inverse case. No inverse when a divides b. */
  55710. ExpectIntEQ(BN_set_word(a, 3), 1);
  55711. ExpectIntEQ(BN_set_word(m, 9), 1);
  55712. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  55713. BN_free(r);
  55714. BN_free(m);
  55715. BN_free(b);
  55716. BN_free(a);
  55717. #endif
  55718. return EXPECT_RESULT();
  55719. }
  55720. static int test_wolfSSL_BN_math_other(void)
  55721. {
  55722. EXPECT_DECLS;
  55723. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55724. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55725. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  55726. BIGNUM* a = NULL;
  55727. BIGNUM* b = NULL;
  55728. BIGNUM* r = NULL;
  55729. BIGNUM emptyBN;
  55730. /* Setup */
  55731. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55732. ExpectNotNull(a = BN_new());
  55733. ExpectNotNull(b = BN_new());
  55734. ExpectNotNull(r = BN_new());
  55735. /* Invalid parameters. */
  55736. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  55737. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  55738. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  55739. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  55740. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  55741. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  55742. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  55743. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55744. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  55745. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  55746. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  55747. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  55748. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  55749. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  55750. /* END Invalid parameters. */
  55751. /* No common factors between 2 and 3. */
  55752. ExpectIntEQ(BN_set_word(a, 2), 1);
  55753. ExpectIntEQ(BN_set_word(b, 3), 1);
  55754. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  55755. ExpectIntEQ(BN_is_word(r, 1), 1);
  55756. /* 3 is largest value that divides both 6 and 9. */
  55757. ExpectIntEQ(BN_set_word(a, 6), 1);
  55758. ExpectIntEQ(BN_set_word(b, 9), 1);
  55759. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  55760. ExpectIntEQ(BN_is_word(r, 3), 1);
  55761. /* GCD of 0 and 0 is undefined. */
  55762. ExpectIntEQ(BN_set_word(a, 0), 1);
  55763. ExpectIntEQ(BN_set_word(b, 0), 1);
  55764. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  55765. /* Teardown */
  55766. BN_free(r);
  55767. BN_free(b);
  55768. BN_free(a);
  55769. #endif
  55770. #endif
  55771. return EXPECT_RESULT();
  55772. }
  55773. static int test_wolfSSL_BN_rand(void)
  55774. {
  55775. EXPECT_DECLS;
  55776. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  55777. BIGNUM* bn = NULL;
  55778. BIGNUM* range = NULL;
  55779. BIGNUM emptyBN;
  55780. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55781. ExpectNotNull(bn = BN_new());
  55782. ExpectNotNull(range = BN_new());
  55783. /* Invalid parameters. */
  55784. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  55785. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  55786. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  55787. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  55788. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  55789. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  55790. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  55791. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  55792. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  55793. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  55794. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  55795. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  55796. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  55797. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  55798. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  55799. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  55800. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  55801. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  55802. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  55803. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55804. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55805. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55806. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55807. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55808. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55809. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55810. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55811. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55812. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55813. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55814. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55815. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55816. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55817. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55818. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55819. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  55820. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55821. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  55822. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55823. /* 1 bit random value must have no more than one top bit set. */
  55824. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55825. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55826. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55827. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55828. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55829. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  55830. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  55831. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  55832. /* END Invalid parameters. */
  55833. /* 0 bit random: 0. */
  55834. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55835. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55836. ExpectIntEQ(BN_is_zero(bn), 1);
  55837. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  55838. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  55839. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55840. ExpectIntEQ(BN_is_zero(bn), 1);
  55841. /* 1 bit random: 0 or 1. */
  55842. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  55843. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55844. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  55845. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55846. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55847. ExpectIntEQ(BN_get_word(bn), 1);
  55848. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55849. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55850. ExpectIntEQ(BN_get_word(bn), 1);
  55851. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  55852. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55853. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  55854. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55855. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55856. ExpectIntEQ(BN_get_word(bn), 1);
  55857. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  55858. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55859. ExpectIntEQ(BN_get_word(bn), 1);
  55860. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55861. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55862. ExpectIntEQ(BN_num_bits(bn), 8);
  55863. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55864. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55865. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55866. ExpectIntEQ(BN_num_bits(bn), 8);
  55867. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55868. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  55869. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55870. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55871. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  55872. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  55873. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55874. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  55875. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  55876. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55877. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55878. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  55879. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  55880. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  55881. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  55882. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  55883. * requested number of bits up to the nearest multiple of 8. E.g. in this
  55884. * case, requesting a 13-bit random number would actually return a 16-bit
  55885. * random number. */
  55886. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  55887. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55888. ExpectIntEQ(BN_num_bits(bn), 13);
  55889. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  55890. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  55891. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55892. ExpectIntEQ(BN_set_word(range, 0), 1);
  55893. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55894. ExpectIntEQ(BN_set_word(range, 1), 1);
  55895. ExpectIntEQ(BN_rand_range(bn, range), 1);
  55896. BN_free(bn);
  55897. BN_free(range);
  55898. #endif
  55899. return EXPECT_RESULT();
  55900. }
  55901. static int test_wolfSSL_BN_prime(void)
  55902. {
  55903. EXPECT_DECLS;
  55904. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55905. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55906. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  55907. BIGNUM* a = NULL;
  55908. BIGNUM* add = NULL;
  55909. BIGNUM* rem = NULL;
  55910. BIGNUM emptyBN;
  55911. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55912. ExpectNotNull(a = BN_new());
  55913. ExpectNotNull(add = BN_new());
  55914. ExpectNotNull(rem = BN_new());
  55915. /* Invalid parameters. */
  55916. /* BN_generate_prime_ex()
  55917. * prime - must have valid BIGNUM
  55918. * bits - Greater then 0
  55919. * safe - not supported, must be 0
  55920. * add - not supported, must be NULL
  55921. * rem - not supported, must be NULL
  55922. * cb - anything
  55923. */
  55924. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  55925. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  55926. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  55927. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  55928. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  55929. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  55930. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  55931. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  55932. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  55933. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  55934. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  55935. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  55936. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  55937. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  55938. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  55939. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  55940. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  55941. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  55942. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  55943. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  55944. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  55945. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  55946. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  55947. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  55948. /* END Invalid parameters. */
  55949. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  55950. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  55951. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55952. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  55953. BN_free(rem);
  55954. BN_free(add);
  55955. BN_free(a);
  55956. #endif
  55957. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55958. return EXPECT_RESULT();
  55959. }
  55960. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55961. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  55962. #define TEST_ARG 0x1234
  55963. static void msg_cb(int write_p, int version, int content_type,
  55964. const void *buf, size_t len, SSL *ssl, void *arg)
  55965. {
  55966. (void)write_p;
  55967. (void)version;
  55968. (void)content_type;
  55969. (void)buf;
  55970. (void)len;
  55971. (void)ssl;
  55972. AssertTrue(arg == (void*)TEST_ARG);
  55973. }
  55974. #endif
  55975. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  55976. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  55977. #if defined(SESSION_CERTS)
  55978. #include "wolfssl/internal.h"
  55979. #endif
  55980. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  55981. {
  55982. EXPECT_DECLS;
  55983. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  55984. STACK_OF(X509)* sk = NULL;
  55985. X509* x509 = NULL;
  55986. int i, num;
  55987. BIO* bio = NULL;
  55988. #endif
  55989. ExpectNotNull(ctx);
  55990. ExpectNotNull(ssl);
  55991. fprintf(stderr, "\n===== msgcb called ====\n");
  55992. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  55993. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  55994. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  55995. ExpectNotNull(SSL_get0_verified_chain(ssl));
  55996. #endif
  55997. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  55998. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  55999. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  56000. if (sk == NULL) {
  56001. BIO_free(bio);
  56002. return TEST_FAIL;
  56003. }
  56004. num = sk_X509_num(sk);
  56005. ExpectTrue(num > 0);
  56006. for (i = 0; i < num; i++) {
  56007. ExpectNotNull(x509 = sk_X509_value(sk,i));
  56008. if (x509 == NULL)
  56009. break;
  56010. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  56011. X509_print(bio,x509);
  56012. fprintf(stderr, "\n\n");
  56013. }
  56014. BIO_free(bio);
  56015. #endif
  56016. return EXPECT_RESULT();
  56017. }
  56018. #endif
  56019. static int test_wolfSSL_msgCb(void)
  56020. {
  56021. EXPECT_DECLS;
  56022. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  56023. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56024. test_ssl_cbf client_cb;
  56025. test_ssl_cbf server_cb;
  56026. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56027. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56028. #ifndef WOLFSSL_NO_TLS12
  56029. client_cb.method = wolfTLSv1_2_client_method;
  56030. server_cb.method = wolfTLSv1_2_server_method;
  56031. #else
  56032. client_cb.method = wolfTLSv1_3_client_method;
  56033. server_cb.method = wolfTLSv1_3_server_method;
  56034. #endif
  56035. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56036. &server_cb, msgCb), TEST_SUCCESS);
  56037. #endif
  56038. return EXPECT_RESULT();
  56039. }
  56040. static int test_wolfSSL_either_side(void)
  56041. {
  56042. EXPECT_DECLS;
  56043. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56044. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56045. test_ssl_cbf client_cb;
  56046. test_ssl_cbf server_cb;
  56047. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56048. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56049. /* Use different CTX for client and server */
  56050. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56051. ExpectNotNull(client_cb.ctx);
  56052. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56053. ExpectNotNull(server_cb.ctx);
  56054. /* we are responsible for free'ing WOLFSSL_CTX */
  56055. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56056. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56057. &server_cb, NULL), TEST_SUCCESS);
  56058. wolfSSL_CTX_free(client_cb.ctx);
  56059. wolfSSL_CTX_free(server_cb.ctx);
  56060. #endif
  56061. return EXPECT_RESULT();
  56062. }
  56063. static int test_wolfSSL_DTLS_either_side(void)
  56064. {
  56065. EXPECT_DECLS;
  56066. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56067. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  56068. test_ssl_cbf client_cb;
  56069. test_ssl_cbf server_cb;
  56070. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56071. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56072. /* Use different CTX for client and server */
  56073. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56074. ExpectNotNull(client_cb.ctx);
  56075. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56076. ExpectNotNull(server_cb.ctx);
  56077. /* we are responsible for free'ing WOLFSSL_CTX */
  56078. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56079. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56080. &server_cb, NULL), TEST_SUCCESS);
  56081. wolfSSL_CTX_free(client_cb.ctx);
  56082. wolfSSL_CTX_free(server_cb.ctx);
  56083. #endif
  56084. return EXPECT_RESULT();
  56085. }
  56086. static int test_generate_cookie(void)
  56087. {
  56088. EXPECT_DECLS;
  56089. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  56090. SSL_CTX* ctx = NULL;
  56091. SSL* ssl = NULL;
  56092. byte buf[FOURK_BUF] = {0};
  56093. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  56094. ExpectNotNull(ssl = SSL_new(ctx));
  56095. /* Test unconnected */
  56096. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  56097. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  56098. wolfSSL_SetCookieCtx(ssl, ctx);
  56099. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  56100. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  56101. SSL_free(ssl);
  56102. SSL_CTX_free(ctx);
  56103. #endif
  56104. return EXPECT_RESULT();
  56105. }
  56106. static int test_wolfSSL_set_options(void)
  56107. {
  56108. EXPECT_DECLS;
  56109. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56110. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56111. WOLFSSL* ssl = NULL;
  56112. WOLFSSL_CTX* ctx = NULL;
  56113. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56114. char appData[] = "extra msg";
  56115. #endif
  56116. #ifdef OPENSSL_EXTRA
  56117. unsigned char protos[] = {
  56118. 7, 't', 'l', 's', '/', '1', '.', '2',
  56119. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  56120. };
  56121. unsigned int len = sizeof(protos);
  56122. void *arg = (void *)TEST_ARG;
  56123. #endif
  56124. #ifndef NO_WOLFSSL_SERVER
  56125. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56126. #else
  56127. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56128. #endif
  56129. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56130. WOLFSSL_FILETYPE_PEM));
  56131. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56132. WOLFSSL_FILETYPE_PEM));
  56133. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  56134. == WOLFSSL_OP_NO_TLSv1);
  56135. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  56136. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56137. WOLFSSL_OP_NO_SSLv2)), 0);
  56138. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56139. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56140. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  56141. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56142. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56143. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56144. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56145. WOLFSSL_OP_NO_COMPRESSION));
  56146. wolfSSL_CTX_free(ctx);
  56147. ctx = NULL;
  56148. #ifndef NO_WOLFSSL_SERVER
  56149. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56150. #else
  56151. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56152. #endif
  56153. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56154. WOLFSSL_FILETYPE_PEM));
  56155. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56156. WOLFSSL_FILETYPE_PEM));
  56157. #ifdef OPENSSL_EXTRA
  56158. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  56159. #endif
  56160. ExpectNotNull(ssl = wolfSSL_new(ctx));
  56161. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56162. #ifdef HAVE_EX_DATA
  56163. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  56164. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56165. if (ssl != NULL) {
  56166. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  56167. appData, sizeof(appData)), 0);
  56168. }
  56169. #else
  56170. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56171. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56172. #endif
  56173. #endif
  56174. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  56175. WOLFSSL_OP_NO_TLSv1);
  56176. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  56177. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56178. WOLFSSL_OP_NO_SSLv2)), 0);
  56179. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56180. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56181. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  56182. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56183. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56184. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56185. #ifdef OPENSSL_EXTRA
  56186. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56187. WOLFSSL_OP_NO_COMPRESSION));
  56188. #endif
  56189. #ifdef OPENSSL_EXTRA
  56190. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  56191. wolfSSL_set_msg_callback_arg(ssl, arg);
  56192. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56193. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  56194. #else
  56195. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  56196. #endif
  56197. #endif
  56198. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  56199. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  56200. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  56201. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  56202. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56203. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  56204. #else
  56205. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  56206. #endif
  56207. #endif /* HAVE_ALPN && !NO_BIO */
  56208. #endif
  56209. wolfSSL_free(ssl);
  56210. wolfSSL_CTX_free(ctx);
  56211. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56212. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56213. return EXPECT_RESULT();
  56214. }
  56215. static int test_wolfSSL_sk_SSL_CIPHER(void)
  56216. {
  56217. EXPECT_DECLS;
  56218. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  56219. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56220. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56221. SSL* ssl = NULL;
  56222. SSL_CTX* ctx = NULL;
  56223. STACK_OF(SSL_CIPHER) *sk = NULL;
  56224. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  56225. #ifndef NO_WOLFSSL_SERVER
  56226. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56227. #else
  56228. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56229. #endif
  56230. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  56231. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56232. ExpectNotNull(ssl = SSL_new(ctx));
  56233. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  56234. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  56235. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  56236. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  56237. /* error case because connection has not been established yet */
  56238. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  56239. sk_SSL_CIPHER_free(dupSk);
  56240. /* sk is pointer to internal struct that should be free'd in SSL_free */
  56241. SSL_free(ssl);
  56242. SSL_CTX_free(ctx);
  56243. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56244. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56245. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56246. return EXPECT_RESULT();
  56247. }
  56248. static int test_wolfSSL_set1_curves_list(void)
  56249. {
  56250. EXPECT_DECLS;
  56251. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  56252. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56253. SSL* ssl = NULL;
  56254. SSL_CTX* ctx = NULL;
  56255. #ifndef NO_WOLFSSL_SERVER
  56256. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56257. #else
  56258. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56259. #endif
  56260. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  56261. SSL_FILETYPE_PEM));
  56262. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  56263. ExpectNotNull(ssl = SSL_new(ctx));
  56264. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56265. #ifdef HAVE_ECC
  56266. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56267. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  56268. #endif
  56269. #ifdef HAVE_CURVE25519
  56270. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  56271. #else
  56272. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56273. #endif
  56274. #ifdef HAVE_CURVE448
  56275. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  56276. #else
  56277. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56278. #endif
  56279. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56280. #ifdef HAVE_ECC
  56281. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56282. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  56283. #endif
  56284. #ifdef HAVE_CURVE25519
  56285. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  56286. #else
  56287. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56288. #endif
  56289. #ifdef HAVE_CURVE448
  56290. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  56291. #else
  56292. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56293. #endif
  56294. SSL_free(ssl);
  56295. SSL_CTX_free(ctx);
  56296. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56297. #endif
  56298. return EXPECT_RESULT();
  56299. }
  56300. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56301. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56302. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  56303. {
  56304. static int counter = 0;
  56305. EXPECT_DECLS;
  56306. if (counter % 2) {
  56307. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  56308. WOLFSSL_SUCCESS);
  56309. }
  56310. else {
  56311. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  56312. WOLFSSL_SUCCESS);
  56313. }
  56314. /* Ciphersuites that require curves */
  56315. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  56316. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  56317. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  56318. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  56319. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  56320. "ECDHE-ECDSA-CHACHA20-POLY1305");
  56321. counter++;
  56322. return EXPECT_RESULT();
  56323. }
  56324. #endif
  56325. static int test_wolfSSL_curves_mismatch(void)
  56326. {
  56327. EXPECT_DECLS;
  56328. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56329. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56330. test_ssl_cbf func_cb_client;
  56331. test_ssl_cbf func_cb_server;
  56332. size_t i;
  56333. struct {
  56334. method_provider client_meth;
  56335. method_provider server_meth;
  56336. const char* desc;
  56337. int client_last_err;
  56338. int server_last_err;
  56339. } test_params[] = {
  56340. #ifdef WOLFSSL_TLS13
  56341. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  56342. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  56343. #endif
  56344. #ifndef WOLFSSL_NO_TLS12
  56345. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  56346. WC_NO_ERR_TRACE(FATAL_ERROR),
  56347. #ifdef OPENSSL_EXTRA
  56348. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56349. #else
  56350. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56351. #endif
  56352. },
  56353. #endif
  56354. #ifndef NO_OLD_TLS
  56355. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  56356. WC_NO_ERR_TRACE(FATAL_ERROR),
  56357. #ifdef OPENSSL_EXTRA
  56358. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56359. #else
  56360. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56361. #endif
  56362. },
  56363. #endif
  56364. };
  56365. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  56366. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  56367. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  56368. printf("\tTesting with %s...\n", test_params[i].desc);
  56369. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56370. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56371. func_cb_client.method = test_params[i].client_meth;
  56372. func_cb_server.method = test_params[i].server_meth;
  56373. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  56374. &func_cb_server, NULL), TEST_FAIL);
  56375. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  56376. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  56377. if (!EXPECT_SUCCESS())
  56378. break;
  56379. printf("\t%s passed\n", test_params[i].desc);
  56380. }
  56381. #endif
  56382. return EXPECT_RESULT();
  56383. }
  56384. static int test_wolfSSL_set1_sigalgs_list(void)
  56385. {
  56386. EXPECT_DECLS;
  56387. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56388. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56389. SSL* ssl = NULL;
  56390. SSL_CTX* ctx = NULL;
  56391. #ifndef NO_WOLFSSL_SERVER
  56392. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56393. #else
  56394. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56395. #endif
  56396. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56397. SSL_FILETYPE_PEM));
  56398. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56399. ExpectNotNull(ssl = SSL_new(ctx));
  56400. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56401. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56402. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56403. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56404. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56405. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56406. #ifndef NO_RSA
  56407. #ifndef NO_SHA256
  56408. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56409. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56410. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56411. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56412. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  56413. WOLFSSL_SUCCESS);
  56414. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  56415. WOLFSSL_SUCCESS);
  56416. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  56417. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56418. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  56419. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56420. #ifdef WC_RSA_PSS
  56421. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  56422. WOLFSSL_SUCCESS);
  56423. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  56424. WOLFSSL_SUCCESS);
  56425. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  56426. WOLFSSL_SUCCESS);
  56427. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  56428. WOLFSSL_SUCCESS);
  56429. #endif
  56430. #ifdef WOLFSSL_SHA512
  56431. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56432. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56433. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56434. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56435. #elif defined(WOLFSSL_SHA384)
  56436. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56437. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56438. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56439. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56440. #endif
  56441. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56442. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56443. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  56444. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56445. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  56446. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56447. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  56448. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56449. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  56450. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56451. #endif
  56452. #endif
  56453. #ifdef HAVE_ECC
  56454. #ifndef NO_SHA256
  56455. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  56456. WOLFSSL_SUCCESS);
  56457. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  56458. WOLFSSL_SUCCESS);
  56459. #ifdef WOLFSSL_SHA512
  56460. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56461. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56462. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56463. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56464. #elif defined(WOLFSSL_SHA384)
  56465. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56466. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56467. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56468. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56469. #endif
  56470. #endif
  56471. #endif
  56472. #ifdef HAVE_ED25519
  56473. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  56474. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  56475. #endif
  56476. #ifdef HAVE_ED448
  56477. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  56478. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  56479. #endif
  56480. #ifndef NO_DSA
  56481. #ifndef NO_SHA256
  56482. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  56483. WOLFSSL_SUCCESS);
  56484. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  56485. WOLFSSL_SUCCESS);
  56486. #endif
  56487. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  56488. defined(WOLFSSL_ALLOW_TLS_SHA1))
  56489. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  56490. WOLFSSL_SUCCESS);
  56491. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  56492. WOLFSSL_SUCCESS);
  56493. #endif
  56494. #endif
  56495. SSL_free(ssl);
  56496. SSL_CTX_free(ctx);
  56497. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56498. #endif
  56499. return EXPECT_RESULT();
  56500. }
  56501. /* Testing wolfSSL_set_tlsext_status_type function.
  56502. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  56503. */
  56504. static int test_wolfSSL_set_tlsext_status_type(void)
  56505. {
  56506. EXPECT_DECLS;
  56507. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  56508. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  56509. SSL* ssl = NULL;
  56510. SSL_CTX* ctx = NULL;
  56511. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56512. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56513. SSL_FILETYPE_PEM));
  56514. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56515. ExpectNotNull(ssl = SSL_new(ctx));
  56516. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  56517. SSL_SUCCESS);
  56518. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  56519. SSL_free(ssl);
  56520. SSL_CTX_free(ctx);
  56521. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  56522. return EXPECT_RESULT();
  56523. }
  56524. #ifndef NO_BIO
  56525. static int test_wolfSSL_PEM_read_bio(void)
  56526. {
  56527. EXPECT_DECLS;
  56528. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56529. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56530. byte buff[6000];
  56531. XFILE f = XBADFILE;
  56532. int bytes;
  56533. X509* x509 = NULL;
  56534. BIO* bio = NULL;
  56535. BUF_MEM* buf = NULL;
  56536. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  56537. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  56538. if (f != XBADFILE)
  56539. XFCLOSE(f);
  56540. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56541. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  56542. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  56543. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56544. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  56545. /* BIO should return the set EOF value */
  56546. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  56547. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  56548. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  56549. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  56550. BIO_free(bio);
  56551. BUF_MEM_free(buf);
  56552. X509_free(x509);
  56553. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  56554. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56555. return EXPECT_RESULT();
  56556. }
  56557. #if defined(OPENSSL_EXTRA)
  56558. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  56559. long argl, long ret)
  56560. {
  56561. (void)bio;
  56562. (void)cmd;
  56563. (void)argp;
  56564. (void)argi;
  56565. (void)argl;
  56566. return ret;
  56567. }
  56568. #endif
  56569. static int test_wolfSSL_BIO(void)
  56570. {
  56571. EXPECT_DECLS;
  56572. #if defined(OPENSSL_EXTRA)
  56573. const unsigned char* p = NULL;
  56574. byte buff[20];
  56575. BIO* bio1 = NULL;
  56576. BIO* bio2 = NULL;
  56577. BIO* bio3 = NULL;
  56578. char* bufPt = NULL;
  56579. int i;
  56580. for (i = 0; i < 20; i++) {
  56581. buff[i] = i;
  56582. }
  56583. /* test BIO_free with NULL */
  56584. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56585. /* Creating and testing type BIO_s_bio */
  56586. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56587. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  56588. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  56589. /* read/write before set up */
  56590. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56591. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56592. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  56593. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  56594. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  56595. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  56596. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  56597. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  56598. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  56599. /* write buffer full */
  56600. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  56601. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  56602. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  56603. /* write the other direction with pair */
  56604. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  56605. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  56606. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  56607. /* try read */
  56608. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  56609. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  56610. /* try read using ctrl function */
  56611. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  56612. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  56613. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  56614. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  56615. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  56616. for (i = 0; i < 20; i++) {
  56617. ExpectIntEQ((int)bufPt[i], i);
  56618. }
  56619. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  56620. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  56621. for (i = 0; i < 8; i++) {
  56622. ExpectIntEQ((int)bufPt[i], i);
  56623. }
  56624. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  56625. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  56626. /* new pair */
  56627. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56628. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  56629. bio2 = NULL;
  56630. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  56631. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56632. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  56633. /* test wrap around... */
  56634. ExpectIntEQ(BIO_reset(bio1), 1);
  56635. ExpectIntEQ(BIO_reset(bio3), 1);
  56636. /* fill write buffer, read only small amount then write again */
  56637. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56638. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56639. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  56640. for (i = 0; i < 4; i++) {
  56641. ExpectIntEQ(bufPt[i], i);
  56642. }
  56643. /* try writing over read index */
  56644. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  56645. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  56646. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  56647. /* read and write 0 bytes */
  56648. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56649. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  56650. /* should read only to end of write buffer then need to read again */
  56651. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  56652. for (i = 0; i < 16; i++) {
  56653. ExpectIntEQ(bufPt[i], buff[4 + i]);
  56654. }
  56655. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56656. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  56657. for (i = 0; i < 4; i++) {
  56658. ExpectIntEQ(bufPt[i], 0);
  56659. }
  56660. /* read index should not have advanced with nread0 */
  56661. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  56662. for (i = 0; i < 4; i++) {
  56663. ExpectIntEQ(bufPt[i], 0);
  56664. }
  56665. /* write and fill up buffer checking reset of index state */
  56666. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56667. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56668. /* test reset on data in bio1 write buffer */
  56669. ExpectIntEQ(BIO_reset(bio1), 1);
  56670. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56671. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  56672. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56673. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  56674. ExpectNotNull(p);
  56675. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56676. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  56677. for (i = 0; i < 6; i++) {
  56678. ExpectIntEQ(bufPt[i], i);
  56679. }
  56680. /* test case of writing twice with offset read index */
  56681. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  56682. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  56683. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56684. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56685. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56686. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  56687. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  56688. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56689. BIO_free(bio1);
  56690. bio1 = NULL;
  56691. BIO_free(bio3);
  56692. bio3 = NULL;
  56693. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  56694. {
  56695. BIO* bioA = NULL;
  56696. BIO* bioB = NULL;
  56697. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  56698. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  56699. BIO_free(bioA);
  56700. bioA = NULL;
  56701. BIO_free(bioB);
  56702. bioB = NULL;
  56703. }
  56704. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  56705. /* BIOs with file pointers */
  56706. #if !defined(NO_FILESYSTEM)
  56707. {
  56708. XFILE f1 = XBADFILE;
  56709. XFILE f2 = XBADFILE;
  56710. BIO* f_bio1 = NULL;
  56711. BIO* f_bio2 = NULL;
  56712. unsigned char cert[300];
  56713. char testFile[] = "tests/bio_write_test.txt";
  56714. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  56715. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  56716. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  56717. /* Failure due to wrong BIO type */
  56718. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56719. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  56720. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  56721. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  56722. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  56723. WOLFSSL_SUCCESS);
  56724. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56725. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  56726. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  56727. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  56728. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  56729. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  56730. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  56731. ExpectIntEQ(BIO_reset(f_bio2), 1);
  56732. ExpectIntEQ(BIO_tell(NULL),-1);
  56733. ExpectIntEQ(BIO_tell(f_bio2),0);
  56734. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  56735. ExpectIntEQ(BIO_tell(f_bio2),4);
  56736. BIO_free(f_bio1);
  56737. f_bio1 = NULL;
  56738. BIO_free(f_bio2);
  56739. f_bio2 = NULL;
  56740. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  56741. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56742. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56743. BIO_free(f_bio1);
  56744. f_bio1 = NULL;
  56745. }
  56746. #endif /* !defined(NO_FILESYSTEM) */
  56747. /* BIO info callback */
  56748. {
  56749. const char* testArg = "test";
  56750. BIO* cb_bio = NULL;
  56751. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  56752. BIO_set_callback(cb_bio, bioCallback);
  56753. ExpectNotNull(BIO_get_callback(cb_bio));
  56754. BIO_set_callback(cb_bio, NULL);
  56755. ExpectNull(BIO_get_callback(cb_bio));
  56756. BIO_set_callback_arg(cb_bio, (char*)testArg);
  56757. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  56758. ExpectNull(BIO_get_callback_arg(NULL));
  56759. BIO_free(cb_bio);
  56760. cb_bio = NULL;
  56761. }
  56762. /* BIO_vfree */
  56763. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56764. BIO_vfree(NULL);
  56765. BIO_vfree(bio1);
  56766. #endif
  56767. return EXPECT_RESULT();
  56768. }
  56769. static int test_wolfSSL_BIO_BIO_ring_read(void)
  56770. {
  56771. EXPECT_DECLS;
  56772. #if defined(OPENSSL_ALL)
  56773. BIO* bio1 = NULL;
  56774. BIO* bio2 = NULL;
  56775. byte data[50];
  56776. byte tmp[50];
  56777. XMEMSET(data, 42, sizeof(data));
  56778. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  56779. SSL_SUCCESS);
  56780. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  56781. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  56782. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  56783. ExpectBufEQ(tmp, data, 20);
  56784. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  56785. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  56786. ExpectBufEQ(tmp, data, 40);
  56787. BIO_free(bio1);
  56788. BIO_free(bio2);
  56789. #endif
  56790. return EXPECT_RESULT();
  56791. }
  56792. #endif /* !NO_BIO */
  56793. static int test_wolfSSL_a2i_IPADDRESS(void)
  56794. {
  56795. EXPECT_DECLS;
  56796. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  56797. const unsigned char* data = NULL;
  56798. int dataSz = 0;
  56799. ASN1_OCTET_STRING *st = NULL;
  56800. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  56801. const unsigned char ipv6_exp[] = {
  56802. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  56803. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  56804. };
  56805. const unsigned char ipv6_home[] = {
  56806. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56807. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  56808. };
  56809. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  56810. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  56811. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56812. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  56813. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  56814. ASN1_STRING_free(st);
  56815. st = NULL;
  56816. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  56817. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56818. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  56819. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  56820. ASN1_STRING_free(st);
  56821. st = NULL;
  56822. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  56823. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  56824. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  56825. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  56826. ASN1_STRING_free(st);
  56827. #endif
  56828. return EXPECT_RESULT();
  56829. }
  56830. static int test_wolfSSL_X509_cmp_time(void)
  56831. {
  56832. EXPECT_DECLS;
  56833. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  56834. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  56835. WOLFSSL_ASN1_TIME asn_time;
  56836. time_t t;
  56837. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  56838. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  56839. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  56840. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  56841. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  56842. #endif
  56843. return EXPECT_RESULT();
  56844. }
  56845. static int test_wolfSSL_X509_time_adj(void)
  56846. {
  56847. EXPECT_DECLS;
  56848. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  56849. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  56850. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  56851. !defined(NO_ASN_TIME)
  56852. X509* x509 = NULL;
  56853. time_t t;
  56854. time_t not_before;
  56855. time_t not_after;
  56856. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56857. client_cert_der_2048, sizeof_client_cert_der_2048,
  56858. WOLFSSL_FILETYPE_ASN1));
  56859. t = 0;
  56860. not_before = wc_Time(0);
  56861. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  56862. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  56863. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  56864. /* Check X509_gmtime_adj, too. */
  56865. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  56866. X509_free(x509);
  56867. #endif
  56868. return EXPECT_RESULT();
  56869. }
  56870. static int test_wolfSSL_X509_bad_altname(void)
  56871. {
  56872. EXPECT_DECLS;
  56873. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56874. const unsigned char malformed_alt_name_cert[] = {
  56875. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  56876. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  56877. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  56878. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  56879. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  56880. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  56881. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  56882. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  56883. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  56884. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  56885. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  56886. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  56887. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  56888. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  56889. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  56890. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  56891. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  56892. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  56893. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  56894. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  56895. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  56896. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  56897. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  56898. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  56899. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  56900. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  56901. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  56902. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  56903. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  56904. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  56905. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  56906. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  56907. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  56908. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  56909. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  56910. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  56911. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  56912. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  56913. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  56914. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  56915. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  56916. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  56917. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  56918. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  56919. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  56920. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  56921. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  56922. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  56923. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  56924. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  56925. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  56926. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  56927. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  56928. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  56929. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  56930. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  56931. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  56932. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  56933. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  56934. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  56935. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  56936. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  56937. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  56938. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  56939. };
  56940. X509* x509 = NULL;
  56941. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  56942. const char *name = "aaaaa";
  56943. int nameLen = (int)XSTRLEN(name);
  56944. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  56945. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  56946. /* malformed_alt_name_cert has a malformed alternative
  56947. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  56948. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  56949. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  56950. X509_free(x509);
  56951. #endif
  56952. return EXPECT_RESULT();
  56953. }
  56954. static int test_wolfSSL_X509_name_match(void)
  56955. {
  56956. EXPECT_DECLS;
  56957. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56958. /* A certificate with the subject alternative name a* */
  56959. const unsigned char cert_der[] = {
  56960. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  56961. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  56962. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  56963. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  56964. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  56965. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  56966. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  56967. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  56968. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  56969. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  56970. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  56971. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  56972. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  56973. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  56974. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  56975. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  56976. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  56977. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  56978. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  56979. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  56980. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  56981. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  56982. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  56983. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  56984. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  56985. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  56986. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  56987. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  56988. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  56989. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  56990. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  56991. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  56992. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  56993. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  56994. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  56995. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  56996. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  56997. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  56998. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  56999. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  57000. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  57001. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  57002. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  57003. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  57004. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  57005. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  57006. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  57007. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  57008. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  57009. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  57010. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  57011. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  57012. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  57013. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  57014. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  57015. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  57016. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  57017. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  57018. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  57019. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  57020. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  57021. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  57022. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  57023. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  57024. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  57025. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  57026. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  57027. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  57028. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  57029. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  57030. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  57031. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  57032. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  57033. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  57034. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  57035. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  57036. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  57037. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  57038. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  57039. };
  57040. WOLFSSL_X509* x509 = NULL;
  57041. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57042. const char *name1 = "aaaaa";
  57043. int nameLen1 = (int)(XSTRLEN(name1));
  57044. const char *name2 = "a";
  57045. int nameLen2 = (int)(XSTRLEN(name2));
  57046. const char *name3 = "abbbb";
  57047. int nameLen3 = (int)(XSTRLEN(name3));
  57048. const char *name4 = "bbb";
  57049. int nameLen4 = (int)(XSTRLEN(name4));
  57050. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57051. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57052. /* Ensure that "a*" matches "aaaaa" */
  57053. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57054. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57055. /* Ensure that "a*" matches "a" */
  57056. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57057. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57058. /* Ensure that "a*" matches "abbbb" */
  57059. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57060. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57061. /* Ensure that "a*" does not match "bbb" */
  57062. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57063. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  57064. wolfSSL_X509_free(x509);
  57065. #endif
  57066. return EXPECT_RESULT();
  57067. }
  57068. static int test_wolfSSL_X509_name_match2(void)
  57069. {
  57070. EXPECT_DECLS;
  57071. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57072. /* A certificate with the subject alternative name a*b* */
  57073. const unsigned char cert_der[] = {
  57074. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  57075. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  57076. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  57077. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57078. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57079. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57080. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57081. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57082. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57083. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57084. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57085. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57086. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57087. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57088. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57089. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57090. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  57091. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57092. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57093. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57094. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57095. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57096. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57097. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57098. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57099. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57100. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57101. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57102. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57103. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  57104. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  57105. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  57106. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  57107. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  57108. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  57109. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  57110. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  57111. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  57112. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  57113. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  57114. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  57115. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  57116. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  57117. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  57118. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  57119. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  57120. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  57121. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  57122. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  57123. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  57124. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  57125. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  57126. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  57127. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  57128. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  57129. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  57130. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  57131. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  57132. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  57133. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  57134. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  57135. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  57136. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  57137. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  57138. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  57139. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  57140. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  57141. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  57142. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  57143. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  57144. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  57145. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  57146. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  57147. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  57148. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  57149. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  57150. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  57151. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  57152. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  57153. };
  57154. WOLFSSL_X509* x509 = NULL;
  57155. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57156. const char *name1 = "ab";
  57157. int nameLen1 = (int)(XSTRLEN(name1));
  57158. const char *name2 = "acccbccc";
  57159. int nameLen2 = (int)(XSTRLEN(name2));
  57160. const char *name3 = "accb";
  57161. int nameLen3 = (int)(XSTRLEN(name3));
  57162. const char *name4 = "accda";
  57163. int nameLen4 = (int)(XSTRLEN(name4));
  57164. const char *name5 = "acc\0bcc";
  57165. int nameLen5 = 7;
  57166. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57167. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57168. /* Ensure that "a*b*" matches "ab" */
  57169. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57170. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57171. /* Ensure that "a*b*" matches "acccbccc" */
  57172. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57173. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57174. /* Ensure that "a*b*" matches "accb" */
  57175. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57176. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57177. /* Ensure that "a*b*" does not match "accda" */
  57178. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57179. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57180. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  57181. * on check len input handling, 0 for len is OK as it should then use
  57182. * strlen(name1) */
  57183. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  57184. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57185. /* Openssl also allows for len to include NULL terminator */
  57186. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  57187. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57188. /* Ensure that check string with NULL terminator in middle is
  57189. * rejected */
  57190. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  57191. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57192. wolfSSL_X509_free(x509);
  57193. #endif
  57194. return EXPECT_RESULT();
  57195. }
  57196. static int test_wolfSSL_X509_name_match3(void)
  57197. {
  57198. EXPECT_DECLS;
  57199. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57200. /* A certificate with the subject alternative name *.example.com */
  57201. const unsigned char cert_der[] = {
  57202. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  57203. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  57204. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  57205. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57206. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57207. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57208. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57209. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57210. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57211. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57212. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57213. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57214. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57215. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57216. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57217. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57218. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  57219. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57220. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57221. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57222. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57223. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57224. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57225. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57226. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57227. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57228. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57229. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57230. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57231. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  57232. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  57233. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  57234. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  57235. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  57236. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  57237. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  57238. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  57239. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  57240. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  57241. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  57242. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  57243. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  57244. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  57245. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  57246. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  57247. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  57248. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  57249. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  57250. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  57251. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  57252. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  57253. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  57254. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  57255. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  57256. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  57257. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  57258. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  57259. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  57260. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  57261. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  57262. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  57263. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  57264. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  57265. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  57266. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  57267. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  57268. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  57269. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  57270. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  57271. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  57272. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  57273. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  57274. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  57275. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  57276. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  57277. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  57278. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  57279. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  57280. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  57281. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  57282. };
  57283. WOLFSSL_X509* x509 = NULL;
  57284. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57285. const char *name1 = "foo.example.com";
  57286. int nameLen1 = (int)(XSTRLEN(name1));
  57287. const char *name2 = "x.y.example.com";
  57288. int nameLen2 = (int)(XSTRLEN(name2));
  57289. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57290. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57291. /* Ensure that "*.example.com" matches "foo.example.com" */
  57292. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57293. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57294. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  57295. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57296. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57297. wolfSSL_X509_free(x509);
  57298. #endif
  57299. return EXPECT_RESULT();
  57300. }
  57301. static int test_wolfSSL_X509_max_altnames(void)
  57302. {
  57303. EXPECT_DECLS;
  57304. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  57305. /* Only test if max alt names has not been modified */
  57306. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  57307. WOLFSSL_CTX* ctx = NULL;
  57308. /* File contains a certificate encoded with 130 subject alternative names */
  57309. const char* over_max_altnames_cert = \
  57310. "./certs/test/cert-over-max-altnames.pem";
  57311. #ifndef NO_WOLFSSL_SERVER
  57312. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57313. #else
  57314. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57315. #endif
  57316. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  57317. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  57318. WOLFSSL_SUCCESS);
  57319. wolfSSL_CTX_free(ctx);
  57320. #endif
  57321. #endif
  57322. return EXPECT_RESULT();
  57323. }
  57324. static int test_wolfSSL_X509_max_name_constraints(void)
  57325. {
  57326. EXPECT_DECLS;
  57327. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  57328. !defined(IGNORE_NAME_CONSTRAINTS)
  57329. /* Only test if max name constraints has not been modified */
  57330. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  57331. WOLFSSL_CTX* ctx = NULL;
  57332. /* File contains a certificate with 130 name constraints */
  57333. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  57334. #ifndef NO_WOLFSSL_SERVER
  57335. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57336. #else
  57337. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57338. #endif
  57339. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  57340. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  57341. wolfSSL_CTX_free(ctx);
  57342. #endif
  57343. #endif
  57344. return EXPECT_RESULT();
  57345. }
  57346. static int test_wolfSSL_X509(void)
  57347. {
  57348. EXPECT_DECLS;
  57349. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57350. !defined(NO_RSA)
  57351. X509* x509 = NULL;
  57352. #ifndef NO_BIO
  57353. BIO* bio = NULL;
  57354. X509_STORE_CTX* ctx = NULL;
  57355. X509_STORE* store = NULL;
  57356. #endif
  57357. char der[] = "certs/ca-cert.der";
  57358. XFILE fp = XBADFILE;
  57359. ExpectNotNull(x509 = X509_new());
  57360. X509_free(x509);
  57361. x509 = NULL;
  57362. #ifndef NO_BIO
  57363. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57364. SSL_FILETYPE_PEM));
  57365. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  57366. #ifdef WOLFSSL_CERT_GEN
  57367. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  57368. #endif
  57369. ExpectNotNull(ctx = X509_STORE_CTX_new());
  57370. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  57371. ExpectNotNull(store = X509_STORE_new());
  57372. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  57373. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  57374. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  57375. X509_STORE_CTX_free(ctx);
  57376. X509_STORE_free(store);
  57377. X509_free(x509);
  57378. x509 = NULL;
  57379. BIO_free(bio);
  57380. #endif
  57381. /** d2i_X509_fp test **/
  57382. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57383. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  57384. ExpectNotNull(x509);
  57385. X509_free(x509);
  57386. x509 = NULL;
  57387. if (fp != XBADFILE) {
  57388. XFCLOSE(fp);
  57389. fp = XBADFILE;
  57390. }
  57391. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57392. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  57393. ExpectNotNull(x509);
  57394. X509_free(x509);
  57395. if (fp != XBADFILE)
  57396. XFCLOSE(fp);
  57397. /* X509_up_ref test */
  57398. ExpectIntEQ(X509_up_ref(NULL), 0);
  57399. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  57400. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  57401. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  57402. X509_free(x509); /* refCount = 2 */
  57403. X509_free(x509); /* refCount = 1 */
  57404. X509_free(x509); /* refCount = 0, free */
  57405. #endif
  57406. return EXPECT_RESULT();
  57407. }
  57408. static int test_wolfSSL_X509_get_ext_count(void)
  57409. {
  57410. EXPECT_DECLS;
  57411. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57412. !defined(NO_RSA)
  57413. int ret = 0;
  57414. WOLFSSL_X509* x509 = NULL;
  57415. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  57416. XFILE f = XBADFILE;
  57417. /* NULL parameter check */
  57418. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57419. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  57420. SSL_FILETYPE_PEM));
  57421. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57422. wolfSSL_X509_free(x509);
  57423. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  57424. SSL_FILETYPE_PEM));
  57425. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57426. wolfSSL_X509_free(x509);
  57427. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  57428. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  57429. if (f != XBADFILE)
  57430. XFCLOSE(f);
  57431. /* wolfSSL_X509_get_ext_count() valid input */
  57432. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  57433. /* wolfSSL_X509_get_ext_count() NULL argument */
  57434. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57435. wolfSSL_X509_free(x509);
  57436. #endif
  57437. return EXPECT_RESULT();
  57438. }
  57439. static int test_wolfSSL_X509_sign2(void)
  57440. {
  57441. EXPECT_DECLS;
  57442. /* test requires WOLFSSL_AKID_NAME to match expected output */
  57443. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  57444. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  57445. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  57446. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  57447. defined(WOLFSSL_IP_ALT_NAME))
  57448. WOLFSSL_X509 *x509 = NULL;
  57449. WOLFSSL_X509 *ca = NULL;
  57450. const unsigned char *der = NULL;
  57451. const unsigned char *pt = NULL;
  57452. WOLFSSL_EVP_PKEY *priv = NULL;
  57453. WOLFSSL_X509_NAME *name = NULL;
  57454. int derSz;
  57455. #ifndef NO_ASN_TIME
  57456. WOLFSSL_ASN1_TIME *notBefore = NULL;
  57457. WOLFSSL_ASN1_TIME *notAfter = NULL;
  57458. const int year = 365*24*60*60;
  57459. const int day = 24*60*60;
  57460. const int hour = 60*60;
  57461. const int mini = 60;
  57462. time_t t;
  57463. #endif
  57464. const unsigned char expected[] = {
  57465. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  57466. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  57467. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  57468. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  57469. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  57470. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  57471. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  57472. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  57473. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  57474. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  57475. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  57476. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  57477. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  57478. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  57479. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57480. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  57481. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  57482. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  57483. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  57484. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  57485. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  57486. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  57487. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  57488. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  57489. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  57490. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  57491. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  57492. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  57493. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  57494. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  57495. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  57496. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  57497. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  57498. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57499. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  57500. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  57501. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  57502. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  57503. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  57504. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  57505. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  57506. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  57507. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  57508. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  57509. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  57510. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  57511. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  57512. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  57513. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  57514. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  57515. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  57516. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  57517. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  57518. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  57519. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  57520. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  57521. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  57522. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  57523. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  57524. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  57525. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  57526. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  57527. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57528. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57529. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  57530. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57531. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57532. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  57533. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  57534. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  57535. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  57536. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  57537. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  57538. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  57539. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  57540. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  57541. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  57542. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  57543. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  57544. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  57545. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  57546. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  57547. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  57548. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  57549. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  57550. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  57551. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  57552. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  57553. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  57554. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  57555. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  57556. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  57557. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  57558. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  57559. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  57560. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  57561. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  57562. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  57563. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  57564. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  57565. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  57566. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  57567. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  57568. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  57569. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  57570. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  57571. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  57572. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  57573. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  57574. };
  57575. pt = ca_key_der_2048;
  57576. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  57577. sizeof_ca_key_der_2048));
  57578. pt = client_cert_der_2048;
  57579. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  57580. sizeof_client_cert_der_2048));
  57581. pt = ca_cert_der_2048;
  57582. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  57583. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  57584. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  57585. #ifndef NO_ASN_TIME
  57586. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  57587. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  57588. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  57589. ExpectIntEQ(notAfter->length, 13);
  57590. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  57591. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  57592. #endif
  57593. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  57594. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  57595. ExpectIntEQ(derSz, sizeof(expected));
  57596. #ifndef NO_ASN_TIME
  57597. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  57598. #endif
  57599. wolfSSL_X509_free(ca);
  57600. wolfSSL_X509_free(x509);
  57601. wolfSSL_EVP_PKEY_free(priv);
  57602. #ifndef NO_ASN_TIME
  57603. wolfSSL_ASN1_TIME_free(notBefore);
  57604. wolfSSL_ASN1_TIME_free(notAfter);
  57605. #endif
  57606. #endif
  57607. return EXPECT_RESULT();
  57608. }
  57609. static int test_wolfSSL_X509_sign(void)
  57610. {
  57611. EXPECT_DECLS;
  57612. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  57613. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  57614. int ret = 0;
  57615. char *cn = NULL;
  57616. word32 cnSz = 0;
  57617. X509_NAME *name = NULL;
  57618. X509 *x509 = NULL;
  57619. X509 *ca = NULL;
  57620. DecodedCert dCert;
  57621. EVP_PKEY *pub = NULL;
  57622. EVP_PKEY *priv = NULL;
  57623. EVP_MD_CTX *mctx = NULL;
  57624. #if defined(USE_CERT_BUFFERS_1024)
  57625. const unsigned char* rsaPriv = client_key_der_1024;
  57626. const unsigned char* rsaPub = client_keypub_der_1024;
  57627. const unsigned char* certIssuer = client_cert_der_1024;
  57628. long clientKeySz = (long)sizeof_client_key_der_1024;
  57629. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  57630. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  57631. #elif defined(USE_CERT_BUFFERS_2048)
  57632. const unsigned char* rsaPriv = client_key_der_2048;
  57633. const unsigned char* rsaPub = client_keypub_der_2048;
  57634. const unsigned char* certIssuer = client_cert_der_2048;
  57635. long clientKeySz = (long)sizeof_client_key_der_2048;
  57636. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  57637. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  57638. #endif
  57639. byte sn[16];
  57640. int snSz = sizeof(sn);
  57641. /* Set X509_NAME fields */
  57642. ExpectNotNull(name = X509_NAME_new());
  57643. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  57644. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  57645. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  57646. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  57647. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  57648. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  57649. /* Get private and public keys */
  57650. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  57651. clientKeySz));
  57652. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  57653. ExpectNotNull(x509 = X509_new());
  57654. /* Set version 3 */
  57655. ExpectIntNE(X509_set_version(x509, 2L), 0);
  57656. /* Set subject name, add pubkey, and sign certificate */
  57657. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  57658. X509_NAME_free(name);
  57659. name = NULL;
  57660. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  57661. #ifdef WOLFSSL_ALT_NAMES
  57662. /* Add some subject alt names */
  57663. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  57664. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  57665. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57666. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  57667. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57668. "sphygmomanometer",
  57669. ASN_DNS_TYPE), SSL_SUCCESS);
  57670. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57671. "supercalifragilisticexpialidocious",
  57672. ASN_DNS_TYPE), SSL_SUCCESS);
  57673. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57674. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  57675. ASN_DNS_TYPE), SSL_SUCCESS);
  57676. #ifdef WOLFSSL_IP_ALT_NAME
  57677. {
  57678. unsigned char ip4_type[] = {127,128,0,255};
  57679. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  57680. 0xff, 0xee, 0x99, 0x88,
  57681. 0x77, 0x66, 0x55, 0x44,
  57682. 0x00, 0x33, 0x22, 0x11};
  57683. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  57684. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  57685. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  57686. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  57687. }
  57688. #endif
  57689. #endif /* WOLFSSL_ALT_NAMES */
  57690. {
  57691. ASN1_UTCTIME* infinite_past = NULL;
  57692. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  57693. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  57694. ASN1_UTCTIME_free(infinite_past);
  57695. }
  57696. /* test valid sign case */
  57697. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  57698. /* test valid X509_sign_ctx case */
  57699. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57700. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  57701. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  57702. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  57703. ExpectIntEQ(X509_get_ext_count(x509), 1);
  57704. #endif
  57705. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  57706. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  57707. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  57708. #endif
  57709. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  57710. WOLFSSL_SUCCESS);
  57711. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  57712. /* Variation in size depends on ASN.1 encoding when MSB is set.
  57713. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  57714. * with the MSB set. See GenerateInteger in asn.c */
  57715. #ifndef USE_CERT_BUFFERS_1024
  57716. #ifndef WOLFSSL_ALT_NAMES
  57717. /* Valid case - size should be 781-786 with 16 byte serial number */
  57718. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  57719. #elif defined(WOLFSSL_IP_ALT_NAME)
  57720. /* Valid case - size should be 955-960 with 16 byte serial number */
  57721. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  57722. #else
  57723. /* Valid case - size should be 926-931 with 16 byte serial number */
  57724. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  57725. #endif
  57726. #else
  57727. #ifndef WOLFSSL_ALT_NAMES
  57728. /* Valid case - size should be 537-542 with 16 byte serial number */
  57729. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  57730. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  57731. /* Valid case - size should be 695-670 with 16 byte serial number */
  57732. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  57733. #else
  57734. /* Valid case - size should be 666-671 with 16 byte serial number */
  57735. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  57736. #endif
  57737. #endif
  57738. /* check that issuer name is as expected after signature */
  57739. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  57740. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  57741. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  57742. ExpectNotNull(name = X509_get_subject_name(ca));
  57743. cnSz = X509_NAME_get_sz(name);
  57744. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  57745. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  57746. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  57747. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  57748. cn = NULL;
  57749. #ifdef WOLFSSL_MULTI_ATTRIB
  57750. /* test adding multiple OU's to the signer */
  57751. ExpectNotNull(name = X509_get_subject_name(ca));
  57752. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  57753. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  57754. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  57755. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  57756. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  57757. #endif
  57758. ExpectNotNull(name = X509_get_subject_name(ca));
  57759. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  57760. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  57761. ExpectNotNull(name = X509_get_issuer_name(x509));
  57762. cnSz = X509_NAME_get_sz(name);
  57763. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  57764. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  57765. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  57766. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  57767. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  57768. cn = NULL;
  57769. FreeDecodedCert(&dCert);
  57770. /* Test invalid parameters */
  57771. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  57772. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  57773. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  57774. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  57775. EVP_MD_CTX_free(mctx);
  57776. mctx = NULL;
  57777. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57778. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  57779. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  57780. /* test invalid version number */
  57781. #if defined(OPENSSL_ALL)
  57782. ExpectIntNE(X509_set_version(x509, 6L), 0);
  57783. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  57784. /* uses ParseCert which fails on bad version number */
  57785. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57786. #endif
  57787. EVP_MD_CTX_free(mctx);
  57788. EVP_PKEY_free(priv);
  57789. EVP_PKEY_free(pub);
  57790. X509_free(x509);
  57791. X509_free(ca);
  57792. #endif
  57793. return EXPECT_RESULT();
  57794. }
  57795. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  57796. {
  57797. EXPECT_DECLS;
  57798. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  57799. X509* x509 = NULL;
  57800. const X509_ALGOR* alg;
  57801. ExpectNotNull(x509 = X509_new());
  57802. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  57803. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  57804. X509_free(x509);
  57805. #endif
  57806. return EXPECT_RESULT();
  57807. }
  57808. static int test_wolfSSL_X509_ALGOR_get0(void)
  57809. {
  57810. EXPECT_DECLS;
  57811. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  57812. !defined(NO_SHA256) && !defined(NO_RSA)
  57813. X509* x509 = NULL;
  57814. const ASN1_OBJECT* obj = NULL;
  57815. const X509_ALGOR* alg = NULL;
  57816. X509_ALGOR* alg2 = NULL;
  57817. int pptype = 0;
  57818. const void *ppval = NULL;
  57819. byte* der = NULL;
  57820. const byte* tmp = NULL;
  57821. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57822. SSL_FILETYPE_PEM));
  57823. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  57824. /* Invalid case */
  57825. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  57826. ExpectNull(obj);
  57827. /* Valid case */
  57828. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  57829. ExpectNotNull(obj);
  57830. ExpectNull(ppval);
  57831. ExpectIntNE(pptype, 0);
  57832. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  57833. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  57834. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  57835. tmp = der;
  57836. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  57837. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  57838. X509_free(x509);
  57839. X509_ALGOR_free(alg2);
  57840. #endif
  57841. return EXPECT_RESULT();
  57842. }
  57843. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  57844. {
  57845. EXPECT_DECLS;
  57846. #if defined(OPENSSL_EXTRA)
  57847. X509_VERIFY_PARAM *paramTo = NULL;
  57848. X509_VERIFY_PARAM *paramFrom = NULL;
  57849. char testIPv4[] = "127.0.0.1";
  57850. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  57851. char testhostName1[] = "foo.hoge.com";
  57852. char testhostName2[] = "foobar.hoge.com";
  57853. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  57854. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  57855. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  57856. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  57857. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  57858. (int)XSTRLEN(testhostName1)), 1);
  57859. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  57860. (int)XSTRLEN(testhostName1)));
  57861. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  57862. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  57863. ExpectIntEQ(0x01, paramFrom->hostFlags);
  57864. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  57865. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  57866. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  57867. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  57868. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  57869. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57870. /* null pointer */
  57871. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  57872. /* in the case of "from" null, returns success */
  57873. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  57874. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  57875. /* inherit flags test : VPARAM_DEFAULT */
  57876. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57877. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57878. (int)XSTRLEN(testhostName1)));
  57879. ExpectIntEQ(0x01, paramTo->hostFlags);
  57880. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57881. /* inherit flags test : VPARAM OVERWRITE */
  57882. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57883. (int)XSTRLEN(testhostName2)), 1);
  57884. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57885. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  57886. if (paramTo != NULL) {
  57887. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  57888. }
  57889. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57890. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57891. (int)XSTRLEN(testhostName1)));
  57892. ExpectIntEQ(0x01, paramTo->hostFlags);
  57893. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57894. /* inherit flags test : VPARAM_RESET_FLAGS */
  57895. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57896. (int)XSTRLEN(testhostName2)), 1);
  57897. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57898. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  57899. if (paramTo != NULL) {
  57900. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  57901. }
  57902. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57903. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  57904. (int)XSTRLEN(testhostName1)));
  57905. ExpectIntEQ(0x01, paramTo->hostFlags);
  57906. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  57907. /* inherit flags test : VPARAM_LOCKED */
  57908. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  57909. (int)XSTRLEN(testhostName2)), 1);
  57910. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  57911. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  57912. if (paramTo != NULL) {
  57913. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  57914. }
  57915. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  57916. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  57917. (int)XSTRLEN(testhostName2)));
  57918. ExpectIntEQ(0x00, paramTo->hostFlags);
  57919. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  57920. /* test for incorrect parameters */
  57921. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  57922. 0);
  57923. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  57924. /* inherit flags test : VPARAM_ONCE, not testable yet */
  57925. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  57926. 1);
  57927. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  57928. X509_V_FLAG_CRL_CHECK_ALL);
  57929. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  57930. X509_V_FLAG_CRL_CHECK_ALL), 1);
  57931. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  57932. X509_VERIFY_PARAM_free(paramTo);
  57933. X509_VERIFY_PARAM_free(paramFrom);
  57934. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  57935. #endif
  57936. return EXPECT_RESULT();
  57937. }
  57938. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57939. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  57940. static int test_wolfSSL_check_domain_verify_count = 0;
  57941. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  57942. WOLFSSL_X509_STORE_CTX* store)
  57943. {
  57944. EXPECT_DECLS;
  57945. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  57946. ExpectIntEQ(preverify, 1);
  57947. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  57948. return EXPECT_SUCCESS();
  57949. }
  57950. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  57951. {
  57952. EXPECT_DECLS;
  57953. X509_VERIFY_PARAM *param = NULL;
  57954. ExpectNotNull(param = SSL_get0_param(ssl));
  57955. /* Domain check should only be done on the leaf cert */
  57956. X509_VERIFY_PARAM_set_hostflags(param,
  57957. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  57958. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  57959. "wolfSSL Server Chain", 0), 1);
  57960. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  57961. test_wolfSSL_check_domain_verify_cb);
  57962. return EXPECT_RESULT();
  57963. }
  57964. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  57965. {
  57966. EXPECT_DECLS;
  57967. /* Use a cert with different domains in chain */
  57968. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  57969. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  57970. return EXPECT_RESULT();
  57971. }
  57972. static int test_wolfSSL_check_domain(void)
  57973. {
  57974. EXPECT_DECLS;
  57975. test_ssl_cbf func_cb_client;
  57976. test_ssl_cbf func_cb_server;
  57977. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  57978. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  57979. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  57980. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  57981. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  57982. &func_cb_server, NULL), TEST_SUCCESS);
  57983. /* Should have been called once for each cert in sent chain */
  57984. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  57985. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  57986. #else
  57987. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  57988. #endif
  57989. return EXPECT_RESULT();
  57990. }
  57991. #else
  57992. static int test_wolfSSL_check_domain(void)
  57993. {
  57994. EXPECT_DECLS;
  57995. return EXPECT_RESULT();
  57996. }
  57997. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  57998. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  57999. {
  58000. EXPECT_DECLS;
  58001. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58002. X509* x509 = NULL;
  58003. X509_PUBKEY* pubKey;
  58004. ExpectNotNull(x509 = X509_new());
  58005. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  58006. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  58007. X509_free(x509);
  58008. #endif
  58009. return EXPECT_RESULT();
  58010. }
  58011. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  58012. {
  58013. EXPECT_DECLS;
  58014. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58015. !defined(NO_SHA256) && !defined(NO_RSA)
  58016. X509* x509 = NULL;
  58017. ASN1_OBJECT* obj = NULL;
  58018. const ASN1_OBJECT* pa_oid = NULL;
  58019. X509_PUBKEY* pubKey = NULL;
  58020. X509_PUBKEY* pubKey2 = NULL;
  58021. EVP_PKEY* evpKey = NULL;
  58022. const unsigned char *pk = NULL;
  58023. int ppklen;
  58024. int pptype;
  58025. X509_ALGOR *pa = NULL;
  58026. const void *pval;
  58027. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  58028. SSL_FILETYPE_PEM));
  58029. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58030. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58031. ExpectNotNull(pk);
  58032. ExpectNotNull(pa);
  58033. ExpectNotNull(pubKey);
  58034. ExpectIntGT(ppklen, 0);
  58035. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  58036. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58037. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58038. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58039. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58040. ExpectNotNull(pk);
  58041. ExpectNotNull(pa);
  58042. ExpectIntGT(ppklen, 0);
  58043. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58044. ExpectNotNull(pa_oid);
  58045. ExpectNull(pval);
  58046. ExpectIntEQ(pptype, V_ASN1_NULL);
  58047. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  58048. X509_PUBKEY_free(pubKey2);
  58049. X509_free(x509);
  58050. EVP_PKEY_free(evpKey);
  58051. #endif
  58052. return EXPECT_RESULT();
  58053. }
  58054. static int test_wolfSSL_X509_PUBKEY_EC(void)
  58055. {
  58056. EXPECT_DECLS;
  58057. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  58058. X509* x509 = NULL;
  58059. ASN1_OBJECT* obj = NULL;
  58060. ASN1_OBJECT* poid = NULL;
  58061. const ASN1_OBJECT* pa_oid = NULL;
  58062. X509_PUBKEY* pubKey = NULL;
  58063. X509_PUBKEY* pubKey2 = NULL;
  58064. EVP_PKEY* evpKey = NULL;
  58065. const unsigned char *pk = NULL;
  58066. int ppklen;
  58067. int pptype;
  58068. X509_ALGOR *pa = NULL;
  58069. const void *pval;
  58070. char buf[50];
  58071. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  58072. SSL_FILETYPE_PEM));
  58073. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58074. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58075. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58076. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58077. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58078. ExpectNotNull(pk);
  58079. ExpectNotNull(pa);
  58080. ExpectIntGT(ppklen, 0);
  58081. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58082. ExpectNotNull(pa_oid);
  58083. ExpectNotNull(pval);
  58084. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  58085. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  58086. poid = (ASN1_OBJECT *)pval;
  58087. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  58088. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  58089. X509_PUBKEY_free(pubKey2);
  58090. X509_free(x509);
  58091. EVP_PKEY_free(evpKey);
  58092. #endif
  58093. return EXPECT_RESULT();
  58094. }
  58095. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  58096. {
  58097. EXPECT_DECLS;
  58098. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  58099. word32 bytes;
  58100. #ifdef USE_CERT_BUFFERS_1024
  58101. byte tmp[ONEK_BUF];
  58102. #elif defined(USE_CERT_BUFFERS_2048)
  58103. byte tmp[TWOK_BUF];
  58104. #else
  58105. byte tmp[TWOK_BUF];
  58106. #endif /* END USE_CERT_BUFFERS_1024 */
  58107. const unsigned char* dsaKeyDer = tmp;
  58108. ASN1_OBJECT* obj = NULL;
  58109. ASN1_STRING* str;
  58110. const ASN1_OBJECT* pa_oid = NULL;
  58111. X509_PUBKEY* pubKey = NULL;
  58112. EVP_PKEY* evpKey = NULL;
  58113. const unsigned char *pk = NULL;
  58114. int ppklen, pptype;
  58115. X509_ALGOR *pa = NULL;
  58116. const void *pval;
  58117. #ifdef USE_CERT_BUFFERS_1024
  58118. XMEMSET(tmp, 0, sizeof(tmp));
  58119. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  58120. bytes = sizeof_dsa_key_der_1024;
  58121. #elif defined(USE_CERT_BUFFERS_2048)
  58122. XMEMSET(tmp, 0, sizeof(tmp));
  58123. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  58124. bytes = sizeof_dsa_key_der_2048;
  58125. #else
  58126. {
  58127. XFILE fp = XBADFILE;
  58128. XMEMSET(tmp, 0, sizeof(tmp));
  58129. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  58130. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  58131. if (fp != XBADFILE)
  58132. XFCLOSE(fp);
  58133. }
  58134. #endif
  58135. /* Initialize pkey with der format dsa key */
  58136. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  58137. ExpectNotNull(pubKey = X509_PUBKEY_new());
  58138. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  58139. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58140. ExpectNotNull(pk);
  58141. ExpectNotNull(pa);
  58142. ExpectIntGT(ppklen, 0);
  58143. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58144. ExpectNotNull(pa_oid);
  58145. ExpectNotNull(pval);
  58146. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  58147. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  58148. str = (ASN1_STRING *)pval;
  58149. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  58150. #ifdef USE_CERT_BUFFERS_1024
  58151. ExpectIntEQ(ASN1_STRING_length(str), 291);
  58152. #else
  58153. ExpectIntEQ(ASN1_STRING_length(str), 549);
  58154. #endif /* END USE_CERT_BUFFERS_1024 */
  58155. X509_PUBKEY_free(pubKey);
  58156. EVP_PKEY_free(evpKey);
  58157. #endif
  58158. return EXPECT_RESULT();
  58159. }
  58160. static int test_wolfSSL_BUF(void)
  58161. {
  58162. EXPECT_DECLS;
  58163. #if defined(OPENSSL_EXTRA)
  58164. BUF_MEM* buf = NULL;
  58165. ExpectNotNull(buf = BUF_MEM_new());
  58166. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  58167. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  58168. BUF_MEM_free(buf);
  58169. #endif
  58170. return EXPECT_RESULT();
  58171. }
  58172. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58173. static int stub_rand_seed(const void *buf, int num)
  58174. {
  58175. (void)buf;
  58176. (void)num;
  58177. return 123;
  58178. }
  58179. static int stub_rand_bytes(unsigned char *buf, int num)
  58180. {
  58181. (void)buf;
  58182. (void)num;
  58183. return 456;
  58184. }
  58185. static byte* was_stub_rand_cleanup_called(void)
  58186. {
  58187. static byte was_called = 0;
  58188. return &was_called;
  58189. }
  58190. static void stub_rand_cleanup(void)
  58191. {
  58192. byte* was_called = was_stub_rand_cleanup_called();
  58193. *was_called = 1;
  58194. return;
  58195. }
  58196. static byte* was_stub_rand_add_called(void)
  58197. {
  58198. static byte was_called = 0;
  58199. return &was_called;
  58200. }
  58201. static int stub_rand_add(const void *buf, int num, double entropy)
  58202. {
  58203. byte* was_called = was_stub_rand_add_called();
  58204. (void)buf;
  58205. (void)num;
  58206. (void)entropy;
  58207. *was_called = 1;
  58208. return 0;
  58209. }
  58210. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  58211. {
  58212. (void)buf;
  58213. (void)num;
  58214. return 9876;
  58215. }
  58216. static int stub_rand_status(void)
  58217. {
  58218. return 5432;
  58219. }
  58220. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58221. static int test_wolfSSL_RAND_set_rand_method(void)
  58222. {
  58223. EXPECT_DECLS;
  58224. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58225. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  58226. unsigned char* buf = NULL;
  58227. int num = 0;
  58228. double entropy = 0;
  58229. int ret;
  58230. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  58231. byte* was_add_called = was_stub_rand_add_called();
  58232. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  58233. DYNAMIC_TYPE_TMP_BUFFER));
  58234. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  58235. ExpectIntEQ(*was_cleanup_called, 0);
  58236. RAND_cleanup();
  58237. ExpectIntEQ(*was_cleanup_called, 0);
  58238. rand_methods.seed = &stub_rand_seed;
  58239. rand_methods.bytes = &stub_rand_bytes;
  58240. rand_methods.cleanup = &stub_rand_cleanup;
  58241. rand_methods.add = &stub_rand_add;
  58242. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  58243. rand_methods.status = &stub_rand_status;
  58244. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  58245. ExpectIntEQ(RAND_seed(buf, num), 123);
  58246. ExpectIntEQ(RAND_bytes(buf, num), 456);
  58247. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  58248. ExpectIntEQ(RAND_status(), 5432);
  58249. ExpectIntEQ(*was_add_called, 0);
  58250. /* The function pointer for RAND_add returns int, but RAND_add itself
  58251. * returns void. */
  58252. RAND_add(buf, num, entropy);
  58253. ExpectIntEQ(*was_add_called, 1);
  58254. was_add_called = 0;
  58255. ExpectIntEQ(*was_cleanup_called, 0);
  58256. RAND_cleanup();
  58257. ExpectIntEQ(*was_cleanup_called, 1);
  58258. *was_cleanup_called = 0;
  58259. ret = RAND_set_rand_method(NULL);
  58260. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  58261. ExpectIntNE(RAND_status(), 5432);
  58262. ExpectIntEQ(*was_cleanup_called, 0);
  58263. RAND_cleanup();
  58264. ExpectIntEQ(*was_cleanup_called, 0);
  58265. RAND_set_rand_method(NULL);
  58266. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58267. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58268. return EXPECT_RESULT();
  58269. }
  58270. static int test_wolfSSL_RAND_bytes(void)
  58271. {
  58272. EXPECT_DECLS;
  58273. #if defined(OPENSSL_EXTRA)
  58274. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  58275. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  58276. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  58277. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  58278. int max_bufsize;
  58279. byte *my_buf = NULL;
  58280. /* sanity check */
  58281. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  58282. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  58283. max_bufsize = size4;
  58284. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  58285. DYNAMIC_TYPE_TMP_BUFFER));
  58286. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  58287. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  58288. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  58289. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  58290. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  58291. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  58292. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  58293. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58294. #endif
  58295. return EXPECT_RESULT();
  58296. }
  58297. static int test_wolfSSL_RAND(void)
  58298. {
  58299. EXPECT_DECLS;
  58300. #if defined(OPENSSL_EXTRA)
  58301. byte seed[16];
  58302. XMEMSET(seed, 0, sizeof(seed));
  58303. /* No global methods set. */
  58304. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  58305. ExpectIntEQ(RAND_poll(), 1);
  58306. RAND_cleanup();
  58307. ExpectIntEQ(RAND_egd(NULL), -1);
  58308. #ifndef NO_FILESYSTEM
  58309. {
  58310. char fname[100];
  58311. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  58312. ExpectIntEQ(RAND_write_file(NULL), 0);
  58313. }
  58314. #endif
  58315. #endif
  58316. return EXPECT_RESULT();
  58317. }
  58318. static int test_wolfSSL_PKCS8_Compat(void)
  58319. {
  58320. EXPECT_DECLS;
  58321. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  58322. !defined(NO_BIO)
  58323. PKCS8_PRIV_KEY_INFO* pt = NULL;
  58324. BIO* bio = NULL;
  58325. XFILE f = XBADFILE;
  58326. int bytes;
  58327. char pkcs8_buffer[512];
  58328. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58329. EVP_PKEY *pkey = NULL;
  58330. #endif
  58331. /* file from wolfssl/certs/ directory */
  58332. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  58333. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  58334. 0);
  58335. if (f != XBADFILE)
  58336. XFCLOSE(f);
  58337. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58338. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  58339. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58340. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  58341. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  58342. /* gets PKCS8 pointer to pkey */
  58343. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  58344. EVP_PKEY_free(pkey);
  58345. #endif
  58346. BIO_free(bio);
  58347. PKCS8_PRIV_KEY_INFO_free(pt);
  58348. #endif
  58349. return EXPECT_RESULT();
  58350. }
  58351. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  58352. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  58353. {
  58354. (void)passwd;
  58355. (void)sz;
  58356. (void)rw;
  58357. (void)userdata;
  58358. return -1;
  58359. }
  58360. #endif
  58361. static int test_wolfSSL_PKCS8_d2i(void)
  58362. {
  58363. EXPECT_DECLS;
  58364. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  58365. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  58366. * requires a 12 byte password in FIPS mode. This test ends up
  58367. * trying to use an 8 byte password. */
  58368. #ifndef NO_FILESYSTEM
  58369. unsigned char pkcs8_buffer[2048];
  58370. const unsigned char* p = NULL;
  58371. int bytes = 0;
  58372. XFILE file = XBADFILE;
  58373. WOLFSSL_EVP_PKEY* pkey = NULL;
  58374. #ifndef NO_BIO
  58375. BIO* bio = NULL;
  58376. #if defined(OPENSSL_ALL) && \
  58377. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  58378. defined(HAVE_ECC)) && \
  58379. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58380. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  58381. #endif
  58382. #endif
  58383. #ifndef NO_RSA
  58384. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  58385. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  58386. #ifndef NO_DES3
  58387. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  58388. #endif
  58389. #endif /* NO_RSA */
  58390. #ifdef HAVE_ECC
  58391. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  58392. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  58393. #ifndef NO_DES3
  58394. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  58395. #endif
  58396. #endif /* HAVE_ECC */
  58397. #endif /* !NO_FILESYSTEM */
  58398. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  58399. #ifndef NO_RSA
  58400. #ifdef USE_CERT_BUFFERS_1024
  58401. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  58402. int rsaSz = sizeof_server_key_der_1024;
  58403. #else
  58404. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  58405. int rsaSz = sizeof_server_key_der_2048;
  58406. #endif
  58407. #endif
  58408. #ifdef HAVE_ECC
  58409. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  58410. int ecSz = sizeof_ecc_key_der_256;
  58411. #endif
  58412. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  58413. #ifndef NO_FILESYSTEM
  58414. (void)pkcs8_buffer;
  58415. (void)p;
  58416. (void)bytes;
  58417. (void)file;
  58418. #ifndef NO_BIO
  58419. (void)bio;
  58420. #endif
  58421. #endif
  58422. #ifdef OPENSSL_ALL
  58423. #ifndef NO_RSA
  58424. /* Try to auto-detect normal RSA private key */
  58425. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  58426. EVP_PKEY_free(pkey);
  58427. pkey = NULL;
  58428. #endif
  58429. #ifdef HAVE_ECC
  58430. /* Try to auto-detect normal EC private key */
  58431. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  58432. EVP_PKEY_free(pkey);
  58433. pkey = NULL;
  58434. #endif
  58435. #endif /* OPENSSL_ALL */
  58436. #ifndef NO_FILESYSTEM
  58437. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58438. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  58439. NULL), 0);
  58440. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  58441. NULL), 0);
  58442. #endif
  58443. #ifndef NO_RSA
  58444. /* Get DER encoded RSA PKCS#8 data. */
  58445. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  58446. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58447. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58448. file)), 0);
  58449. if (file != XBADFILE) {
  58450. XFCLOSE(file);
  58451. file = XBADFILE;
  58452. }
  58453. p = pkcs8_buffer;
  58454. #ifdef OPENSSL_ALL
  58455. /* Try to decode - auto-detect key type. */
  58456. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58457. #else
  58458. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  58459. #endif
  58460. /* Get PEM encoded RSA PKCS#8 data. */
  58461. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  58462. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58463. file)), 0);
  58464. if (file != XBADFILE) {
  58465. XFCLOSE(file);
  58466. file = XBADFILE;
  58467. }
  58468. #if defined(OPENSSL_ALL) && \
  58469. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58470. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58471. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  58472. NULL), 0);
  58473. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  58474. NULL), 0);
  58475. /* Write PKCS#8 PEM to BIO. */
  58476. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58477. NULL), bytes);
  58478. /* Write PKCS#8 PEM to stderr. */
  58479. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58480. NULL), bytes);
  58481. /* Compare file and written data */
  58482. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58483. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58484. BIO_free(bio);
  58485. bio = NULL;
  58486. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  58487. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  58488. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  58489. #endif
  58490. #if !defined(NO_DES3) && !defined(NO_SHA)
  58491. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58492. /* Write Encrypted PKCS#8 PEM to BIO. */
  58493. bytes = 1834;
  58494. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  58495. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58496. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  58497. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58498. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58499. (void*)"yassl123"));
  58500. EVP_PKEY_free(evpPkey);
  58501. evpPkey = NULL;
  58502. BIO_free(bio);
  58503. bio = NULL;
  58504. #endif /* !NO_DES3 && !NO_SHA */
  58505. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58506. EVP_PKEY_free(pkey);
  58507. pkey = NULL;
  58508. /* PKCS#8 encrypted RSA key */
  58509. #ifndef NO_DES3
  58510. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  58511. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58512. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58513. file)), 0);
  58514. if (file != XBADFILE) {
  58515. XFCLOSE(file);
  58516. file = XBADFILE;
  58517. }
  58518. #if defined(OPENSSL_ALL) && \
  58519. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58520. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58521. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58522. (void*)"yassl123"));
  58523. EVP_PKEY_free(pkey);
  58524. pkey = NULL;
  58525. BIO_free(bio);
  58526. bio = NULL;
  58527. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58528. #endif /* !NO_DES3 */
  58529. #endif /* NO_RSA */
  58530. #ifdef HAVE_ECC
  58531. /* PKCS#8 encode EC key */
  58532. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  58533. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58534. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58535. file)), 0);
  58536. if (file != XBADFILE) {
  58537. XFCLOSE(file);
  58538. file = XBADFILE;
  58539. }
  58540. p = pkcs8_buffer;
  58541. #ifdef OPENSSL_ALL
  58542. /* Try to decode - auto-detect key type. */
  58543. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58544. #else
  58545. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  58546. #endif
  58547. /* Get PEM encoded RSA PKCS#8 data. */
  58548. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  58549. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58550. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58551. file)), 0);
  58552. if (file != XBADFILE) {
  58553. XFCLOSE(file);
  58554. file = XBADFILE;
  58555. }
  58556. #if defined(OPENSSL_ALL) && \
  58557. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  58558. defined(HAVE_AES_CBC)
  58559. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58560. /* Write PKCS#8 PEM to BIO. */
  58561. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58562. NULL), bytes);
  58563. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58564. NULL), bytes);
  58565. /* Compare file and written data */
  58566. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58567. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58568. BIO_free(bio);
  58569. bio = NULL;
  58570. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58571. /* Write Encrypted PKCS#8 PEM to BIO. */
  58572. bytes = 379;
  58573. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58574. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  58575. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58576. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58577. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58578. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58579. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58580. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  58581. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  58582. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58583. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58584. (void*)"yassl123"));
  58585. EVP_PKEY_free(evpPkey);
  58586. evpPkey = NULL;
  58587. BIO_free(bio);
  58588. bio = NULL;
  58589. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  58590. EVP_PKEY_free(pkey);
  58591. pkey = NULL;
  58592. /* PKCS#8 encrypted EC key */
  58593. #ifndef NO_DES3
  58594. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  58595. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58596. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58597. file)), 0);
  58598. if (file != XBADFILE) {
  58599. XFCLOSE(file);
  58600. file = XBADFILE;
  58601. }
  58602. #if defined(OPENSSL_ALL) && \
  58603. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58604. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58605. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58606. (void*)"yassl123"));
  58607. EVP_PKEY_free(pkey);
  58608. pkey = NULL;
  58609. BIO_free(bio);
  58610. bio = NULL;
  58611. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58612. #endif /* !NO_DES3 */
  58613. #endif /* HAVE_ECC */
  58614. #endif /* !NO_FILESYSTEM */
  58615. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  58616. return EXPECT_RESULT();
  58617. }
  58618. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58619. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58620. defined(DEBUG_WOLFSSL)
  58621. #define LOGGING_THREADS 5
  58622. #define ERROR_COUNT 10
  58623. /* copied from logging.c since this is not exposed otherwise */
  58624. #ifndef ERROR_QUEUE_MAX
  58625. #ifdef ERROR_QUEUE_PER_THREAD
  58626. #define ERROR_QUEUE_MAX 16
  58627. #else
  58628. /* this breaks from compat of unlimited error queue size */
  58629. #define ERROR_QUEUE_MAX 100
  58630. #endif
  58631. #endif
  58632. static volatile int loggingThreadsReady;
  58633. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  58634. {
  58635. const char* file;
  58636. int line;
  58637. unsigned long err;
  58638. int errorCount = 0;
  58639. int i;
  58640. (void)args;
  58641. while (!loggingThreadsReady);
  58642. for (i = 0; i < ERROR_COUNT; i++)
  58643. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58644. while ((err = ERR_get_error_line(&file, &line))) {
  58645. AssertIntEQ(err, 990 + errorCount);
  58646. errorCount++;
  58647. }
  58648. AssertIntEQ(errorCount, ERROR_COUNT);
  58649. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  58650. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  58651. errorCount = 0;
  58652. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  58653. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58654. while ((err = ERR_get_error_line(&file, &line))) {
  58655. AssertIntEQ(err, 990 + errorCount);
  58656. errorCount++;
  58657. }
  58658. /* test that the 3 errors over the max were dropped */
  58659. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  58660. WOLFSSL_RETURN_FROM_THREAD(0);
  58661. }
  58662. #endif
  58663. static int test_error_queue_per_thread(void)
  58664. {
  58665. int res = TEST_SKIPPED;
  58666. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58667. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58668. defined(DEBUG_WOLFSSL)
  58669. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  58670. int i;
  58671. ERR_clear_error(); /* clear out any error nodes */
  58672. loggingThreadsReady = 0;
  58673. for (i = 0; i < LOGGING_THREADS; i++)
  58674. start_thread(test_logging, NULL, &loggingThreads[i]);
  58675. loggingThreadsReady = 1;
  58676. for (i = 0; i < LOGGING_THREADS; i++)
  58677. join_thread(loggingThreads[i]);
  58678. res = TEST_SUCCESS;
  58679. #endif
  58680. return res;
  58681. }
  58682. static int test_wolfSSL_ERR_put_error(void)
  58683. {
  58684. EXPECT_DECLS;
  58685. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58686. defined(DEBUG_WOLFSSL)
  58687. const char* file;
  58688. int line;
  58689. ERR_clear_error(); /* clear out any error nodes */
  58690. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58691. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58692. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  58693. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  58694. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  58695. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  58696. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  58697. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  58698. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  58699. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  58700. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  58701. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  58702. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  58703. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  58704. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  58705. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  58706. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  58707. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  58708. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  58709. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  58710. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  58711. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  58712. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  58713. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  58714. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  58715. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  58716. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  58717. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  58718. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  58719. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  58720. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  58721. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  58722. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  58723. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  58724. "this file", 100);
  58725. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  58726. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58727. ExpectIntEQ(line, 100);
  58728. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  58729. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58730. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  58731. #endif
  58732. /* try reading past end of error queue */
  58733. file = NULL;
  58734. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58735. ExpectNull(file);
  58736. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  58737. PEMerr(4,4);
  58738. ExpectIntEQ(ERR_get_error(), 4);
  58739. /* Empty and free up all error nodes */
  58740. ERR_clear_error();
  58741. /* Verify all nodes are cleared */
  58742. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58743. ERR_clear_error();
  58744. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58745. #endif
  58746. return EXPECT_RESULT();
  58747. }
  58748. /*
  58749. * This is a regression test for a bug where the peek/get error functions were
  58750. * drawing from the end of the queue rather than the front.
  58751. */
  58752. static int test_wolfSSL_ERR_get_error_order(void)
  58753. {
  58754. EXPECT_DECLS;
  58755. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  58756. /* Empty the queue. */
  58757. wolfSSL_ERR_clear_error();
  58758. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  58759. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  58760. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  58761. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  58762. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  58763. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  58764. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  58765. return EXPECT_RESULT();
  58766. }
  58767. #ifndef NO_BIO
  58768. static int test_wolfSSL_ERR_print_errors(void)
  58769. {
  58770. EXPECT_DECLS;
  58771. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58772. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  58773. BIO* bio = NULL;
  58774. char buf[1024];
  58775. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58776. ERR_clear_error(); /* clear out any error nodes */
  58777. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  58778. /* Choosing -600 as an unused errno. */
  58779. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  58780. ERR_print_errors(bio);
  58781. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  58782. ExpectIntEQ(XSTRNCMP(
  58783. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  58784. buf, 55), 0);
  58785. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  58786. ExpectIntEQ(XSTRNCMP(
  58787. "error:600:wolfSSL library:unknown error number:asn.c:100",
  58788. buf, 56), 0);
  58789. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  58790. ExpectIntEQ(buf[0], '\0');
  58791. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  58792. BIO_free(bio);
  58793. #endif
  58794. return EXPECT_RESULT();
  58795. }
  58796. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58797. defined(DEBUG_WOLFSSL)
  58798. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  58799. {
  58800. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  58801. return 0;
  58802. }
  58803. #endif
  58804. static int test_wolfSSL_ERR_print_errors_cb(void)
  58805. {
  58806. EXPECT_DECLS;
  58807. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58808. defined(DEBUG_WOLFSSL)
  58809. BIO* bio = NULL;
  58810. char buf[1024];
  58811. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58812. ERR_clear_error(); /* clear out any error nodes */
  58813. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  58814. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  58815. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  58816. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  58817. ExpectIntEQ(XSTRNCMP(
  58818. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  58819. buf, 53), 0);
  58820. ExpectIntEQ(XSTRNCMP(
  58821. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  58822. buf + 53, 55), 0);
  58823. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  58824. BIO_free(bio);
  58825. #endif
  58826. return EXPECT_RESULT();
  58827. }
  58828. /*
  58829. * Testing WOLFSSL_ERROR_MSG
  58830. */
  58831. static int test_WOLFSSL_ERROR_MSG(void)
  58832. {
  58833. int res = TEST_SKIPPED;
  58834. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  58835. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  58836. const char* msg = TEST_STRING;
  58837. WOLFSSL_ERROR_MSG(msg);
  58838. res = TEST_SUCCESS;
  58839. #endif
  58840. return res;
  58841. } /* End test_WOLFSSL_ERROR_MSG */
  58842. /*
  58843. * Testing wc_ERR_remove_state
  58844. */
  58845. static int test_wc_ERR_remove_state(void)
  58846. {
  58847. int res = TEST_SKIPPED;
  58848. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  58849. wc_ERR_remove_state();
  58850. res = TEST_SUCCESS;
  58851. #endif
  58852. return res;
  58853. } /* End test_wc_ERR_remove_state */
  58854. /*
  58855. * Testing wc_ERR_print_errors_fp
  58856. */
  58857. static int test_wc_ERR_print_errors_fp(void)
  58858. {
  58859. EXPECT_DECLS;
  58860. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  58861. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  58862. long sz;
  58863. XFILE fp = XBADFILE;
  58864. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  58865. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  58866. XBADFILE);
  58867. wc_ERR_print_errors_fp(fp);
  58868. #if defined(DEBUG_WOLFSSL)
  58869. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  58870. #ifdef NO_ERROR_QUEUE
  58871. ExpectIntEQ(sz = XFTELL(fp), 0);
  58872. #else
  58873. ExpectIntNE(sz = XFTELL(fp), 0);
  58874. #endif
  58875. #endif
  58876. if (fp != XBADFILE)
  58877. XFCLOSE(fp);
  58878. (void)sz;
  58879. #endif
  58880. return EXPECT_RESULT();
  58881. } /* End test_wc_ERR_print_errors_fp */
  58882. #ifdef DEBUG_WOLFSSL
  58883. static void Logging_cb(const int logLevel, const char *const logMessage)
  58884. {
  58885. (void)logLevel;
  58886. (void)logMessage;
  58887. }
  58888. #endif
  58889. /*
  58890. * Testing wolfSSL_GetLoggingCb
  58891. */
  58892. static int test_wolfSSL_GetLoggingCb(void)
  58893. {
  58894. EXPECT_DECLS;
  58895. #ifdef DEBUG_WOLFSSL
  58896. /* Testing without wolfSSL_SetLoggingCb() */
  58897. ExpectNull(wolfSSL_GetLoggingCb());
  58898. /* Testing with wolfSSL_SetLoggingCb() */
  58899. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  58900. ExpectNotNull(wolfSSL_GetLoggingCb());
  58901. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  58902. #endif
  58903. ExpectNull(wolfSSL_GetLoggingCb());
  58904. return EXPECT_RESULT();
  58905. } /* End test_wolfSSL_GetLoggingCb */
  58906. #endif /* !NO_BIO */
  58907. static int test_wolfSSL_MD4(void)
  58908. {
  58909. EXPECT_DECLS;
  58910. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  58911. MD4_CTX md4;
  58912. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  58913. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  58914. "789012345678901234567890";
  58915. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  58916. "\xcc\x05\x36";
  58917. int msgSz = (int)XSTRLEN(msg);
  58918. XMEMSET(out, 0, sizeof(out));
  58919. MD4_Init(&md4);
  58920. MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz);
  58921. MD4_Final(out, &md4);
  58922. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  58923. #endif
  58924. return EXPECT_RESULT();
  58925. }
  58926. static int test_wolfSSL_MD5(void)
  58927. {
  58928. EXPECT_DECLS;
  58929. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  58930. byte input1[] = "";
  58931. byte input2[] = "message digest";
  58932. byte hash[WC_MD5_DIGEST_SIZE];
  58933. unsigned char output1[] =
  58934. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  58935. unsigned char output2[] =
  58936. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  58937. WOLFSSL_MD5_CTX md5;
  58938. XMEMSET(&md5, 0, sizeof(md5));
  58939. /* Test cases for illegal parameters */
  58940. ExpectIntEQ(MD5_Init(NULL), 0);
  58941. ExpectIntEQ(MD5_Init(&md5), 1);
  58942. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  58943. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  58944. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  58945. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  58946. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  58947. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  58948. /* Init MD5 CTX */
  58949. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  58950. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  58951. 1);
  58952. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  58953. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  58954. /* Init MD5 CTX */
  58955. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  58956. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  58957. (int)XSTRLEN((const char*)input2)), 1);
  58958. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  58959. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  58960. #if !defined(NO_OLD_NAMES) && \
  58961. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  58962. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  58963. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  58964. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  58965. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  58966. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  58967. &hash);
  58968. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  58969. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  58970. &hash);
  58971. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  58972. {
  58973. byte data[] = "Data to be hashed.";
  58974. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  58975. ExpectNotNull(MD5(data, sizeof(data), NULL));
  58976. ExpectNotNull(MD5(data, sizeof(data), hash));
  58977. ExpectNotNull(MD5(NULL, 0, hash));
  58978. ExpectNull(MD5(NULL, sizeof(data), hash));
  58979. }
  58980. #endif
  58981. #endif
  58982. return EXPECT_RESULT();
  58983. }
  58984. static int test_wolfSSL_MD5_Transform(void)
  58985. {
  58986. EXPECT_DECLS;
  58987. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  58988. byte input1[] = "";
  58989. byte input2[] = "abc";
  58990. byte local[WC_MD5_BLOCK_SIZE];
  58991. word32 sLen = 0;
  58992. #ifdef BIG_ENDIAN_ORDER
  58993. unsigned char output1[] =
  58994. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  58995. unsigned char output2[] =
  58996. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  58997. #else
  58998. unsigned char output1[] =
  58999. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  59000. unsigned char output2[] =
  59001. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  59002. #endif
  59003. union {
  59004. wc_Md5 native;
  59005. MD5_CTX compat;
  59006. } md5;
  59007. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  59008. XMEMSET(&local, 0, sizeof(local));
  59009. /* sanity check */
  59010. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  59011. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  59012. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  59013. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59014. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59015. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59016. /* Init MD5 CTX */
  59017. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  59018. /* Do Transform*/
  59019. sLen = (word32)XSTRLEN((char*)input1);
  59020. XMEMCPY(local, input1, sLen);
  59021. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59022. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  59023. /* Init MD5 CTX */
  59024. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  59025. sLen = (word32)XSTRLEN((char*)input2);
  59026. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  59027. XMEMCPY(local, input2, sLen);
  59028. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59029. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  59030. #endif
  59031. return EXPECT_RESULT();
  59032. }
  59033. static int test_wolfSSL_SHA(void)
  59034. {
  59035. EXPECT_DECLS;
  59036. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  59037. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  59038. (!defined(HAVE_FIPS) || \
  59039. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59040. {
  59041. const unsigned char in[] = "abc";
  59042. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  59043. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  59044. unsigned char out[WC_SHA_DIGEST_SIZE];
  59045. unsigned char* p = NULL;
  59046. WOLFSSL_SHA_CTX sha;
  59047. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59048. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  59049. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59050. /* SHA interface test */
  59051. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59052. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  59053. ExpectNotNull(SHA(in, 0, out));
  59054. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  59055. ExpectNotNull(SHA(NULL, 0, out));
  59056. ExpectNotNull(SHA(NULL, 0, NULL));
  59057. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  59058. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59059. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  59060. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  59061. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  59062. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59063. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  59064. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59065. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  59066. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59067. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  59068. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59069. }
  59070. #endif
  59071. #if !defined(NO_SHA256)
  59072. {
  59073. const unsigned char in[] = "abc";
  59074. unsigned char expected[] =
  59075. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  59076. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  59077. "\x15\xAD";
  59078. unsigned char out[WC_SHA256_DIGEST_SIZE];
  59079. unsigned char* p = NULL;
  59080. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  59081. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59082. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  59083. #else
  59084. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  59085. #endif
  59086. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  59087. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59088. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  59089. #else
  59090. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  59091. #endif
  59092. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  59093. }
  59094. #endif
  59095. #if defined(WOLFSSL_SHA384)
  59096. {
  59097. const unsigned char in[] = "abc";
  59098. unsigned char expected[] =
  59099. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  59100. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  59101. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  59102. "\xc8\x25\xa7";
  59103. unsigned char out[WC_SHA384_DIGEST_SIZE];
  59104. unsigned char* p = NULL;
  59105. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  59106. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59107. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  59108. #else
  59109. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  59110. #endif
  59111. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  59112. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59113. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  59114. #else
  59115. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  59116. #endif
  59117. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  59118. }
  59119. #endif
  59120. #if defined(WOLFSSL_SHA512)
  59121. {
  59122. const unsigned char in[] = "abc";
  59123. unsigned char expected[] =
  59124. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  59125. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  59126. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  59127. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  59128. "\xa5\x4c\xa4\x9f";
  59129. unsigned char out[WC_SHA512_DIGEST_SIZE];
  59130. unsigned char* p = NULL;
  59131. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  59132. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59133. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  59134. #else
  59135. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  59136. #endif
  59137. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  59138. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59139. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  59140. #else
  59141. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  59142. #endif
  59143. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  59144. }
  59145. #endif
  59146. #endif
  59147. return EXPECT_RESULT();
  59148. }
  59149. static int test_wolfSSL_SHA_Transform(void)
  59150. {
  59151. EXPECT_DECLS;
  59152. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  59153. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59154. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  59155. byte input1[] = "";
  59156. byte input2[] = "abc";
  59157. byte local[WC_SHA_BLOCK_SIZE];
  59158. word32 sLen = 0;
  59159. #ifdef BIG_ENDIAN_ORDER
  59160. unsigned char output1[] =
  59161. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  59162. "\x09\xf7\x3a\x93";
  59163. unsigned char output2[] =
  59164. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  59165. "\x7c\x6e\x08\xb8";
  59166. #else
  59167. unsigned char output1[] =
  59168. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  59169. "\x93\x3a\xf7\x09";
  59170. unsigned char output2[] =
  59171. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  59172. "\xb8\x08\x6e\x7c";
  59173. #endif
  59174. union {
  59175. wc_Sha native;
  59176. SHA_CTX compat;
  59177. } sha;
  59178. union {
  59179. wc_Sha native;
  59180. SHA_CTX compat;
  59181. } sha1;
  59182. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  59183. XMEMSET(&local, 0, sizeof(local));
  59184. /* sanity check */
  59185. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  59186. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  59187. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  59188. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  59189. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  59190. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  59191. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59192. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59193. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59194. /* Init SHA CTX */
  59195. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59196. /* Do Transform*/
  59197. sLen = (word32)XSTRLEN((char*)input1);
  59198. XMEMCPY(local, input1, sLen);
  59199. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59200. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59201. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59202. /* Init SHA CTX */
  59203. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59204. sLen = (word32)XSTRLEN((char*)input2);
  59205. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59206. XMEMCPY(local, input2, sLen);
  59207. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59208. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59209. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59210. /* SHA1 */
  59211. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59212. /* Init SHA CTX */
  59213. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59214. /* Do Transform*/
  59215. sLen = (word32)XSTRLEN((char*)input1);
  59216. XMEMCPY(local, input1, sLen);
  59217. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59218. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59219. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  59220. /* Init SHA CTX */
  59221. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59222. sLen = (word32)XSTRLEN((char*)input2);
  59223. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59224. XMEMCPY(local, input2, sLen);
  59225. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59226. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59227. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  59228. #endif
  59229. #endif
  59230. return EXPECT_RESULT();
  59231. }
  59232. static int test_wolfSSL_SHA224(void)
  59233. {
  59234. EXPECT_DECLS;
  59235. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  59236. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59237. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59238. unsigned char input[] =
  59239. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59240. unsigned char output[] =
  59241. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  59242. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  59243. size_t inLen;
  59244. byte hash[WC_SHA224_DIGEST_SIZE];
  59245. unsigned char* p;
  59246. inLen = XSTRLEN((char*)input);
  59247. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  59248. ExpectNull(SHA224(NULL, inLen, hash));
  59249. ExpectNotNull(SHA224(input, 0, hash));
  59250. ExpectNotNull(SHA224(input, inLen, NULL));
  59251. ExpectNotNull(SHA224(NULL, 0, hash));
  59252. ExpectNotNull(SHA224(NULL, 0, NULL));
  59253. ExpectNotNull(SHA224(input, inLen, hash));
  59254. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  59255. ExpectNotNull(p = SHA224(input, inLen, NULL));
  59256. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  59257. #endif
  59258. return EXPECT_RESULT();
  59259. }
  59260. static int test_wolfSSL_SHA256(void)
  59261. {
  59262. EXPECT_DECLS;
  59263. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  59264. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  59265. unsigned char input[] =
  59266. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59267. unsigned char output[] =
  59268. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  59269. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  59270. "\x06\xC1";
  59271. size_t inLen;
  59272. byte hash[WC_SHA256_DIGEST_SIZE];
  59273. inLen = XSTRLEN((char*)input);
  59274. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  59275. ExpectNotNull(SHA256(input, inLen, hash));
  59276. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  59277. #endif
  59278. return EXPECT_RESULT();
  59279. }
  59280. static int test_wolfSSL_SHA256_Transform(void)
  59281. {
  59282. EXPECT_DECLS;
  59283. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  59284. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59285. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59286. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  59287. !defined(WOLFSSL_KCAPI_HASH)
  59288. byte input1[] = "";
  59289. byte input2[] = "abc";
  59290. byte local[WC_SHA256_BLOCK_SIZE];
  59291. word32 sLen = 0;
  59292. #ifdef BIG_ENDIAN_ORDER
  59293. unsigned char output1[] =
  59294. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  59295. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  59296. unsigned char output2[] =
  59297. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  59298. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  59299. #else
  59300. unsigned char output1[] =
  59301. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  59302. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  59303. unsigned char output2[] =
  59304. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  59305. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  59306. #endif
  59307. union {
  59308. wc_Sha256 native;
  59309. SHA256_CTX compat;
  59310. } sha256;
  59311. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  59312. XMEMSET(&local, 0, sizeof(local));
  59313. /* sanity check */
  59314. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  59315. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  59316. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  59317. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59318. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59319. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59320. /* Init SHA256 CTX */
  59321. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59322. /* Do Transform*/
  59323. sLen = (word32)XSTRLEN((char*)input1);
  59324. XMEMCPY(local, input1, sLen);
  59325. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59326. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  59327. 0);
  59328. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59329. /* Init SHA256 CTX */
  59330. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59331. sLen = (word32)XSTRLEN((char*)input2);
  59332. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  59333. XMEMCPY(local, input2, sLen);
  59334. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59335. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  59336. 0);
  59337. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59338. #endif
  59339. #endif
  59340. return EXPECT_RESULT();
  59341. }
  59342. static int test_wolfSSL_SHA512_Transform(void)
  59343. {
  59344. EXPECT_DECLS;
  59345. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  59346. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59347. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59348. !defined(WOLFSSL_KCAPI_HASH)
  59349. byte input1[] = "";
  59350. byte input2[] = "abc";
  59351. byte local[WC_SHA512_BLOCK_SIZE];
  59352. word32 sLen = 0;
  59353. #ifdef BIG_ENDIAN_ORDER
  59354. unsigned char output1[] =
  59355. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  59356. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  59357. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  59358. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  59359. unsigned char output2[] =
  59360. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  59361. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  59362. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  59363. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  59364. #else
  59365. unsigned char output1[] =
  59366. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  59367. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  59368. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  59369. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  59370. unsigned char output2[] =
  59371. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  59372. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  59373. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  59374. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  59375. #endif
  59376. union {
  59377. wc_Sha512 native;
  59378. SHA512_CTX compat;
  59379. } sha512;
  59380. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59381. XMEMSET(&local, 0, sizeof(local));
  59382. /* sanity check */
  59383. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  59384. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  59385. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  59386. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59387. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59388. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59389. /* Init SHA512 CTX */
  59390. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  59391. /* Do Transform*/
  59392. sLen = (word32)XSTRLEN((char*)input1);
  59393. XMEMCPY(local, input1, sLen);
  59394. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59395. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59396. WC_SHA512_DIGEST_SIZE), 0);
  59397. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59398. /* Init SHA512 CTX */
  59399. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  59400. sLen = (word32)XSTRLEN((char*)input2);
  59401. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59402. XMEMCPY(local, input2, sLen);
  59403. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59404. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59405. WC_SHA512_DIGEST_SIZE), 0);
  59406. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59407. (void)input1;
  59408. #endif
  59409. #endif
  59410. return EXPECT_RESULT();
  59411. }
  59412. static int test_wolfSSL_SHA512_224_Transform(void)
  59413. {
  59414. EXPECT_DECLS;
  59415. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59416. !defined(WOLFSSL_NOSHA512_224)
  59417. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59418. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59419. !defined(WOLFSSL_KCAPI_HASH)
  59420. byte input1[] = "";
  59421. byte input2[] = "abc";
  59422. byte local[WC_SHA512_BLOCK_SIZE];
  59423. word32 sLen = 0;
  59424. unsigned char output1[] =
  59425. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  59426. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  59427. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  59428. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  59429. unsigned char output2[] =
  59430. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  59431. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  59432. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  59433. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  59434. union {
  59435. wc_Sha512 native;
  59436. SHA512_CTX compat;
  59437. } sha512;
  59438. #ifdef BIG_ENDIAN_ORDER
  59439. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59440. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59441. #endif
  59442. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59443. XMEMSET(&local, 0, sizeof(local));
  59444. /* sanity check */
  59445. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  59446. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  59447. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  59448. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59449. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  59450. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59451. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59452. /* Init SHA512 CTX */
  59453. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  59454. /* Do Transform*/
  59455. sLen = (word32)XSTRLEN((char*)input1);
  59456. XMEMCPY(local, input1, sLen);
  59457. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59458. 1);
  59459. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59460. WC_SHA512_DIGEST_SIZE), 0);
  59461. /* frees resources */
  59462. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59463. /* Init SHA512 CTX */
  59464. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  59465. sLen = (word32)XSTRLEN((char*)input2);
  59466. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59467. XMEMCPY(local, input2, sLen);
  59468. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59469. 1);
  59470. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59471. WC_SHA512_DIGEST_SIZE), 0);
  59472. /* frees resources */
  59473. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59474. #endif
  59475. #endif
  59476. return EXPECT_RESULT();
  59477. }
  59478. static int test_wolfSSL_SHA512_256_Transform(void)
  59479. {
  59480. EXPECT_DECLS;
  59481. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59482. !defined(WOLFSSL_NOSHA512_256)
  59483. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59484. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59485. !defined(WOLFSSL_KCAPI_HASH)
  59486. byte input1[] = "";
  59487. byte input2[] = "abc";
  59488. byte local[WC_SHA512_BLOCK_SIZE];
  59489. word32 sLen = 0;
  59490. unsigned char output1[] =
  59491. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  59492. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  59493. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  59494. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  59495. unsigned char output2[] =
  59496. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  59497. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  59498. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  59499. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  59500. union {
  59501. wc_Sha512 native;
  59502. SHA512_CTX compat;
  59503. } sha512;
  59504. #ifdef BIG_ENDIAN_ORDER
  59505. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59506. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59507. #endif
  59508. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59509. XMEMSET(&local, 0, sizeof(local));
  59510. /* sanity check */
  59511. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  59512. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  59513. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  59514. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59515. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  59516. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59517. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59518. /* Init SHA512 CTX */
  59519. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  59520. /* Do Transform*/
  59521. sLen = (word32)XSTRLEN((char*)input1);
  59522. XMEMCPY(local, input1, sLen);
  59523. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59524. 1);
  59525. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59526. WC_SHA512_DIGEST_SIZE), 0);
  59527. /* frees resources */
  59528. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59529. /* Init SHA512 CTX */
  59530. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  59531. sLen = (word32)XSTRLEN((char*)input2);
  59532. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59533. XMEMCPY(local, input2, sLen);
  59534. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59535. 1);
  59536. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59537. WC_SHA512_DIGEST_SIZE), 0);
  59538. /* frees resources */
  59539. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59540. #endif
  59541. #endif
  59542. return EXPECT_RESULT();
  59543. }
  59544. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59545. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  59546. * buffer of 64 bytes.
  59547. *
  59548. * returns the size of the digest buffer on success and a negative value on
  59549. * failure.
  59550. */
  59551. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  59552. int* sz)
  59553. {
  59554. EXPECT_DECLS;
  59555. HMAC_CTX ctx1;
  59556. HMAC_CTX ctx2;
  59557. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  59558. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  59559. unsigned char long_key[] =
  59560. "0123456789012345678901234567890123456789"
  59561. "0123456789012345678901234567890123456789"
  59562. "0123456789012345678901234567890123456789"
  59563. "0123456789012345678901234567890123456789";
  59564. unsigned char msg[] = "message to hash";
  59565. unsigned int digestSz = 64;
  59566. int keySz = sizeof(key);
  59567. int long_keySz = sizeof(long_key);
  59568. int msgSz = sizeof(msg);
  59569. unsigned char digest2[64];
  59570. unsigned int digestSz2 = 64;
  59571. HMAC_CTX_init(&ctx1);
  59572. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59573. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59574. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59575. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59576. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59577. HMAC_CTX_cleanup(&ctx1);
  59578. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59579. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  59580. HMAC_CTX_cleanup(&ctx2);
  59581. ExpectIntEQ(digestSz, digestSz2);
  59582. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59583. /* test HMAC_Init with NULL key */
  59584. /* init after copy */
  59585. HMAC_CTX_init(&ctx1);
  59586. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59587. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59588. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59589. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59590. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59591. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59592. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59593. HMAC_CTX_cleanup(&ctx1);
  59594. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59595. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59596. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59597. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59598. HMAC_CTX_cleanup(&ctx2);
  59599. ExpectIntEQ(digestSz, digestSz2);
  59600. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59601. /* long key */
  59602. HMAC_CTX_init(&ctx1);
  59603. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  59604. SSL_SUCCESS);
  59605. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59606. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59607. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59608. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59609. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59610. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59611. HMAC_CTX_cleanup(&ctx1);
  59612. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59613. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59614. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59615. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59616. HMAC_CTX_cleanup(&ctx2);
  59617. ExpectIntEQ(digestSz, digestSz2);
  59618. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59619. /* init before copy */
  59620. HMAC_CTX_init(&ctx1);
  59621. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59622. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59623. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59624. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59625. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59626. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59627. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59628. HMAC_CTX_cleanup(&ctx1);
  59629. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59630. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59631. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59632. HMAC_CTX_cleanup(&ctx2);
  59633. ExpectIntEQ(digestSz, digestSz2);
  59634. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59635. *sz = (int)digestSz;
  59636. return EXPECT_RESULT();
  59637. }
  59638. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  59639. static int test_wolfSSL_HMAC_CTX(void)
  59640. {
  59641. EXPECT_DECLS;
  59642. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59643. unsigned char digest[64];
  59644. int digestSz;
  59645. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  59646. WOLFSSL_HMAC_CTX ctx1;
  59647. WOLFSSL_HMAC_CTX ctx2;
  59648. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  59649. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  59650. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  59651. wolfSSL_HMAC_CTX_free(NULL);
  59652. wolfSSL_HMAC_CTX_free(hmac_ctx);
  59653. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  59654. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  59655. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  59656. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  59657. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  59658. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  59659. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59660. ((! defined(HAVE_FIPS_VERSION)) || \
  59661. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59662. /* Copy object that hasn't had a digest set - MD5. */
  59663. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  59664. #else
  59665. /* Copy object that hasn't had a digest set. */
  59666. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  59667. #endif
  59668. HMAC_CTX_cleanup(NULL);
  59669. HMAC_CTX_cleanup(&ctx2);
  59670. ExpectNull(HMAC_CTX_get_md(NULL));
  59671. #ifndef NO_SHA
  59672. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  59673. TEST_SUCCESS);
  59674. ExpectIntEQ(digestSz, 20);
  59675. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  59676. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  59677. #endif /* !NO_SHA */
  59678. #ifdef WOLFSSL_SHA224
  59679. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  59680. TEST_SUCCESS);
  59681. ExpectIntEQ(digestSz, 28);
  59682. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  59683. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  59684. "\x02\x0E", digest, digestSz), 0);
  59685. #endif /* WOLFSSL_SHA224 */
  59686. #ifndef NO_SHA256
  59687. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  59688. TEST_SUCCESS);
  59689. ExpectIntEQ(digestSz, 32);
  59690. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  59691. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  59692. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  59693. #endif /* !NO_SHA256 */
  59694. #ifdef WOLFSSL_SHA384
  59695. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  59696. TEST_SUCCESS);
  59697. ExpectIntEQ(digestSz, 48);
  59698. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  59699. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  59700. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  59701. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  59702. digest, digestSz), 0);
  59703. #endif /* WOLFSSL_SHA384 */
  59704. #ifdef WOLFSSL_SHA512
  59705. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  59706. TEST_SUCCESS);
  59707. ExpectIntEQ(digestSz, 64);
  59708. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  59709. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  59710. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  59711. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  59712. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  59713. digest, digestSz), 0);
  59714. #endif /* WOLFSSL_SHA512 */
  59715. #ifdef WOLFSSL_SHA3
  59716. #ifndef WOLFSSL_NOSHA3_224
  59717. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  59718. TEST_SUCCESS);
  59719. ExpectIntEQ(digestSz, 28);
  59720. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  59721. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  59722. "\x29\x0f", digest, digestSz), 0);
  59723. #endif
  59724. #ifndef WOLFSSL_NOSHA3_256
  59725. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  59726. TEST_SUCCESS);
  59727. ExpectIntEQ(digestSz, 32);
  59728. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  59729. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  59730. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  59731. #endif
  59732. #ifndef WOLFSSL_NOSHA3_384
  59733. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  59734. TEST_SUCCESS);
  59735. ExpectIntEQ(digestSz, 48);
  59736. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  59737. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  59738. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  59739. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  59740. digest, digestSz), 0);
  59741. #endif
  59742. #ifndef WOLFSSL_NOSHA3_512
  59743. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  59744. TEST_SUCCESS);
  59745. ExpectIntEQ(digestSz, 64);
  59746. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  59747. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  59748. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  59749. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  59750. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  59751. digest, digestSz), 0);
  59752. #endif
  59753. #endif
  59754. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  59755. HAVE_FIPS_VERSION <= 2)
  59756. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  59757. TEST_SUCCESS);
  59758. ExpectIntEQ(digestSz, 16);
  59759. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  59760. "\xE4\x98\xDD", digest, digestSz), 0);
  59761. #endif /* !NO_MD5 */
  59762. #endif
  59763. return EXPECT_RESULT();
  59764. }
  59765. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  59766. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  59767. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  59768. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  59769. {
  59770. EXPECT_DECLS;
  59771. static const unsigned char key[] = "simple test key";
  59772. HMAC_CTX* hmac = NULL;
  59773. ENGINE* e = NULL;
  59774. unsigned char hash[WC_MAX_DIGEST_SIZE];
  59775. unsigned int len;
  59776. ExpectNotNull(hmac = HMAC_CTX_new());
  59777. HMAC_CTX_init(hmac);
  59778. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59779. ((! defined(HAVE_FIPS_VERSION)) || \
  59780. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59781. /* Get size on object that hasn't had a digest set - MD5. */
  59782. ExpectIntEQ(HMAC_size(hmac), 16);
  59783. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  59784. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  59785. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  59786. #else
  59787. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59788. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  59789. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  59790. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  59791. #endif
  59792. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  59793. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  59794. /* re-using test key as data to hash */
  59795. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  59796. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  59797. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  59798. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  59799. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  59800. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  59801. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  59802. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  59803. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  59804. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  59805. ExpectIntEQ(len, md_len);
  59806. ExpectIntEQ(HMAC_size(NULL), 0);
  59807. ExpectIntEQ(HMAC_size(hmac), md_len);
  59808. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  59809. HMAC_cleanup(NULL);
  59810. HMAC_cleanup(hmac);
  59811. HMAC_CTX_free(hmac);
  59812. len = 0;
  59813. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  59814. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  59815. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  59816. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  59817. ExpectIntEQ(len, md_len);
  59818. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  59819. /* With data. */
  59820. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  59821. &len));
  59822. /* With NULL data. */
  59823. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  59824. &len));
  59825. /* With zero length data. */
  59826. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  59827. return EXPECT_RESULT();
  59828. }
  59829. #endif
  59830. static int test_wolfSSL_HMAC(void)
  59831. {
  59832. EXPECT_DECLS;
  59833. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  59834. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  59835. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  59836. #ifndef NO_SHA256
  59837. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  59838. TEST_SUCCESS);
  59839. #endif
  59840. #ifdef WOLFSSL_SHA224
  59841. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  59842. TEST_SUCCESS);
  59843. #endif
  59844. #ifdef WOLFSSL_SHA384
  59845. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  59846. TEST_SUCCESS);
  59847. #endif
  59848. #ifdef WOLFSSL_SHA512
  59849. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  59850. TEST_SUCCESS);
  59851. #endif
  59852. #ifdef WOLFSSL_SHA3
  59853. #ifndef WOLFSSL_NOSHA3_224
  59854. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  59855. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  59856. #endif
  59857. #ifndef WOLFSSL_NOSHA3_256
  59858. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  59859. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  59860. #endif
  59861. #ifndef WOLFSSL_NOSHA3_384
  59862. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  59863. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  59864. #endif
  59865. #ifndef WOLFSSL_NOSHA3_512
  59866. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  59867. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  59868. #endif
  59869. #endif
  59870. #ifndef NO_SHA
  59871. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  59872. TEST_SUCCESS);
  59873. #endif
  59874. #endif
  59875. return EXPECT_RESULT();
  59876. }
  59877. static int test_wolfSSL_CMAC(void)
  59878. {
  59879. EXPECT_DECLS;
  59880. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  59881. defined(WOLFSSL_AES_DIRECT)
  59882. int i;
  59883. byte key[AES_256_KEY_SIZE];
  59884. CMAC_CTX* cmacCtx = NULL;
  59885. byte out[AES_BLOCK_SIZE];
  59886. size_t outLen = AES_BLOCK_SIZE;
  59887. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  59888. key[i] = i;
  59889. }
  59890. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59891. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  59892. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  59893. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59894. NULL), 1);
  59895. /* re-using test key as data to hash */
  59896. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59897. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  59898. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  59899. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  59900. /* No Update works. */
  59901. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59902. NULL), 1);
  59903. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59904. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  59905. NULL), 1);
  59906. /* Test parameters with CMAC_Update. */
  59907. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  59908. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  59909. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  59910. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  59911. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  59912. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  59913. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  59914. /* Test parameters with CMAC_Final. */
  59915. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  59916. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  59917. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  59918. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  59919. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  59920. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  59921. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59922. CMAC_CTX_free(cmacCtx);
  59923. /* Test parameters with CMAC Init. */
  59924. cmacCtx = NULL;
  59925. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59926. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  59927. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  59928. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59929. NULL), 0);
  59930. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59931. NULL), 0);
  59932. /* give a key too small for the cipher, verify we get failure */
  59933. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  59934. NULL), 0);
  59935. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  59936. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  59937. /* Only AES-CBC supported. */
  59938. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  59939. NULL), 0);
  59940. #endif
  59941. CMAC_CTX_free(cmacCtx);
  59942. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  59943. cmacCtx = NULL;
  59944. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59945. /* No Init. */
  59946. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  59947. CMAC_CTX_free(cmacCtx);
  59948. /* Test AES-256-CBC */
  59949. cmacCtx = NULL;
  59950. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59951. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  59952. NULL), 1);
  59953. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59954. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59955. CMAC_CTX_free(cmacCtx);
  59956. /* Test AES-192-CBC */
  59957. cmacCtx = NULL;
  59958. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59959. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  59960. NULL), 1);
  59961. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  59962. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  59963. CMAC_CTX_free(cmacCtx);
  59964. cmacCtx = NULL;
  59965. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  59966. CMAC_CTX_free(cmacCtx);
  59967. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  59968. return EXPECT_RESULT();
  59969. }
  59970. static int test_wolfSSL_DES(void)
  59971. {
  59972. EXPECT_DECLS;
  59973. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  59974. const_DES_cblock myDes;
  59975. DES_cblock iv;
  59976. DES_key_schedule key;
  59977. word32 i = 0;
  59978. DES_LONG dl = 0;
  59979. unsigned char msg[] = "hello wolfssl";
  59980. unsigned char weakKey[][8] = {
  59981. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  59982. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  59983. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  59984. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  59985. };
  59986. unsigned char semiWeakKey[][8] = {
  59987. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  59988. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  59989. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  59990. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  59991. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  59992. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  59993. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  59994. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  59995. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  59996. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  59997. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  59998. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  59999. };
  60000. DES_check_key(1);
  60001. DES_set_key(&myDes, &key);
  60002. /* check, check of odd parity */
  60003. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  60004. myDes[0] = 6; /* set even parity */
  60005. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60006. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  60007. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60008. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  60009. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  60010. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  60011. /* set odd parity for success case */
  60012. DES_set_odd_parity(&myDes);
  60013. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  60014. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  60015. myDes[3]);
  60016. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60017. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60018. ExpectIntEQ(key[i], myDes[i]);
  60019. }
  60020. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60021. /* check weak key */
  60022. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  60023. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60024. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  60025. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60026. DES_set_key_unchecked(NULL, NULL);
  60027. DES_set_key_unchecked(&myDes, NULL);
  60028. DES_set_key_unchecked(NULL, &key);
  60029. /* compare arrays, should be the same */
  60030. /* now do unchecked copy of a weak key over */
  60031. DES_set_key_unchecked(&myDes, &key);
  60032. /* compare arrays, should be the same */
  60033. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60034. ExpectIntEQ(key[i], myDes[i]);
  60035. }
  60036. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  60037. myDes[7] = 2;
  60038. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60039. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60040. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  60041. /* Test all weak keys. */
  60042. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  60043. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  60044. }
  60045. /* Test all semi-weak keys. */
  60046. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  60047. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  60048. }
  60049. /* check DES_key_sched API */
  60050. XMEMSET(key, 1, sizeof(DES_key_schedule));
  60051. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  60052. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  60053. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  60054. /* compare arrays, should be the same */
  60055. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60056. ExpectIntEQ(key[i], myDes[i]);
  60057. }
  60058. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  60059. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  60060. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  60061. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  60062. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  60063. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  60064. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  60065. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  60066. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  60067. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  60068. * DES_cbc_encrypt on the input */
  60069. XMEMSET(iv, 0, sizeof(DES_cblock));
  60070. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  60071. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  60072. ExpectIntEQ(dl, 480052723);
  60073. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  60074. return EXPECT_RESULT();
  60075. }
  60076. static int test_wolfSSL_DES_ncbc(void)
  60077. {
  60078. EXPECT_DECLS;
  60079. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60080. const_DES_cblock myDes;
  60081. DES_cblock iv = {1};
  60082. DES_key_schedule key = {0};
  60083. unsigned char msg[] = "hello wolfssl";
  60084. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  60085. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  60086. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  60087. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  60088. /* partial block test */
  60089. DES_set_key(&key, &myDes);
  60090. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  60091. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  60092. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60093. DES_set_key(&key, &myDes);
  60094. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60095. *((byte*)&iv) = 1;
  60096. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  60097. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  60098. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60099. /* full block test */
  60100. DES_set_key(&key, &myDes);
  60101. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  60102. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60103. *((byte*)&iv) = 1;
  60104. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  60105. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  60106. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60107. DES_set_key(&key, &myDes);
  60108. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60109. *((byte*)&iv) = 1;
  60110. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  60111. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  60112. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60113. #endif
  60114. return EXPECT_RESULT();
  60115. }
  60116. static int test_wolfSSL_DES_ecb_encrypt(void)
  60117. {
  60118. EXPECT_DECLS;
  60119. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  60120. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  60121. WOLFSSL_DES_key_schedule key;
  60122. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60123. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  60124. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  60125. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  60126. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  60127. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  60128. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  60129. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  60130. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  60131. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  60132. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  60133. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  60134. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  60135. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  60136. /* Encrypt messages */
  60137. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  60138. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  60139. {
  60140. /* Decrypt messages */
  60141. int ret1 = 0;
  60142. int ret2 = 0;
  60143. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  60144. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  60145. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  60146. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  60147. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  60148. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  60149. }
  60150. #endif
  60151. return EXPECT_RESULT();
  60152. }
  60153. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  60154. {
  60155. EXPECT_DECLS;
  60156. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60157. unsigned char input1[8], input2[8];
  60158. unsigned char output1[8], output2[8];
  60159. unsigned char back1[8], back2[8];
  60160. WOLFSSL_DES_cblock iv1, iv2;
  60161. WOLFSSL_DES_key_schedule key1, key2, key3;
  60162. int i;
  60163. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60164. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  60165. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  60166. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  60167. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  60168. XMEMSET(output1, 0, sizeof(output1));
  60169. XMEMSET(output2, 0, sizeof(output2));
  60170. XMEMSET(back1, 0, sizeof(back1));
  60171. XMEMSET(back2, 0, sizeof(back2));
  60172. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60173. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60174. /* Encrypt messages */
  60175. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  60176. DES_ENCRYPT);
  60177. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  60178. DES_ENCRYPT);
  60179. {
  60180. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60181. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60182. /* Decrypt messages */
  60183. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  60184. &iv1, DES_DECRYPT);
  60185. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  60186. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  60187. &iv2, DES_DECRYPT);
  60188. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  60189. }
  60190. for (i = 0; i < 8; i++) {
  60191. XMEMSET(output1, 0, sizeof(output1));
  60192. XMEMSET(output2, 0, sizeof(output2));
  60193. XMEMSET(back1, 0, sizeof(back1));
  60194. XMEMSET(back2, 0, sizeof(back2));
  60195. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60196. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60197. /* Encrypt partial messages */
  60198. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  60199. &iv1, DES_ENCRYPT);
  60200. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  60201. &iv2, DES_ENCRYPT);
  60202. {
  60203. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60204. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60205. /* Decrypt messages */
  60206. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  60207. &key3, &iv1, DES_DECRYPT);
  60208. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  60209. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  60210. &key3, &iv2, DES_DECRYPT);
  60211. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  60212. }
  60213. }
  60214. #endif
  60215. return EXPECT_RESULT();
  60216. }
  60217. static int test_wolfSSL_AES_encrypt(void)
  60218. {
  60219. EXPECT_DECLS;
  60220. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60221. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60222. AES_KEY enc;
  60223. AES_KEY dec;
  60224. const byte msg[] = {
  60225. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60226. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60227. };
  60228. const byte exp[] = {
  60229. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  60230. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  60231. };
  60232. const byte key[] = {
  60233. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60234. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60235. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60236. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60237. };
  60238. byte eout[sizeof(msg)];
  60239. byte dout[sizeof(msg)];
  60240. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  60241. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  60242. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  60243. wolfSSL_AES_encrypt(msg, NULL, NULL);
  60244. wolfSSL_AES_encrypt(NULL, eout, NULL);
  60245. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  60246. wolfSSL_AES_encrypt(msg, eout, NULL);
  60247. wolfSSL_AES_encrypt(msg, NULL, &enc);
  60248. wolfSSL_AES_encrypt(NULL, eout, &enc);
  60249. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  60250. wolfSSL_AES_decrypt(eout, NULL, NULL);
  60251. wolfSSL_AES_decrypt(NULL, dout, NULL);
  60252. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  60253. wolfSSL_AES_decrypt(eout, dout, NULL);
  60254. wolfSSL_AES_decrypt(eout, NULL, &dec);
  60255. wolfSSL_AES_decrypt(NULL, dout, &dec);
  60256. wolfSSL_AES_encrypt(msg, eout, &enc);
  60257. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  60258. wolfSSL_AES_decrypt(eout, dout, &dec);
  60259. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  60260. #endif
  60261. return EXPECT_RESULT();
  60262. }
  60263. static int test_wolfSSL_AES_ecb_encrypt(void)
  60264. {
  60265. EXPECT_DECLS;
  60266. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60267. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60268. AES_KEY aes;
  60269. const byte msg[] =
  60270. {
  60271. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60272. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  60273. };
  60274. const byte verify[] =
  60275. {
  60276. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  60277. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  60278. };
  60279. const byte key[] =
  60280. {
  60281. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60282. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60283. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60284. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  60285. };
  60286. byte out[AES_BLOCK_SIZE];
  60287. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  60288. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60289. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  60290. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  60291. #ifdef HAVE_AES_DECRYPT
  60292. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  60293. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60294. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  60295. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  60296. #endif
  60297. /* test bad arguments */
  60298. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  60299. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  60300. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  60301. #endif
  60302. return EXPECT_RESULT();
  60303. }
  60304. static int test_wolfSSL_AES_cbc_encrypt(void)
  60305. {
  60306. EXPECT_DECLS;
  60307. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60308. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60309. AES_KEY aes;
  60310. AES_KEY* aesN = NULL;
  60311. size_t len = 0;
  60312. size_t lenB = 0;
  60313. int keySz0 = 0;
  60314. int keySzN = -1;
  60315. byte out[AES_BLOCK_SIZE] = {0};
  60316. byte* outN = NULL;
  60317. /* Test vectors retrieved from:
  60318. * <begin URL>
  60319. * https://csrc.nist.gov/
  60320. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  60321. * documents/aes/KAT_AES.zip
  60322. * </end URL>
  60323. */
  60324. const byte* pt128N = NULL;
  60325. byte* key128N = NULL;
  60326. byte* iv128N = NULL;
  60327. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  60328. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60329. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60330. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  60331. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  60332. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60333. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60334. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  60335. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  60336. len = sizeof(pt128);
  60337. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  60338. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  60339. ExpectIntNE(XMEMCMP(b, g, h), i)
  60340. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  60341. /* Stressing wolfSSL_AES_cbc_encrypt() */
  60342. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60343. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  60344. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  60345. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60346. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  60347. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60348. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60349. /* Stressing wolfSSL_AES_set_encrypt_key */
  60350. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60351. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  60352. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  60353. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  60354. /* Stressing wolfSSL_AES_set_decrypt_key */
  60355. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60356. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  60357. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  60358. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  60359. #ifdef WOLFSSL_AES_128
  60360. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  60361. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60362. RESET_IV(iv128tmp, iv128);
  60363. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60364. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  60365. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60366. wc_AesFree((Aes*)&aes);
  60367. #ifdef HAVE_AES_DECRYPT
  60368. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  60369. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60370. RESET_IV(iv128tmp, iv128);
  60371. len = sizeof(ct128);
  60372. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60373. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  60374. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  60375. wc_AesFree((Aes*)&aes);
  60376. #endif
  60377. #endif /* WOLFSSL_AES_128 */
  60378. #ifdef WOLFSSL_AES_192
  60379. {
  60380. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  60381. * Appendix F.2.3 */
  60382. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  60383. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60384. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60385. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  60386. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  60387. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60388. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60389. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  60390. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  60391. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  60392. len = sizeof(pt192);
  60393. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  60394. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60395. RESET_IV(iv192tmp, iv192);
  60396. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60397. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  60398. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  60399. wc_AesFree((Aes*)&aes);
  60400. #ifdef HAVE_AES_DECRYPT
  60401. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  60402. len = sizeof(ct192);
  60403. RESET_IV(iv192tmp, iv192);
  60404. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60405. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60406. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  60407. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  60408. wc_AesFree((Aes*)&aes);
  60409. #endif
  60410. }
  60411. #endif /* WOLFSSL_AES_192 */
  60412. #ifdef WOLFSSL_AES_256
  60413. {
  60414. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  60415. * Appendix F.2.5 */
  60416. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  60417. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60418. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60419. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  60420. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  60421. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60422. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60423. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60424. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60425. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60426. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  60427. len = sizeof(pt256);
  60428. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  60429. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60430. RESET_IV(iv256tmp, iv256);
  60431. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60432. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  60433. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  60434. wc_AesFree((Aes*)&aes);
  60435. #ifdef HAVE_AES_DECRYPT
  60436. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  60437. len = sizeof(ct256);
  60438. RESET_IV(iv256tmp, iv256);
  60439. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60440. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60441. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  60442. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  60443. wc_AesFree((Aes*)&aes);
  60444. #endif
  60445. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  60446. !defined(HAVE_SELFTEST)
  60447. {
  60448. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  60449. byte wrapPlain[sizeof(key256)] = { 0 };
  60450. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  60451. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  60452. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60453. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60454. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60455. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60456. sizeof(key256)), sizeof(wrapCipher));
  60457. wc_AesFree((Aes*)&aes);
  60458. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  60459. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60460. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60461. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60462. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60463. sizeof(wrapCipher)), sizeof(wrapPlain));
  60464. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60465. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  60466. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  60467. wc_AesFree((Aes*)&aes);
  60468. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  60469. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60470. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  60471. sizeof(key256)), sizeof(wrapCipher));
  60472. wc_AesFree((Aes*)&aes);
  60473. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  60474. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60475. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  60476. sizeof(wrapCipher)), sizeof(wrapPlain));
  60477. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60478. wc_AesFree((Aes*)&aes);
  60479. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60480. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60481. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60482. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  60483. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  60484. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  60485. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  60486. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  60487. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  60488. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60489. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60490. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60491. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  60492. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  60493. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  60494. 0);
  60495. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  60496. 0);
  60497. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  60498. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  60499. }
  60500. #endif /* HAVE_AES_KEYWRAP */
  60501. }
  60502. #endif /* WOLFSSL_AES_256 */
  60503. #endif
  60504. return EXPECT_RESULT();
  60505. }
  60506. static int test_wolfSSL_AES_cfb128_encrypt(void)
  60507. {
  60508. EXPECT_DECLS;
  60509. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  60510. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60511. AES_KEY aesEnc;
  60512. AES_KEY aesDec;
  60513. const byte msg[] = {
  60514. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60515. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60516. };
  60517. const byte exp[] = {
  60518. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  60519. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  60520. };
  60521. const byte key[] = {
  60522. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60523. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60524. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60525. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60526. };
  60527. const byte ivData[] = {
  60528. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60529. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60530. };
  60531. byte out[AES_BLOCK_SIZE];
  60532. byte iv[AES_BLOCK_SIZE];
  60533. word32 i;
  60534. int num;
  60535. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60536. XMEMCPY(iv, ivData, sizeof(iv));
  60537. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60538. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  60539. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  60540. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60541. #ifdef HAVE_AES_DECRYPT
  60542. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60543. XMEMCPY(iv, ivData, sizeof(iv));
  60544. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60545. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  60546. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  60547. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60548. #endif
  60549. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  60550. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60551. XMEMCPY(iv, ivData, sizeof(iv));
  60552. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60553. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  60554. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60555. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  60556. if (i == 0) {
  60557. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60558. }
  60559. else {
  60560. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60561. }
  60562. #ifdef HAVE_AES_DECRYPT
  60563. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60564. XMEMCPY(iv, ivData, sizeof(iv));
  60565. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60566. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  60567. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60568. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  60569. if (i == 0) {
  60570. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60571. }
  60572. else {
  60573. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60574. }
  60575. #endif
  60576. }
  60577. if (EXPECT_SUCCESS()) {
  60578. /* test bad arguments */
  60579. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60580. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60581. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  60582. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60583. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  60584. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60585. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60586. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  60587. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60588. }
  60589. #endif
  60590. return EXPECT_RESULT();
  60591. }
  60592. static int test_wolfSSL_CRYPTO_cts128(void)
  60593. {
  60594. EXPECT_DECLS;
  60595. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60596. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60597. byte tmp[64]; /* Largest vector size */
  60598. /* Test vectors taken form RFC3962 Appendix B */
  60599. const testVector vects[] = {
  60600. {
  60601. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60602. "\x20",
  60603. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  60604. "\x97",
  60605. 17, 17
  60606. },
  60607. {
  60608. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60609. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  60610. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  60611. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  60612. 31, 31
  60613. },
  60614. {
  60615. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60616. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  60617. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60618. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  60619. 32, 32
  60620. },
  60621. {
  60622. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60623. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60624. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  60625. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60626. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  60627. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  60628. 47, 47
  60629. },
  60630. {
  60631. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60632. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60633. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  60634. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60635. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  60636. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  60637. 48, 48
  60638. },
  60639. {
  60640. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60641. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60642. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  60643. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  60644. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60645. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60646. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  60647. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  60648. 64, 64
  60649. }
  60650. };
  60651. byte keyBytes[AES_128_KEY_SIZE] = {
  60652. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  60653. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  60654. };
  60655. size_t i;
  60656. AES_KEY encKey;
  60657. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  60658. XMEMSET(tmp, 0, sizeof(tmp));
  60659. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  60660. AES_KEY decKey;
  60661. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60662. &encKey), 0);
  60663. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60664. &decKey), 0);
  60665. XMEMSET(iv, 0, sizeof(iv));
  60666. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  60667. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  60668. vects[i].outLen);
  60669. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  60670. XMEMSET(iv, 0, sizeof(iv));
  60671. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  60672. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  60673. vects[i].inLen);
  60674. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  60675. }
  60676. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60677. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60678. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60679. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60680. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60681. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  60682. (cbc128_f)AES_cbc_encrypt), 0);
  60683. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  60684. (cbc128_f)AES_cbc_encrypt), 0);
  60685. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  60686. (cbc128_f)AES_cbc_encrypt), 0);
  60687. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  60688. (cbc128_f)AES_cbc_encrypt), 0);
  60689. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  60690. (cbc128_f)AES_cbc_encrypt), 0);
  60691. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60692. /* Length too small. */
  60693. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  60694. (cbc128_f)AES_cbc_encrypt), 0);
  60695. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60696. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60697. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60698. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60699. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60700. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  60701. (cbc128_f)AES_cbc_encrypt), 0);
  60702. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  60703. (cbc128_f)AES_cbc_encrypt), 0);
  60704. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  60705. (cbc128_f)AES_cbc_encrypt), 0);
  60706. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  60707. (cbc128_f)AES_cbc_encrypt), 0);
  60708. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  60709. (cbc128_f)AES_cbc_encrypt), 0);
  60710. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60711. /* Length too small. */
  60712. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  60713. (cbc128_f)AES_cbc_encrypt), 0);
  60714. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  60715. return EXPECT_RESULT();
  60716. }
  60717. static int test_wolfSSL_RC4(void)
  60718. {
  60719. EXPECT_DECLS;
  60720. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  60721. WOLFSSL_RC4_KEY rc4Key;
  60722. unsigned char key[] = {
  60723. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60724. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60725. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60726. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60727. };
  60728. unsigned char data[] = {
  60729. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60730. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60731. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60732. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60733. };
  60734. unsigned char enc[sizeof(data)];
  60735. unsigned char dec[sizeof(data)];
  60736. word32 i;
  60737. word32 j;
  60738. wolfSSL_RC4_set_key(NULL, -1, NULL);
  60739. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  60740. wolfSSL_RC4_set_key(NULL, 0, NULL);
  60741. wolfSSL_RC4_set_key(NULL, -1, key);
  60742. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  60743. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  60744. wolfSSL_RC4_set_key(NULL, 0, key);
  60745. wolfSSL_RC4(NULL, 0, NULL, NULL);
  60746. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  60747. wolfSSL_RC4(NULL, 0, data, NULL);
  60748. wolfSSL_RC4(NULL, 0, NULL, enc);
  60749. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  60750. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  60751. wolfSSL_RC4(NULL, 0, data, enc);
  60752. ExpectIntEQ(1, 1);
  60753. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  60754. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  60755. XMEMSET(enc, 0, sizeof(enc));
  60756. XMEMSET(dec, 0, sizeof(dec));
  60757. /* Encrypt */
  60758. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  60759. wolfSSL_RC4(&rc4Key, j, data, enc);
  60760. /* Decrypt */
  60761. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  60762. wolfSSL_RC4(&rc4Key, j, enc, dec);
  60763. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  60764. }
  60765. }
  60766. #endif
  60767. return EXPECT_RESULT();
  60768. }
  60769. static int test_wolfSSL_OBJ(void)
  60770. {
  60771. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  60772. * mode
  60773. */
  60774. EXPECT_DECLS;
  60775. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  60776. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  60777. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  60778. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  60779. ASN1_OBJECT *obj = NULL;
  60780. ASN1_OBJECT *obj2 = NULL;
  60781. char buf[50];
  60782. XFILE fp = XBADFILE;
  60783. X509 *x509 = NULL;
  60784. X509_NAME *x509Name = NULL;
  60785. X509_NAME_ENTRY *x509NameEntry = NULL;
  60786. ASN1_OBJECT *asn1Name = NULL;
  60787. int numNames = 0;
  60788. BIO *bio = NULL;
  60789. int nid;
  60790. int i, j;
  60791. const char *f[] = {
  60792. #ifndef NO_RSA
  60793. "./certs/ca-cert.der",
  60794. #endif
  60795. #ifdef HAVE_ECC
  60796. "./certs/ca-ecc-cert.der",
  60797. "./certs/ca-ecc384-cert.der",
  60798. #endif
  60799. NULL};
  60800. ASN1_OBJECT *field_name_obj = NULL;
  60801. int lastpos = -1;
  60802. int tmp = -1;
  60803. ASN1_STRING *asn1 = NULL;
  60804. unsigned char *buf_dyn = NULL;
  60805. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60806. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  60807. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  60808. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  60809. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  60810. ASN1_OBJECT_free(obj);
  60811. obj = NULL;
  60812. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  60813. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  60814. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  60815. #ifdef WOLFSSL_CERT_EXT
  60816. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  60817. #endif
  60818. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  60819. ExpectNotNull(obj2 = OBJ_dup(obj));
  60820. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  60821. ASN1_OBJECT_free(obj);
  60822. obj = NULL;
  60823. ASN1_OBJECT_free(obj2);
  60824. obj2 = NULL;
  60825. for (i = 0; f[i] != NULL; i++)
  60826. {
  60827. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  60828. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  60829. if (fp != XBADFILE) {
  60830. XFCLOSE(fp);
  60831. fp = XBADFILE;
  60832. }
  60833. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  60834. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  60835. /* Get the Common Name by using OBJ_txt2obj */
  60836. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  60837. do
  60838. {
  60839. lastpos = tmp;
  60840. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  60841. } while (tmp > -1);
  60842. ExpectIntNE(lastpos, -1);
  60843. ASN1_OBJECT_free(field_name_obj);
  60844. field_name_obj = NULL;
  60845. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  60846. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  60847. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  60848. /*
  60849. * All Common Names should be www.wolfssl.com
  60850. * This makes testing easier as we can test for the expected value.
  60851. */
  60852. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  60853. OPENSSL_free(buf_dyn);
  60854. buf_dyn = NULL;
  60855. bio = BIO_new(BIO_s_mem());
  60856. ExpectTrue(bio != NULL);
  60857. for (j = 0; j < numNames; j++)
  60858. {
  60859. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  60860. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  60861. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  60862. }
  60863. BIO_free(bio);
  60864. bio = NULL;
  60865. X509_free(x509);
  60866. x509 = NULL;
  60867. }
  60868. #ifdef HAVE_PKCS12
  60869. {
  60870. PKCS12 *p12 = NULL;
  60871. int boolRet;
  60872. EVP_PKEY *pkey = NULL;
  60873. const char *p12_f[] = {
  60874. #if !defined(NO_DES3) && !defined(NO_RSA)
  60875. "./certs/test-servercert.p12",
  60876. #endif
  60877. NULL};
  60878. for (i = 0; p12_f[i] != NULL; i++)
  60879. {
  60880. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  60881. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  60882. if (fp != XBADFILE) {
  60883. XFCLOSE(fp);
  60884. fp = XBADFILE;
  60885. }
  60886. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  60887. &pkey, &x509, NULL)) > 0);
  60888. wc_PKCS12_free(p12);
  60889. p12 = NULL;
  60890. EVP_PKEY_free(pkey);
  60891. x509Name = X509_get_issuer_name(x509);
  60892. ExpectNotNull(x509Name);
  60893. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  60894. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  60895. for (j = 0; j < numNames; j++)
  60896. {
  60897. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  60898. ExpectNotNull(asn1Name =
  60899. X509_NAME_ENTRY_get_object(x509NameEntry));
  60900. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  60901. }
  60902. BIO_free(bio);
  60903. bio = NULL;
  60904. X509_free(x509);
  60905. x509 = NULL;
  60906. }
  60907. }
  60908. #endif /* HAVE_PKCS12 */
  60909. #endif
  60910. return EXPECT_RESULT();
  60911. }
  60912. static int test_wolfSSL_OBJ_cmp(void)
  60913. {
  60914. EXPECT_DECLS;
  60915. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  60916. ASN1_OBJECT *obj = NULL;
  60917. ASN1_OBJECT *obj2 = NULL;
  60918. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  60919. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  60920. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60921. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60922. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60923. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  60924. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  60925. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  60926. ASN1_OBJECT_free(obj);
  60927. ASN1_OBJECT_free(obj2);
  60928. #endif
  60929. return EXPECT_RESULT();
  60930. }
  60931. static int test_wolfSSL_OBJ_txt2nid(void)
  60932. {
  60933. EXPECT_DECLS;
  60934. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  60935. defined(WOLFSSL_APACHE_HTTPD)
  60936. int i;
  60937. static const struct {
  60938. const char* sn;
  60939. const char* ln;
  60940. const char* oid;
  60941. int nid;
  60942. } testVals[] = {
  60943. #ifdef WOLFSSL_APACHE_HTTPD
  60944. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  60945. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  60946. NID_id_on_dnsSRV },
  60947. { "msUPN", "Microsoft User Principal Name",
  60948. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  60949. #endif
  60950. { NULL, NULL, NULL, NID_undef }
  60951. };
  60952. /* Invalid cases */
  60953. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  60954. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  60955. /* Valid cases */
  60956. for (i = 0; testVals[i].sn != NULL; i++) {
  60957. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  60958. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  60959. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  60960. }
  60961. #endif
  60962. return EXPECT_RESULT();
  60963. }
  60964. static int test_wolfSSL_OBJ_txt2obj(void)
  60965. {
  60966. EXPECT_DECLS;
  60967. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  60968. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  60969. int i;
  60970. char buf[50];
  60971. ASN1_OBJECT* obj = NULL;
  60972. static const struct {
  60973. const char* oidStr;
  60974. const char* sn;
  60975. const char* ln;
  60976. } objs_list[] = {
  60977. #if defined(WOLFSSL_APACHE_HTTPD)
  60978. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  60979. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  60980. #endif
  60981. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  60982. { NULL, NULL, NULL }
  60983. };
  60984. static const struct {
  60985. const char* numeric;
  60986. const char* name;
  60987. } objs_named[] = {
  60988. /* In dictionary but not in normal list. */
  60989. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  60990. /* Made up OID. */
  60991. { "1.3.5.7", "1.3.5.7" },
  60992. { NULL, NULL }
  60993. };
  60994. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  60995. ASN1_OBJECT_free(obj);
  60996. obj = NULL;
  60997. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  60998. ASN1_OBJECT_free(obj);
  60999. obj = NULL;
  61000. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  61001. /* Test numerical value of oid (oidStr) */
  61002. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  61003. /* Convert object back to text to confirm oid is correct */
  61004. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61005. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61006. ASN1_OBJECT_free(obj);
  61007. obj = NULL;
  61008. XMEMSET(buf, 0, sizeof(buf));
  61009. /* Test short name (sn) */
  61010. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  61011. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  61012. /* Convert object back to text to confirm oid is correct */
  61013. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61014. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61015. ASN1_OBJECT_free(obj);
  61016. obj = NULL;
  61017. XMEMSET(buf, 0, sizeof(buf));
  61018. /* Test long name (ln) - should fail when no_name = 1 */
  61019. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  61020. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  61021. /* Convert object back to text to confirm oid is correct */
  61022. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61023. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61024. ASN1_OBJECT_free(obj);
  61025. obj = NULL;
  61026. XMEMSET(buf, 0, sizeof(buf));
  61027. }
  61028. for (i = 0; objs_named[i].numeric != NULL; i++) {
  61029. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  61030. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  61031. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  61032. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61033. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  61034. ASN1_OBJECT_free(obj);
  61035. obj = NULL;
  61036. }
  61037. #endif
  61038. return EXPECT_RESULT();
  61039. }
  61040. static int test_wolfSSL_PEM_write_bio_X509(void)
  61041. {
  61042. EXPECT_DECLS;
  61043. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  61044. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  61045. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  61046. !defined(NO_FILESYSTEM)
  61047. /* This test contains the hard coded expected
  61048. * lengths. Update if necessary */
  61049. XFILE fp = XBADFILE;
  61050. WOLFSSL_EVP_PKEY *priv = NULL;
  61051. BIO* input = NULL;
  61052. BIO* output = NULL;
  61053. X509* x509a = NULL;
  61054. X509* x509b = NULL;
  61055. ASN1_TIME* notBeforeA = NULL;
  61056. ASN1_TIME* notAfterA = NULL;
  61057. #ifndef NO_ASN_TIME
  61058. ASN1_TIME* notBeforeB = NULL;
  61059. ASN1_TIME* notAfterB = NULL;
  61060. #endif
  61061. int expectedLen;
  61062. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  61063. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  61064. if (fp != XBADFILE) {
  61065. XFCLOSE(fp);
  61066. fp = XBADFILE;
  61067. }
  61068. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  61069. "rb"));
  61070. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  61071. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  61072. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61073. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  61074. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  61075. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  61076. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61077. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61078. /* compare length against expected */
  61079. expectedLen = 2000;
  61080. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61081. #ifndef NO_ASN_TIME
  61082. /* read exported X509 PEM back into struct, sanity check on export,
  61083. * make sure notBefore/notAfter are the same and certs are identical. */
  61084. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61085. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  61086. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  61087. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  61088. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  61089. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61090. X509_free(x509b);
  61091. x509b = NULL;
  61092. #endif
  61093. /* Reset output buffer */
  61094. BIO_free(output);
  61095. output = NULL;
  61096. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61097. /* Test forcing the AKID to be generated just from KeyIdentifier */
  61098. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  61099. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  61100. x509a->authKeyId = x509a->authKeyIdSrc;
  61101. x509a->authKeyIdSrc = NULL;
  61102. x509a->authKeyIdSrcSz = 0;
  61103. }
  61104. /* Resign to re-generate the der */
  61105. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  61106. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61107. /* Check that we generate a smaller output since the AKID will
  61108. * only contain the KeyIdentifier without any additional
  61109. * information */
  61110. /* Here we copy the validity struct from the original */
  61111. expectedLen = 1688;
  61112. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61113. /* Reset buffers and x509 */
  61114. BIO_free(input);
  61115. input = NULL;
  61116. BIO_free(output);
  61117. output = NULL;
  61118. X509_free(x509a);
  61119. x509a = NULL;
  61120. /* test CA and basicConstSet values are encoded when
  61121. * the cert is a CA */
  61122. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  61123. /* read PEM into X509 struct */
  61124. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61125. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61126. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61127. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61128. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  61129. * values are maintained and certs are identical.*/
  61130. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61131. ExpectIntEQ(x509b->isCa, 1);
  61132. ExpectIntEQ(x509b->basicConstSet, 1);
  61133. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61134. X509_free(x509a);
  61135. x509a = NULL;
  61136. X509_free(x509b);
  61137. x509b = NULL;
  61138. BIO_free(input);
  61139. input = NULL;
  61140. BIO_free(output);
  61141. output = NULL;
  61142. /* test CA and basicConstSet values are encoded when
  61143. * the cert is not CA */
  61144. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  61145. /* read PEM into X509 struct */
  61146. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61147. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61148. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61149. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61150. /* read exported X509 PEM back into struct, ensure isCa and
  61151. * basicConstSet values are maintained and certs are identical */
  61152. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61153. ExpectIntEQ(x509b->isCa, 0);
  61154. ExpectIntEQ(x509b->basicConstSet, 1);
  61155. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61156. wolfSSL_EVP_PKEY_free(priv);
  61157. X509_free(x509a);
  61158. X509_free(x509b);
  61159. BIO_free(input);
  61160. BIO_free(output);
  61161. #endif
  61162. return EXPECT_RESULT();
  61163. }
  61164. static int test_wolfSSL_X509_NAME_ENTRY(void)
  61165. {
  61166. EXPECT_DECLS;
  61167. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  61168. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  61169. X509* x509 = NULL;
  61170. #ifndef NO_BIO
  61171. BIO* bio = NULL;
  61172. #endif
  61173. X509_NAME* nm = NULL;
  61174. X509_NAME_ENTRY* entry = NULL;
  61175. unsigned char cn[] = "another name to add";
  61176. #ifdef OPENSSL_ALL
  61177. int i;
  61178. int names_len = 0;
  61179. #endif
  61180. ExpectNotNull(x509 =
  61181. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61182. #ifndef NO_BIO
  61183. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61184. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  61185. #endif
  61186. #ifdef WOLFSSL_CERT_REQ
  61187. {
  61188. X509_REQ* req = NULL;
  61189. #ifndef NO_BIO
  61190. BIO* bReq = NULL;
  61191. #endif
  61192. ExpectNotNull(req =
  61193. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61194. #ifndef NO_BIO
  61195. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  61196. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  61197. BIO_free(bReq);
  61198. #endif
  61199. X509_free(req);
  61200. }
  61201. #endif
  61202. ExpectNotNull(nm = X509_get_subject_name(x509));
  61203. /* Test add entry */
  61204. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  61205. 0x0c, cn, (int)sizeof(cn)));
  61206. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61207. #ifdef WOLFSSL_CERT_EXT
  61208. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  61209. (byte*)"support@wolfssl.com", 19, -1,
  61210. 1), WOLFSSL_SUCCESS);
  61211. #endif
  61212. X509_NAME_ENTRY_free(entry);
  61213. entry = NULL;
  61214. #ifdef WOLFSSL_CERT_REQ
  61215. {
  61216. unsigned char srv_pkcs9p[] = "Server";
  61217. unsigned char fvrtDrnk[] = "tequila";
  61218. unsigned char* der = NULL;
  61219. char* subject = NULL;
  61220. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  61221. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  61222. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  61223. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  61224. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  61225. ExpectNotNull(der);
  61226. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  61227. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  61228. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  61229. #ifdef DEBUG_WOLFSSL
  61230. if (subject != NULL) {
  61231. fprintf(stderr, "\n\t%s\n", subject);
  61232. }
  61233. #endif
  61234. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  61235. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  61236. }
  61237. #endif
  61238. /* Test add entry by text */
  61239. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  61240. 0x0c, cn, (int)sizeof(cn)));
  61241. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  61242. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  61243. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  61244. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  61245. #endif
  61246. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61247. X509_NAME_ENTRY_free(entry);
  61248. entry = NULL;
  61249. /* Test add entry by NID */
  61250. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  61251. cn, -1, -1, 0), SSL_SUCCESS);
  61252. #ifdef OPENSSL_ALL
  61253. /* stack of name entry */
  61254. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  61255. for (i = 0; i < names_len; i++) {
  61256. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  61257. }
  61258. #endif
  61259. #ifndef NO_BIO
  61260. BIO_free(bio);
  61261. #endif
  61262. X509_free(x509); /* free's nm */
  61263. #endif
  61264. return EXPECT_RESULT();
  61265. }
  61266. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61267. static int test_GENERAL_NAME_set0_othername(void) {
  61268. EXPECT_DECLS;
  61269. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61270. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61271. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61272. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61273. defined(WOLFSSL_FPKI)
  61274. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61275. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61276. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61277. const char * cert_fname = "./certs/server-cert.der";
  61278. const char * key_fname = "./certs/server-key.der";
  61279. X509* x509 = NULL;
  61280. GENERAL_NAME* gn = NULL;
  61281. GENERAL_NAMES* gns = NULL;
  61282. ASN1_OBJECT* upn_oid = NULL;
  61283. ASN1_UTF8STRING *utf8str = NULL;
  61284. ASN1_TYPE *value = NULL;
  61285. X509_EXTENSION * ext = NULL;
  61286. byte* pt = NULL;
  61287. byte der[4096];
  61288. int derSz = 0;
  61289. EVP_PKEY* priv = NULL;
  61290. XFILE f = XBADFILE;
  61291. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  61292. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  61293. if (f != XBADFILE) {
  61294. XFCLOSE(f);
  61295. f = XBADFILE;
  61296. }
  61297. ExpectNotNull(gn = GENERAL_NAME_new());
  61298. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61299. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61300. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61301. ExpectNotNull(value = ASN1_TYPE_new());
  61302. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61303. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  61304. wolfSSL_ASN1_STRING_free(utf8str);
  61305. }
  61306. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61307. if (EXPECT_FAIL()) {
  61308. ASN1_TYPE_free(value);
  61309. }
  61310. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61311. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61312. if (EXPECT_FAIL()) {
  61313. GENERAL_NAME_free(gn);
  61314. gn = NULL;
  61315. }
  61316. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61317. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  61318. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61319. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61320. if (f != XBADFILE) {
  61321. XFCLOSE(f);
  61322. f = XBADFILE;
  61323. }
  61324. pt = der;
  61325. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61326. (const unsigned char**)&pt, derSz));
  61327. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  61328. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61329. gns = NULL;
  61330. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61331. NID_subject_alt_name, NULL, NULL));
  61332. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  61333. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  61334. ExpectIntEQ(gn->type, 0);
  61335. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61336. ASN1_OBJECT_free(upn_oid);
  61337. X509_EXTENSION_free(ext);
  61338. X509_free(x509);
  61339. EVP_PKEY_free(priv);
  61340. #endif
  61341. return EXPECT_RESULT();
  61342. }
  61343. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61344. static int test_othername_and_SID_ext(void) {
  61345. EXPECT_DECLS;
  61346. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61347. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61348. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61349. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61350. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  61351. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61352. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61353. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61354. const char* csr_fname = "./certs/csr.signed.der";
  61355. const char* key_fname = "./certs/server-key.der";
  61356. byte der[4096];
  61357. int derSz = 0;
  61358. X509_REQ* x509 = NULL;
  61359. STACK_OF(X509_EXTENSION) *exts = NULL;
  61360. X509_EXTENSION * san_ext = NULL;
  61361. X509_EXTENSION * ext = NULL;
  61362. GENERAL_NAME* gn = NULL;
  61363. GENERAL_NAMES* gns = NULL;
  61364. ASN1_OBJECT* upn_oid = NULL;
  61365. ASN1_UTF8STRING *utf8str = NULL;
  61366. ASN1_TYPE *value = NULL;
  61367. ASN1_STRING *extval = NULL;
  61368. /* SID extension. SID data format explained here:
  61369. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  61370. */
  61371. byte SidExtension[] = {
  61372. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  61373. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  61374. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  61375. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  61376. byte expectedAltName[] = {
  61377. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  61378. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  61379. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  61380. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  61381. X509_EXTENSION *sid_ext = NULL;
  61382. ASN1_OBJECT* sid_oid = NULL;
  61383. ASN1_OCTET_STRING *sid_data = NULL;
  61384. ASN1_OBJECT* alt_names_oid = NULL;
  61385. EVP_PKEY* priv = NULL;
  61386. XFILE f = XBADFILE;
  61387. byte* pt = NULL;
  61388. BIO* bio = NULL;
  61389. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  61390. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  61391. if (f != XBADFILE) {
  61392. XFCLOSE(f);
  61393. f = XBADFILE;
  61394. }
  61395. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  61396. ExpectNotNull(gn = GENERAL_NAME_new());
  61397. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61398. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61399. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61400. ExpectNotNull(value = ASN1_TYPE_new());
  61401. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61402. if (EXPECT_FAIL()) {
  61403. ASN1_UTF8STRING_free(utf8str);
  61404. }
  61405. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61406. if (EXPECT_FAIL()) {
  61407. ASN1_TYPE_free(value);
  61408. GENERAL_NAME_free(gn);
  61409. gn = NULL;
  61410. }
  61411. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61412. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61413. if (EXPECT_FAIL()) {
  61414. GENERAL_NAME_free(gn);
  61415. }
  61416. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61417. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61418. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  61419. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  61420. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  61421. sid_data));
  61422. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  61423. /* Ensure an empty stack doesn't raise an error. */
  61424. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61425. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  61426. if (EXPECT_FAIL()) {
  61427. X509_EXTENSION_free(san_ext);
  61428. }
  61429. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  61430. if (EXPECT_FAIL()) {
  61431. X509_EXTENSION_free(sid_ext);
  61432. }
  61433. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61434. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61435. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61436. if (f != XBADFILE)
  61437. XFCLOSE(f);
  61438. pt = der;
  61439. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61440. (const unsigned char**)&pt, derSz));
  61441. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  61442. pt = der;
  61443. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  61444. X509_REQ_free(x509);
  61445. x509 = NULL;
  61446. pt = der;
  61447. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  61448. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61449. gns = NULL;
  61450. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61451. exts = NULL;
  61452. ASN1_OBJECT_free(upn_oid);
  61453. ASN1_OBJECT_free(sid_oid);
  61454. ASN1_OCTET_STRING_free(sid_data);
  61455. X509_REQ_free(x509);
  61456. EVP_PKEY_free(priv);
  61457. /* At this point everything used to generate what is in der is cleaned up.
  61458. * We now read back from der to confirm the extensions were inserted
  61459. * correctly. */
  61460. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  61461. ExpectNotNull(bio);
  61462. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  61463. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  61464. ExpectNotNull(x509);
  61465. BIO_free(bio);
  61466. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  61467. x509));
  61468. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  61469. /* Check the SID extension. */
  61470. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61471. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61472. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  61473. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61474. ExpectIntEQ(extval->length, sizeof(SidExtension));
  61475. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  61476. ASN1_OBJECT_free(sid_oid);
  61477. /* Check the AltNames extension. */
  61478. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  61479. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61480. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  61481. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61482. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  61483. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  61484. 0);
  61485. ASN1_OBJECT_free(alt_names_oid);
  61486. /* Cleanup */
  61487. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61488. NID_subject_alt_name, NULL, NULL));
  61489. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  61490. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  61491. ExpectIntEQ(gn->type, 0);
  61492. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61493. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61494. X509_REQ_free(x509);
  61495. #endif
  61496. return EXPECT_RESULT();
  61497. }
  61498. static int test_wolfSSL_X509_set_name(void)
  61499. {
  61500. EXPECT_DECLS;
  61501. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61502. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61503. X509* x509 = NULL;
  61504. X509_NAME* name = NULL;
  61505. ExpectNotNull(name = X509_NAME_new());
  61506. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  61507. (byte*)"wolfssl.com", 11, 0, 1),
  61508. WOLFSSL_SUCCESS);
  61509. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  61510. (byte*)"support@wolfssl.com", 19, -1,
  61511. 1), WOLFSSL_SUCCESS);
  61512. ExpectNotNull(x509 = X509_new());
  61513. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61514. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61515. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61516. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  61517. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61518. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61519. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61520. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  61521. X509_free(x509);
  61522. X509_NAME_free(name);
  61523. #endif /* OPENSSL_ALL && !NO_CERTS */
  61524. return EXPECT_RESULT();
  61525. }
  61526. static int test_wolfSSL_X509_set_notAfter(void)
  61527. {
  61528. EXPECT_DECLS;
  61529. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61530. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61531. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61532. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  61533. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  61534. /* Generalized time will overflow time_t if not long */
  61535. X509* x = NULL;
  61536. BIO* bio = NULL;
  61537. ASN1_TIME *asn_time = NULL;
  61538. ASN1_TIME *time_check = NULL;
  61539. const int year = 365*24*60*60;
  61540. const int day = 24*60*60;
  61541. const int hour = 60*60;
  61542. const int mini = 60;
  61543. int offset_day;
  61544. unsigned char buf[25];
  61545. time_t t;
  61546. /*
  61547. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61548. */
  61549. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  61550. offset_day = 7;
  61551. /*
  61552. * Free these.
  61553. */
  61554. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61555. ExpectNotNull(asn_time);
  61556. ExpectNotNull(x = X509_new());
  61557. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61558. /*
  61559. * Tests
  61560. */
  61561. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  61562. /* time_check is simply (ANS1_TIME*)x->notAfter */
  61563. ExpectNotNull(time_check = X509_get_notAfter(x));
  61564. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61565. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61566. /* Convert to human readable format and compare to intended date */
  61567. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61568. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61569. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  61570. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  61571. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  61572. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  61573. /*
  61574. * Cleanup
  61575. */
  61576. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61577. X509_free(x);
  61578. BIO_free(bio);
  61579. #endif
  61580. return EXPECT_RESULT();
  61581. }
  61582. static int test_wolfSSL_X509_set_notBefore(void)
  61583. {
  61584. EXPECT_DECLS;
  61585. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61586. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61587. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61588. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  61589. X509* x = NULL;
  61590. BIO* bio = NULL;
  61591. ASN1_TIME *asn_time = NULL;
  61592. ASN1_TIME *time_check = NULL;
  61593. const int year = 365*24*60*60;
  61594. const int day = 24*60*60;
  61595. const int hour = 60*60;
  61596. const int mini = 60;
  61597. int offset_day;
  61598. unsigned char buf[25];
  61599. time_t t;
  61600. /*
  61601. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61602. */
  61603. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  61604. offset_day = 7;
  61605. /*
  61606. * Free these.
  61607. */
  61608. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61609. ExpectNotNull(asn_time);
  61610. ExpectNotNull(x = X509_new());
  61611. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61612. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  61613. /*
  61614. * Main Tests
  61615. */
  61616. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  61617. /* time_check == (ANS1_TIME*)x->notBefore */
  61618. ExpectNotNull(time_check = X509_get_notBefore(x));
  61619. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61620. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61621. /* Convert to human readable format and compare to intended date */
  61622. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61623. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61624. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  61625. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  61626. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  61627. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  61628. /*
  61629. * Cleanup
  61630. */
  61631. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61632. X509_free(x);
  61633. BIO_free(bio);
  61634. #endif
  61635. return EXPECT_RESULT();
  61636. }
  61637. static int test_wolfSSL_X509_set_version(void)
  61638. {
  61639. EXPECT_DECLS;
  61640. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  61641. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61642. X509* x509 = NULL;
  61643. long v = 2L;
  61644. long maxInt = INT_MAX;
  61645. ExpectNotNull(x509 = X509_new());
  61646. /* These should pass. */
  61647. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  61648. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  61649. /* Fail Case: When v(long) is greater than x509->version(int). */
  61650. v = maxInt+1;
  61651. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  61652. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  61653. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  61654. /* Cleanup */
  61655. X509_free(x509);
  61656. #endif
  61657. return EXPECT_RESULT();
  61658. }
  61659. #ifndef NO_BIO
  61660. static int test_wolfSSL_BIO_gets(void)
  61661. {
  61662. EXPECT_DECLS;
  61663. #if defined(OPENSSL_EXTRA)
  61664. BIO* bio = NULL;
  61665. BIO* bio2 = NULL;
  61666. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  61667. char emp[] = "";
  61668. char bio_buffer[20];
  61669. int bufferSz = 20;
  61670. #ifdef OPENSSL_ALL
  61671. BUF_MEM* emp_bm = NULL;
  61672. BUF_MEM* msg_bm = NULL;
  61673. #endif
  61674. /* try with bad args */
  61675. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  61676. #ifdef OPENSSL_ALL
  61677. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  61678. #endif
  61679. /* try with real msg */
  61680. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61681. XMEMSET(bio_buffer, 0, bufferSz);
  61682. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  61683. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  61684. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  61685. ExpectFalse(bio2 != BIO_next(bio));
  61686. /* make buffer filled with no terminating characters */
  61687. XMEMSET(bio_buffer, 1, bufferSz);
  61688. /* BIO_gets reads a line of data */
  61689. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61690. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61691. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61692. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61693. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61694. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61695. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61696. #ifdef OPENSSL_ALL
  61697. /* test setting the mem_buf manually */
  61698. BIO_free(bio);
  61699. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61700. ExpectNotNull(emp_bm = BUF_MEM_new());
  61701. ExpectNotNull(msg_bm = BUF_MEM_new());
  61702. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  61703. if (EXPECT_SUCCESS()) {
  61704. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61705. msg_bm->data = NULL;
  61706. }
  61707. /* emp size is 1 for terminator */
  61708. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  61709. if (EXPECT_SUCCESS()) {
  61710. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61711. emp_bm->data = emp;
  61712. msg_bm->data = msg;
  61713. }
  61714. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  61715. /* check reading an empty string */
  61716. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61717. ExpectStrEQ(emp, bio_buffer);
  61718. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61719. /* BIO_gets reads a line of data */
  61720. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  61721. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61722. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61723. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61724. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61725. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61726. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61727. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61728. if (EXPECT_SUCCESS())
  61729. emp_bm->data = NULL;
  61730. BUF_MEM_free(emp_bm);
  61731. if (EXPECT_SUCCESS())
  61732. msg_bm->data = NULL;
  61733. BUF_MEM_free(msg_bm);
  61734. #endif
  61735. /* check not null terminated string */
  61736. BIO_free(bio);
  61737. bio = NULL;
  61738. msg[0] = 0x33;
  61739. msg[1] = 0x33;
  61740. msg[2] = 0x33;
  61741. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  61742. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  61743. ExpectIntEQ(bio_buffer[0], msg[0]);
  61744. ExpectIntEQ(bio_buffer[1], msg[1]);
  61745. ExpectIntNE(bio_buffer[2], msg[2]);
  61746. BIO_free(bio);
  61747. bio = NULL;
  61748. msg[3] = 0x33;
  61749. bio_buffer[3] = 0x33;
  61750. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  61751. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  61752. ExpectIntEQ(bio_buffer[0], msg[0]);
  61753. ExpectIntEQ(bio_buffer[1], msg[1]);
  61754. ExpectIntEQ(bio_buffer[2], msg[2]);
  61755. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  61756. /* check reading an empty string */
  61757. BIO_free(bio);
  61758. bio = NULL;
  61759. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  61760. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61761. ExpectStrEQ(emp, bio_buffer);
  61762. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61763. /* check error cases */
  61764. BIO_free(bio);
  61765. bio = NULL;
  61766. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61767. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61768. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  61769. #if !defined(NO_FILESYSTEM)
  61770. {
  61771. BIO* f_bio = NULL;
  61772. XFILE f = XBADFILE;
  61773. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  61774. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  61775. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  61776. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  61777. if (EXPECT_FAIL() && (f != XBADFILE)) {
  61778. XFCLOSE(f);
  61779. }
  61780. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  61781. BIO_free(f_bio);
  61782. f_bio = NULL;
  61783. }
  61784. #endif /* NO_FILESYSTEM */
  61785. BIO_free(bio);
  61786. bio = NULL;
  61787. BIO_free(bio2);
  61788. bio2 = NULL;
  61789. /* try with type BIO */
  61790. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  61791. sizeof(msg));
  61792. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  61793. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  61794. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  61795. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  61796. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  61797. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  61798. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  61799. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61800. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61801. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61802. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61803. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61804. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61805. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61806. BIO_free(bio);
  61807. bio = NULL;
  61808. BIO_free(bio2);
  61809. bio2 = NULL;
  61810. /* check reading an empty string */
  61811. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  61812. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  61813. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61814. ExpectStrEQ(emp, bio_buffer);
  61815. BIO_free(bio);
  61816. bio = NULL;
  61817. #endif
  61818. return EXPECT_RESULT();
  61819. }
  61820. static int test_wolfSSL_BIO_puts(void)
  61821. {
  61822. EXPECT_DECLS;
  61823. #if defined(OPENSSL_EXTRA)
  61824. BIO* bio = NULL;
  61825. char input[] = "hello\0world\n.....ok\n\0";
  61826. char output[128];
  61827. XMEMSET(output, 0, sizeof(output));
  61828. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61829. ExpectIntEQ(BIO_puts(bio, input), 5);
  61830. ExpectIntEQ(BIO_pending(bio), 5);
  61831. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  61832. ExpectIntEQ(BIO_pending(bio), 19);
  61833. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  61834. ExpectStrEQ(output, "helloworld\n");
  61835. ExpectIntEQ(BIO_pending(bio), 8);
  61836. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  61837. ExpectStrEQ(output, ".....ok\n");
  61838. ExpectIntEQ(BIO_pending(bio), 0);
  61839. ExpectIntEQ(BIO_puts(bio, ""), -1);
  61840. BIO_free(bio);
  61841. #endif
  61842. return EXPECT_RESULT();
  61843. }
  61844. static int test_wolfSSL_BIO_dump(void)
  61845. {
  61846. EXPECT_DECLS;
  61847. #if defined(OPENSSL_EXTRA)
  61848. BIO* bio;
  61849. static const unsigned char data[] = {
  61850. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  61851. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  61852. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  61853. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  61854. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  61855. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  61856. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  61857. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  61858. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  61859. 0xB4
  61860. };
  61861. /* Generated with OpenSSL. */
  61862. static const char expected[] =
  61863. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  61864. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  61865. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  61866. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  61867. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  61868. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  61869. static const char expectedAll[] =
  61870. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  61871. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  61872. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  61873. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  61874. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  61875. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  61876. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  61877. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  61878. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  61879. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  61880. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  61881. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  61882. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  61883. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  61884. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  61885. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  61886. char output[16 * 80];
  61887. int i;
  61888. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61889. /* Example key dumped. */
  61890. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  61891. sizeof(expected) - 1);
  61892. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  61893. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  61894. /* Try every possible value for a character. */
  61895. for (i = 0; i < 256; i++)
  61896. output[i] = i;
  61897. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  61898. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  61899. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  61900. BIO_free(bio);
  61901. #endif
  61902. return EXPECT_RESULT();
  61903. }
  61904. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  61905. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  61906. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  61907. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  61908. {
  61909. (void)ssl;
  61910. (void)buf;
  61911. (void)sz;
  61912. (void)ctx;
  61913. return WOLFSSL_CBIO_ERR_WANT_READ;
  61914. }
  61915. #endif
  61916. static int test_wolfSSL_BIO_should_retry(void)
  61917. {
  61918. EXPECT_DECLS;
  61919. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  61920. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  61921. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  61922. tcp_ready ready;
  61923. func_args server_args;
  61924. THREAD_TYPE serverThread;
  61925. SOCKET_T sockfd = 0;
  61926. WOLFSSL_CTX* ctx = NULL;
  61927. WOLFSSL* ssl = NULL;
  61928. char msg[64] = "hello wolfssl!";
  61929. char reply[1024];
  61930. int msgSz = (int)XSTRLEN(msg);
  61931. int ret;
  61932. BIO* bio = NULL;
  61933. XMEMSET(&server_args, 0, sizeof(func_args));
  61934. #ifdef WOLFSSL_TIRTOS
  61935. fdOpenSession(Task_self());
  61936. #endif
  61937. StartTCP();
  61938. InitTcpReady(&ready);
  61939. #if defined(USE_WINDOWS_API)
  61940. /* use RNG to get random port if using windows */
  61941. ready.port = GetRandomPort();
  61942. #endif
  61943. server_args.signal = &ready;
  61944. start_thread(test_server_nofail, &server_args, &serverThread);
  61945. wait_tcp_ready(&server_args);
  61946. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  61947. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  61948. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  61949. #endif
  61950. ExpectIntEQ(WOLFSSL_SUCCESS,
  61951. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  61952. ExpectIntEQ(WOLFSSL_SUCCESS,
  61953. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  61954. ExpectIntEQ(WOLFSSL_SUCCESS,
  61955. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  61956. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  61957. /* force retry */
  61958. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  61959. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  61960. ExpectNotNull(ssl);
  61961. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  61962. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  61963. if (EXPECT_FAIL()) {
  61964. wolfSSL_free(ssl);
  61965. ssl = NULL;
  61966. }
  61967. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  61968. ExpectIntNE(BIO_should_retry(bio), 0);
  61969. ExpectIntEQ(BIO_should_read(bio), 0);
  61970. ExpectIntEQ(BIO_should_write(bio), 0);
  61971. /* now perform successful connection */
  61972. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  61973. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  61974. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  61975. ret = wolfSSL_get_error(ssl, -1);
  61976. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  61977. ExpectIntNE(BIO_should_retry(bio), 0);
  61978. if (ret == WOLFSSL_ERROR_WANT_READ)
  61979. ExpectIntEQ(BIO_should_read(bio), 1);
  61980. else
  61981. ExpectIntEQ(BIO_should_read(bio), 0);
  61982. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  61983. ExpectIntEQ(BIO_should_write(bio), 1);
  61984. else
  61985. ExpectIntEQ(BIO_should_write(bio), 0);
  61986. }
  61987. else {
  61988. ExpectIntEQ(BIO_should_retry(bio), 0);
  61989. ExpectIntEQ(BIO_should_read(bio), 0);
  61990. ExpectIntEQ(BIO_should_write(bio), 0);
  61991. }
  61992. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  61993. XSTRLEN("I hear you fa shizzle!")), 0);
  61994. BIO_free(bio);
  61995. wolfSSL_CTX_free(ctx);
  61996. CloseSocket(sockfd);
  61997. join_thread(serverThread);
  61998. FreeTcpReady(&ready);
  61999. #ifdef WOLFSSL_TIRTOS
  62000. fdOpenSession(Task_self());
  62001. #endif
  62002. #endif
  62003. return EXPECT_RESULT();
  62004. }
  62005. static int test_wolfSSL_BIO_connect(void)
  62006. {
  62007. EXPECT_DECLS;
  62008. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62009. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  62010. tcp_ready ready;
  62011. func_args server_args;
  62012. THREAD_TYPE serverThread;
  62013. BIO *tcpBio = NULL;
  62014. BIO *sslBio = NULL;
  62015. SSL_CTX* ctx = NULL;
  62016. SSL *ssl = NULL;
  62017. SSL *sslPtr;
  62018. char msg[] = "hello wolfssl!";
  62019. char reply[30];
  62020. char buff[10] = {0};
  62021. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62022. ExpectIntEQ(WOLFSSL_SUCCESS,
  62023. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  62024. ExpectIntEQ(WOLFSSL_SUCCESS,
  62025. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  62026. ExpectIntEQ(WOLFSSL_SUCCESS,
  62027. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  62028. /* Setup server */
  62029. XMEMSET(&server_args, 0, sizeof(func_args));
  62030. StartTCP();
  62031. InitTcpReady(&ready);
  62032. #if defined(USE_WINDOWS_API)
  62033. /* use RNG to get random port if using windows */
  62034. ready.port = GetRandomPort();
  62035. #endif
  62036. server_args.signal = &ready;
  62037. start_thread(test_server_nofail, &server_args, &serverThread);
  62038. wait_tcp_ready(&server_args);
  62039. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62040. /* Start the test proper */
  62041. /* Setup the TCP BIO */
  62042. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  62043. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  62044. /* Setup the SSL object */
  62045. ExpectNotNull(ssl = SSL_new(ctx));
  62046. SSL_set_connect_state(ssl);
  62047. /* Setup the SSL BIO */
  62048. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  62049. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  62050. if (EXPECT_FAIL()) {
  62051. wolfSSL_free(ssl);
  62052. }
  62053. /* Verify that BIO_get_ssl works. */
  62054. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  62055. ExpectPtrEq(ssl, sslPtr);
  62056. /* Link BIO's so that sslBio uses tcpBio for IO */
  62057. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  62058. /* Do TCP connect */
  62059. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62060. /* Do TLS handshake */
  62061. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62062. /* Test writing */
  62063. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62064. /* Expect length of default wolfSSL reply */
  62065. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62066. /* Clean it all up */
  62067. BIO_free_all(sslBio);
  62068. /* Server clean up */
  62069. join_thread(serverThread);
  62070. FreeTcpReady(&ready);
  62071. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  62072. * after. */
  62073. XMEMSET(&server_args, 0, sizeof(func_args));
  62074. StartTCP();
  62075. InitTcpReady(&ready);
  62076. #if defined(USE_WINDOWS_API)
  62077. /* use RNG to get random port if using windows */
  62078. ready.port = GetRandomPort();
  62079. #endif
  62080. server_args.signal = &ready;
  62081. start_thread(test_server_nofail, &server_args, &serverThread);
  62082. wait_tcp_ready(&server_args);
  62083. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62084. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  62085. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  62086. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  62087. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62088. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62089. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62090. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62091. /* Attempt to close the TLS connection gracefully. */
  62092. BIO_ssl_shutdown(sslBio);
  62093. BIO_free_all(sslBio);
  62094. join_thread(serverThread);
  62095. FreeTcpReady(&ready);
  62096. SSL_CTX_free(ctx);
  62097. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62098. wc_ecc_fp_free(); /* free per thread cache */
  62099. #endif
  62100. #endif
  62101. return EXPECT_RESULT();
  62102. }
  62103. static int test_wolfSSL_BIO_tls(void)
  62104. {
  62105. EXPECT_DECLS;
  62106. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  62107. SSL_CTX* ctx = NULL;
  62108. SSL *ssl = NULL;
  62109. BIO *readBio = NULL;
  62110. BIO *writeBio = NULL;
  62111. int ret;
  62112. int err = 0;
  62113. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62114. ExpectNotNull(ssl = SSL_new(ctx));
  62115. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  62116. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  62117. /* Qt reads data from write-bio,
  62118. * then writes the read data into plain packet.
  62119. * Qt reads data from plain packet,
  62120. * then writes the read data into read-bio.
  62121. */
  62122. SSL_set_bio(ssl, readBio, writeBio);
  62123. do {
  62124. #ifdef WOLFSSL_ASYNC_CRYPT
  62125. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62126. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62127. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62128. }
  62129. #endif
  62130. ret = SSL_connect(ssl);
  62131. err = SSL_get_error(ssl, 0);
  62132. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62133. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62134. /* in this use case, should return WANT READ
  62135. * so that Qt will read the data from plain packet for next state.
  62136. */
  62137. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  62138. SSL_free(ssl);
  62139. SSL_CTX_free(ctx);
  62140. #endif
  62141. return EXPECT_RESULT();
  62142. }
  62143. static int test_wolfSSL_BIO_datagram(void)
  62144. {
  62145. EXPECT_DECLS;
  62146. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  62147. int ret;
  62148. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  62149. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  62150. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  62151. SOCKADDR_IN sin1, sin2;
  62152. socklen_t slen;
  62153. static const char test_msg[] = "I am a datagram, short and stout.";
  62154. char test_msg_recvd[sizeof(test_msg) + 10];
  62155. #ifdef USE_WINDOWS_API
  62156. static const DWORD timeout = 250; /* ms */
  62157. #else
  62158. static const struct timeval timeout = { 0, 250000 };
  62159. #endif
  62160. StartTCP();
  62161. if (EXPECT_SUCCESS()) {
  62162. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62163. ExpectIntNE(fd1, SOCKET_INVALID);
  62164. }
  62165. if (EXPECT_SUCCESS()) {
  62166. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62167. ExpectIntNE(fd2, SOCKET_INVALID);
  62168. }
  62169. if (EXPECT_SUCCESS()) {
  62170. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  62171. ExpectNotNull(bio1);
  62172. }
  62173. if (EXPECT_SUCCESS()) {
  62174. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  62175. ExpectNotNull(bio2);
  62176. }
  62177. if (EXPECT_SUCCESS()) {
  62178. sin1.sin_family = AF_INET;
  62179. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62180. sin1.sin_port = 0;
  62181. slen = (socklen_t)sizeof(sin1);
  62182. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  62183. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62184. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  62185. }
  62186. if (EXPECT_SUCCESS()) {
  62187. sin2.sin_family = AF_INET;
  62188. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62189. sin2.sin_port = 0;
  62190. slen = (socklen_t)sizeof(sin2);
  62191. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  62192. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62193. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  62194. }
  62195. if (EXPECT_SUCCESS()) {
  62196. bio_addr1 = wolfSSL_BIO_ADDR_new();
  62197. ExpectNotNull(bio_addr1);
  62198. }
  62199. if (EXPECT_SUCCESS()) {
  62200. bio_addr2 = wolfSSL_BIO_ADDR_new();
  62201. ExpectNotNull(bio_addr2);
  62202. }
  62203. if (EXPECT_SUCCESS()) {
  62204. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  62205. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62206. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62207. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62208. }
  62209. test_msg_recvd[0] = 0;
  62210. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62211. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62212. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62213. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  62214. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  62215. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  62216. #endif
  62217. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  62218. * BIOs aren't "connected" yet. use it to send a reply.
  62219. */
  62220. test_msg_recvd[0] = 0;
  62221. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62222. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62223. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62224. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62225. ExpectIntNE(BIO_should_retry(bio1), 0);
  62226. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62227. ExpectIntNE(BIO_should_retry(bio2), 0);
  62228. /* now "connect" the sockets. */
  62229. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  62230. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62231. if (EXPECT_SUCCESS()) {
  62232. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62233. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  62234. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62235. }
  62236. if (EXPECT_SUCCESS()) {
  62237. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  62238. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  62239. wolfSSL_BIO_ADDR_clear(bio_addr1);
  62240. }
  62241. test_msg_recvd[0] = 0;
  62242. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62243. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62244. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62245. test_msg_recvd[0] = 0;
  62246. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62247. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62248. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62249. #ifdef __linux__
  62250. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  62251. sin1.sin_family = AF_UNSPEC;
  62252. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62253. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62254. sin1.sin_family = AF_INET;
  62255. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62256. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62257. if (EXPECT_SUCCESS()) {
  62258. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  62259. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62260. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62261. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62262. }
  62263. test_msg_recvd[0] = 0;
  62264. errno = 0;
  62265. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  62266. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  62267. #endif /* __linux__ */
  62268. if (bio1) {
  62269. ret = wolfSSL_BIO_free(bio1);
  62270. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62271. } else if (fd1 != SOCKET_INVALID)
  62272. CloseSocket(fd1);
  62273. if (bio2) {
  62274. ret = wolfSSL_BIO_free(bio2);
  62275. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62276. } else if (fd2 != SOCKET_INVALID)
  62277. CloseSocket(fd2);
  62278. if (bio_addr1)
  62279. wolfSSL_BIO_ADDR_free(bio_addr1);
  62280. if (bio_addr2)
  62281. wolfSSL_BIO_ADDR_free(bio_addr2);
  62282. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  62283. return EXPECT_RESULT();
  62284. }
  62285. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62286. defined(HAVE_HTTP_CLIENT)
  62287. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  62288. {
  62289. BIO* clientBio;
  62290. SSL* sslClient;
  62291. SSL_CTX* ctx;
  62292. char connectAddr[20]; /* IP + port */;
  62293. (void)args;
  62294. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  62295. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  62296. AssertIntEQ(BIO_do_connect(clientBio), 1);
  62297. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62298. AssertNotNull(sslClient = SSL_new(ctx));
  62299. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  62300. SSL_set_bio(sslClient, clientBio, clientBio);
  62301. AssertIntEQ(SSL_connect(sslClient), 1);
  62302. SSL_free(sslClient);
  62303. SSL_CTX_free(ctx);
  62304. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62305. wc_ecc_fp_free(); /* free per thread cache */
  62306. #endif
  62307. WOLFSSL_RETURN_FROM_THREAD(0);
  62308. }
  62309. #endif
  62310. static int test_wolfSSL_BIO_accept(void)
  62311. {
  62312. EXPECT_DECLS;
  62313. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62314. defined(HAVE_HTTP_CLIENT)
  62315. BIO* serverBindBio = NULL;
  62316. BIO* serverAcceptBio = NULL;
  62317. SSL* sslServer = NULL;
  62318. SSL_CTX* ctx = NULL;
  62319. func_args args;
  62320. THREAD_TYPE thread;
  62321. char port[10]; /* 10 bytes should be enough to store the string
  62322. * representation of the port */
  62323. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  62324. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  62325. /* First BIO_do_accept binds the port */
  62326. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62327. XMEMSET(&args, 0, sizeof(func_args));
  62328. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  62329. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62330. /* Let's plug it into SSL to test */
  62331. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62332. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  62333. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62334. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  62335. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62336. ExpectNotNull(sslServer = SSL_new(ctx));
  62337. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  62338. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  62339. ExpectIntEQ(SSL_accept(sslServer), 1);
  62340. join_thread(thread);
  62341. BIO_free(serverBindBio);
  62342. SSL_free(sslServer);
  62343. SSL_CTX_free(ctx);
  62344. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62345. wc_ecc_fp_free(); /* free per thread cache */
  62346. #endif
  62347. #endif
  62348. return EXPECT_RESULT();
  62349. }
  62350. static int test_wolfSSL_BIO_write(void)
  62351. {
  62352. EXPECT_DECLS;
  62353. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  62354. BIO* bio = NULL;
  62355. BIO* bio64 = NULL;
  62356. BIO* bio_mem = NULL;
  62357. BIO* ptr = NULL;
  62358. int sz;
  62359. char msg[] = "conversion test";
  62360. char out[40];
  62361. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  62362. void* bufPtr = NULL;
  62363. BUF_MEM* buf = NULL;
  62364. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62365. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  62366. if (EXPECT_FAIL()) {
  62367. BIO_free(bio64);
  62368. }
  62369. /* now should convert to base64 then write to memory */
  62370. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62371. BIO_flush(bio);
  62372. /* test BIO chain */
  62373. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  62374. ExpectNotNull(buf);
  62375. ExpectIntEQ(buf->length, 25);
  62376. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  62377. ExpectPtrEq(buf->data, bufPtr);
  62378. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  62379. sz = sizeof(out);
  62380. XMEMSET(out, 0, sz);
  62381. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  62382. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62383. /* write then read should return the same message */
  62384. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62385. sz = sizeof(out);
  62386. XMEMSET(out, 0, sz);
  62387. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  62388. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62389. /* now try encoding with no line ending */
  62390. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  62391. #ifdef HAVE_EX_DATA
  62392. BIO_set_ex_data(bio64, 0, (void*) "data");
  62393. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  62394. #endif
  62395. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62396. BIO_flush(bio);
  62397. sz = sizeof(out);
  62398. XMEMSET(out, 0, sz);
  62399. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  62400. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62401. BIO_free_all(bio); /* frees bio64 also */
  62402. bio = NULL;
  62403. /* test with more than one bio64 in list */
  62404. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62405. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  62406. if (EXPECT_FAIL()) {
  62407. BIO_free(bio64);
  62408. bio64 = NULL;
  62409. }
  62410. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  62411. ExpectNotNull(BIO_push(bio64, bio_mem));
  62412. if (EXPECT_FAIL()) {
  62413. BIO_free(bio_mem);
  62414. }
  62415. /* now should convert to base64 when stored and then decode with read */
  62416. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  62417. BIO_flush(bio);
  62418. sz = sizeof(out);
  62419. XMEMSET(out, 0, sz);
  62420. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  62421. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  62422. BIO_clear_flags(bio64, ~0);
  62423. BIO_set_retry_read(bio);
  62424. BIO_free_all(bio); /* frees bio64s also */
  62425. bio = NULL;
  62426. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  62427. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62428. BIO_free(bio);
  62429. #endif
  62430. return EXPECT_RESULT();
  62431. }
  62432. static int test_wolfSSL_BIO_printf(void)
  62433. {
  62434. EXPECT_DECLS;
  62435. #if defined(OPENSSL_ALL)
  62436. BIO* bio = NULL;
  62437. int sz = 7;
  62438. char msg[] = "TLS 1.3 for the world";
  62439. char out[60];
  62440. char expected[] = "TLS 1.3 for the world : sz = 7";
  62441. XMEMSET(out, 0, sizeof(out));
  62442. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62443. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  62444. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62445. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  62446. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  62447. BIO_free(bio);
  62448. #endif
  62449. return EXPECT_RESULT();
  62450. }
  62451. static int test_wolfSSL_BIO_f_md(void)
  62452. {
  62453. EXPECT_DECLS;
  62454. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  62455. BIO* bio = NULL;
  62456. BIO* mem = NULL;
  62457. char msg[] = "message to hash";
  62458. char out[60];
  62459. EVP_MD_CTX* ctx = NULL;
  62460. const unsigned char testKey[] =
  62461. {
  62462. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62463. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62464. 0x0b, 0x0b, 0x0b, 0x0b
  62465. };
  62466. const char testData[] = "Hi There";
  62467. const unsigned char testResult[] =
  62468. {
  62469. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  62470. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  62471. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  62472. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  62473. };
  62474. const unsigned char expectedHash[] =
  62475. {
  62476. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  62477. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  62478. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  62479. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  62480. };
  62481. const unsigned char emptyHash[] =
  62482. {
  62483. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  62484. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  62485. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  62486. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  62487. };
  62488. unsigned char check[sizeof(testResult) + 1];
  62489. size_t checkSz = -1;
  62490. EVP_PKEY* key = NULL;
  62491. XMEMSET(out, 0, sizeof(out));
  62492. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62493. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62494. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  62495. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  62496. /* should not be able to write/read yet since just digest wrapper and no
  62497. * data is passing through the bio */
  62498. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  62499. ExpectIntEQ(BIO_pending(bio), 0);
  62500. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  62501. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  62502. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62503. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  62504. BIO_reset(bio);
  62505. /* append BIO mem to bio in order to read/write */
  62506. ExpectNotNull(bio = BIO_push(bio, mem));
  62507. XMEMSET(out, 0, sizeof(out));
  62508. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  62509. ExpectIntEQ(BIO_pending(bio), 16);
  62510. /* this just reads the message and does not hash it (gets calls final) */
  62511. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  62512. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62513. /* create a message digest using BIO */
  62514. XMEMSET(out, 0, sizeof(out));
  62515. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  62516. ExpectIntEQ(BIO_pending(mem), 16);
  62517. ExpectIntEQ(BIO_pending(bio), 16);
  62518. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62519. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  62520. BIO_free(bio);
  62521. bio = NULL;
  62522. BIO_free(mem);
  62523. mem = NULL;
  62524. /* test with HMAC */
  62525. XMEMSET(out, 0, sizeof(out));
  62526. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62527. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62528. BIO_get_md_ctx(bio, &ctx);
  62529. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  62530. (int)sizeof(testKey)));
  62531. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  62532. ExpectNotNull(bio = BIO_push(bio, mem));
  62533. BIO_write(bio, testData, (int)strlen(testData));
  62534. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  62535. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  62536. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  62537. EVP_PKEY_free(key);
  62538. BIO_free(bio);
  62539. BIO_free(mem);
  62540. #endif
  62541. return EXPECT_RESULT();
  62542. }
  62543. static int test_wolfSSL_BIO_up_ref(void)
  62544. {
  62545. EXPECT_DECLS;
  62546. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62547. BIO* bio = NULL;
  62548. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62549. ExpectIntEQ(BIO_up_ref(NULL), 0);
  62550. ExpectIntEQ(BIO_up_ref(bio), 1);
  62551. BIO_free(bio);
  62552. ExpectIntEQ(BIO_up_ref(bio), 1);
  62553. BIO_free(bio);
  62554. BIO_free(bio);
  62555. #endif
  62556. return EXPECT_RESULT();
  62557. }
  62558. static int test_wolfSSL_BIO_reset(void)
  62559. {
  62560. EXPECT_DECLS;
  62561. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62562. BIO* bio = NULL;
  62563. byte buf[16];
  62564. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  62565. (word32)XSTRLEN("secure your data")));
  62566. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  62567. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  62568. XMEMSET(buf, 0, 16);
  62569. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  62570. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  62571. /* You cannot write to MEM BIO with read-only mode. */
  62572. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  62573. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  62574. XMEMSET(buf, 0, 16);
  62575. ExpectIntEQ(BIO_reset(bio), 1);
  62576. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  62577. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  62578. BIO_free(bio);
  62579. #endif
  62580. return EXPECT_RESULT();
  62581. }
  62582. #endif /* !NO_BIO */
  62583. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62584. /* test that the callback arg is correct */
  62585. static int certCbArg = 0;
  62586. static int certCb(WOLFSSL* ssl, void* arg)
  62587. {
  62588. if (ssl == NULL || arg != &certCbArg)
  62589. return 0;
  62590. if (wolfSSL_is_server(ssl)) {
  62591. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  62592. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62593. return 0;
  62594. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  62595. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62596. return 0;
  62597. }
  62598. else {
  62599. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  62600. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62601. return 0;
  62602. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  62603. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62604. return 0;
  62605. }
  62606. return 1;
  62607. }
  62608. static int certSetupCb(WOLFSSL_CTX* ctx)
  62609. {
  62610. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  62611. return TEST_SUCCESS;
  62612. }
  62613. /**
  62614. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  62615. * to stop certificate and key loading
  62616. */
  62617. static int certClearCb(WOLFSSL* ssl)
  62618. {
  62619. /* Clear the loaded certs to force the callbacks to set them up */
  62620. SSL_certs_clear(ssl);
  62621. return TEST_SUCCESS;
  62622. }
  62623. #endif
  62624. static int test_wolfSSL_cert_cb(void)
  62625. {
  62626. EXPECT_DECLS;
  62627. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62628. test_ssl_cbf func_cb_client;
  62629. test_ssl_cbf func_cb_server;
  62630. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62631. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62632. func_cb_client.ctx_ready = certSetupCb;
  62633. func_cb_client.ssl_ready = certClearCb;
  62634. func_cb_server.ctx_ready = certSetupCb;
  62635. func_cb_server.ssl_ready = certClearCb;
  62636. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62637. &func_cb_server, NULL), TEST_SUCCESS);
  62638. #endif
  62639. return EXPECT_RESULT();
  62640. }
  62641. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62642. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  62643. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  62644. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  62645. {
  62646. EXPECT_DECLS;
  62647. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  62648. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  62649. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  62650. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  62651. return EXPECT_RESULT();
  62652. }
  62653. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  62654. {
  62655. const byte* suites = NULL;
  62656. word16 suiteSz = 0;
  62657. const byte* hashSigAlgo = NULL;
  62658. word16 hashSigAlgoSz = 0;
  62659. word16 idx = 0;
  62660. int haveRSA = 0;
  62661. int haveECC = 0;
  62662. (void)arg;
  62663. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  62664. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  62665. return 0;
  62666. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  62667. hashSigAlgoSz == 0)
  62668. return 0;
  62669. for (idx = 0; idx < suiteSz; idx += 2) {
  62670. WOLFSSL_CIPHERSUITE_INFO info =
  62671. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  62672. if (info.rsaAuth)
  62673. haveRSA = 1;
  62674. else if (info.eccAuth)
  62675. haveECC = 1;
  62676. }
  62677. if (hashSigAlgoSz > 0) {
  62678. /* sigalgs extension takes precedence over ciphersuites */
  62679. haveRSA = 0;
  62680. haveECC = 0;
  62681. }
  62682. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  62683. int hashAlgo = 0;
  62684. int sigAlgo = 0;
  62685. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  62686. &hashAlgo, &sigAlgo) != 0)
  62687. return 0;
  62688. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  62689. haveRSA = 1;
  62690. else if (sigAlgo == ECDSAk)
  62691. haveECC = 1;
  62692. }
  62693. if (haveRSA) {
  62694. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  62695. != WOLFSSL_SUCCESS)
  62696. return 0;
  62697. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  62698. != WOLFSSL_SUCCESS)
  62699. return 0;
  62700. }
  62701. else if (haveECC) {
  62702. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  62703. != WOLFSSL_SUCCESS)
  62704. return 0;
  62705. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  62706. != WOLFSSL_SUCCESS)
  62707. return 0;
  62708. }
  62709. return 1;
  62710. }
  62711. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  62712. {
  62713. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  62714. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  62715. return TEST_SUCCESS;
  62716. }
  62717. #endif
  62718. /* Testing dynamic ciphers offered by client */
  62719. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  62720. {
  62721. EXPECT_DECLS;
  62722. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62723. test_ssl_cbf func_cb_client;
  62724. test_ssl_cbf func_cb_server;
  62725. struct {
  62726. method_provider client_meth;
  62727. const char* client_ciphers;
  62728. const char* client_sigalgs;
  62729. const char* client_ca;
  62730. method_provider server_meth;
  62731. } test_params[] = {
  62732. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  62733. #ifdef WOLFSSL_TLS13
  62734. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  62735. {wolfTLSv1_3_client_method,
  62736. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62737. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  62738. #endif
  62739. #ifdef HAVE_ECC
  62740. {wolfTLSv1_3_client_method,
  62741. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62742. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  62743. #endif
  62744. #endif
  62745. #ifndef WOLFSSL_NO_TLS12
  62746. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  62747. {wolfTLSv1_2_client_method,
  62748. "DHE-RSA-AES128-GCM-SHA256",
  62749. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  62750. #endif
  62751. #ifdef HAVE_ECC
  62752. {wolfTLSv1_2_client_method,
  62753. "ECDHE-ECDSA-AES128-GCM-SHA256",
  62754. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  62755. #endif
  62756. #endif
  62757. #endif
  62758. };
  62759. size_t i;
  62760. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  62761. if (testCount > 0) {
  62762. for (i = 0; i < testCount; i++) {
  62763. printf("\tTesting %s ciphers with %s sigalgs\n",
  62764. test_params[i].client_ciphers,
  62765. test_params[i].client_sigalgs);
  62766. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62767. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62768. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  62769. test_params[i].client_ciphers;
  62770. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  62771. test_params[i].client_sigalgs;
  62772. func_cb_client.method = test_params[i].client_meth;
  62773. func_cb_client.caPemFile = test_params[i].client_ca;
  62774. func_cb_client.ctx_ready =
  62775. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  62776. func_cb_server.ctx_ready =
  62777. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  62778. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  62779. func_cb_server.method = test_params[i].server_meth;
  62780. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62781. &func_cb_server, NULL), TEST_SUCCESS);
  62782. }
  62783. }
  62784. #endif
  62785. return EXPECT_RESULT();
  62786. }
  62787. static int test_wolfSSL_ciphersuite_auth(void)
  62788. {
  62789. EXPECT_DECLS;
  62790. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  62791. WOLFSSL_CIPHERSUITE_INFO info;
  62792. (void)info;
  62793. #ifndef WOLFSSL_NO_TLS12
  62794. #ifdef HAVE_CHACHA
  62795. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62796. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  62797. ExpectIntEQ(info.rsaAuth, 1);
  62798. ExpectIntEQ(info.eccAuth, 0);
  62799. ExpectIntEQ(info.eccStatic, 0);
  62800. ExpectIntEQ(info.psk, 0);
  62801. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62802. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  62803. ExpectIntEQ(info.rsaAuth, 0);
  62804. ExpectIntEQ(info.eccAuth, 1);
  62805. ExpectIntEQ(info.eccStatic, 0);
  62806. ExpectIntEQ(info.psk, 0);
  62807. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  62808. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  62809. ExpectIntEQ(info.rsaAuth, 0);
  62810. ExpectIntEQ(info.eccAuth, 0);
  62811. ExpectIntEQ(info.eccStatic, 0);
  62812. ExpectIntEQ(info.psk, 1);
  62813. #endif
  62814. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  62815. #ifndef NO_RSA
  62816. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62817. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  62818. ExpectIntEQ(info.rsaAuth, 1);
  62819. ExpectIntEQ(info.eccAuth, 0);
  62820. ExpectIntEQ(info.eccStatic, 0);
  62821. ExpectIntEQ(info.psk, 0);
  62822. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62823. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  62824. ExpectIntEQ(info.rsaAuth, 1);
  62825. ExpectIntEQ(info.eccAuth, 0);
  62826. ExpectIntEQ(info.eccStatic, 1);
  62827. ExpectIntEQ(info.psk, 0);
  62828. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62829. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  62830. ExpectIntEQ(info.rsaAuth, 1);
  62831. ExpectIntEQ(info.eccAuth, 0);
  62832. ExpectIntEQ(info.eccStatic, 1);
  62833. ExpectIntEQ(info.psk, 0);
  62834. #endif
  62835. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62836. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  62837. ExpectIntEQ(info.rsaAuth, 0);
  62838. ExpectIntEQ(info.eccAuth, 1);
  62839. ExpectIntEQ(info.eccStatic, 0);
  62840. ExpectIntEQ(info.psk, 0);
  62841. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  62842. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  62843. ExpectIntEQ(info.rsaAuth, 0);
  62844. ExpectIntEQ(info.eccAuth, 1);
  62845. ExpectIntEQ(info.eccStatic, 1);
  62846. ExpectIntEQ(info.psk, 0);
  62847. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  62848. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  62849. ExpectIntEQ(info.rsaAuth, 0);
  62850. ExpectIntEQ(info.eccAuth, 0);
  62851. ExpectIntEQ(info.eccStatic, 0);
  62852. ExpectIntEQ(info.psk, 1);
  62853. #endif
  62854. #endif
  62855. #ifdef WOLFSSL_TLS13
  62856. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  62857. TLS_AES_128_GCM_SHA256);
  62858. ExpectIntEQ(info.rsaAuth, 0);
  62859. ExpectIntEQ(info.eccAuth, 0);
  62860. ExpectIntEQ(info.eccStatic, 0);
  62861. ExpectIntEQ(info.psk, 0);
  62862. #endif
  62863. #endif
  62864. return EXPECT_RESULT();
  62865. }
  62866. static int test_wolfSSL_sigalg_info(void)
  62867. {
  62868. EXPECT_DECLS;
  62869. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  62870. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  62871. word16 len = 0;
  62872. word16 idx = 0;
  62873. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  62874. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  62875. for (idx = 0; idx < len; idx += 2) {
  62876. int hashAlgo = 0;
  62877. int sigAlgo = 0;
  62878. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  62879. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  62880. ExpectIntNE(hashAlgo, 0);
  62881. ExpectIntNE(sigAlgo, 0);
  62882. }
  62883. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  62884. 0xFFFFFFFF, &len);
  62885. for (idx = 0; idx < len; idx += 2) {
  62886. int hashAlgo = 0;
  62887. int sigAlgo = 0;
  62888. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  62889. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  62890. ExpectIntNE(hashAlgo, 0);
  62891. }
  62892. #endif
  62893. return EXPECT_RESULT();
  62894. }
  62895. static int test_wolfSSL_SESSION(void)
  62896. {
  62897. EXPECT_DECLS;
  62898. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62899. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62900. !defined(NO_SESSION_CACHE)
  62901. WOLFSSL* ssl = NULL;
  62902. WOLFSSL_CTX* ctx = NULL;
  62903. WOLFSSL_SESSION* sess = NULL;
  62904. WOLFSSL_SESSION* sess_copy = NULL;
  62905. #ifdef OPENSSL_EXTRA
  62906. #ifdef HAVE_EXT_CACHE
  62907. unsigned char* sessDer = NULL;
  62908. unsigned char* ptr = NULL;
  62909. int sz = 0;
  62910. #endif
  62911. const unsigned char context[] = "user app context";
  62912. unsigned int contextSz = (unsigned int)sizeof(context);
  62913. #endif
  62914. int ret = 0, err = 0;
  62915. SOCKET_T sockfd;
  62916. tcp_ready ready;
  62917. func_args server_args;
  62918. THREAD_TYPE serverThread;
  62919. char msg[80];
  62920. const char* sendGET = "GET";
  62921. /* TLS v1.3 requires session tickets */
  62922. /* CHACHA and POLY1305 required for myTicketEncCb */
  62923. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  62924. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  62925. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  62926. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  62927. #else
  62928. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62929. #endif
  62930. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  62931. WOLFSSL_FILETYPE_PEM));
  62932. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  62933. WOLFSSL_FILETYPE_PEM));
  62934. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  62935. WOLFSSL_SUCCESS);
  62936. #ifdef WOLFSSL_ENCRYPTED_KEYS
  62937. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  62938. #endif
  62939. #ifdef HAVE_SESSION_TICKET
  62940. /* Use session tickets, for ticket tests below */
  62941. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  62942. #endif
  62943. XMEMSET(&server_args, 0, sizeof(func_args));
  62944. #ifdef WOLFSSL_TIRTOS
  62945. fdOpenSession(Task_self());
  62946. #endif
  62947. StartTCP();
  62948. InitTcpReady(&ready);
  62949. #if defined(USE_WINDOWS_API)
  62950. /* use RNG to get random port if using windows */
  62951. ready.port = GetRandomPort();
  62952. #endif
  62953. server_args.signal = &ready;
  62954. start_thread(test_server_nofail, &server_args, &serverThread);
  62955. wait_tcp_ready(&server_args);
  62956. /* client connection */
  62957. ExpectNotNull(ssl = wolfSSL_new(ctx));
  62958. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  62959. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  62960. #ifdef WOLFSSL_ASYNC_CRYPT
  62961. err = 0; /* Reset error */
  62962. #endif
  62963. do {
  62964. #ifdef WOLFSSL_ASYNC_CRYPT
  62965. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62966. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62967. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62968. }
  62969. #endif
  62970. ret = wolfSSL_connect(ssl);
  62971. err = wolfSSL_get_error(ssl, 0);
  62972. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62973. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62974. #ifdef WOLFSSL_ASYNC_CRYPT
  62975. err = 0; /* Reset error */
  62976. #endif
  62977. do {
  62978. #ifdef WOLFSSL_ASYNC_CRYPT
  62979. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62980. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62981. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62982. }
  62983. #endif
  62984. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  62985. err = wolfSSL_get_error(ssl, 0);
  62986. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62987. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  62988. #ifdef WOLFSSL_ASYNC_CRYPT
  62989. err = 0; /* Reset error */
  62990. #endif
  62991. do {
  62992. #ifdef WOLFSSL_ASYNC_CRYPT
  62993. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62994. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62995. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62996. }
  62997. #endif
  62998. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  62999. err = wolfSSL_get_error(ssl, 0);
  63000. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63001. ExpectIntEQ(ret, 23);
  63002. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  63003. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  63004. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  63005. #ifdef HAVE_EXT_CACHE
  63006. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  63007. * HAVE_EXT_CACHE we get new objects each time */
  63008. #endif
  63009. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63010. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  63011. sess = wolfSSL_get_session(ssl);
  63012. #ifdef OPENSSL_EXTRA
  63013. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  63014. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  63015. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  63016. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  63017. #ifdef HAVE_SESSION_TICKET
  63018. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  63019. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  63020. SESSION_TICKET_HINT_DEFAULT);
  63021. #else
  63022. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  63023. #endif
  63024. #else
  63025. (void)sess;
  63026. #endif /* OPENSSL_EXTRA */
  63027. /* Retain copy of the session for later testing */
  63028. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  63029. wolfSSL_shutdown(ssl);
  63030. wolfSSL_free(ssl); ssl = NULL;
  63031. CloseSocket(sockfd);
  63032. join_thread(serverThread);
  63033. FreeTcpReady(&ready);
  63034. #ifdef WOLFSSL_TIRTOS
  63035. fdOpenSession(Task_self());
  63036. #endif
  63037. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  63038. {
  63039. X509 *x509 = NULL;
  63040. char buf[30];
  63041. int bufSz = 0;
  63042. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  63043. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  63044. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  63045. sizeof(buf))), 0);
  63046. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  63047. if (bufSz == 7) {
  63048. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  63049. }
  63050. if (bufSz == 16) {
  63051. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  63052. }
  63053. }
  63054. #endif
  63055. #ifdef HAVE_EXT_CACHE
  63056. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  63057. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63058. sess_copy = NULL;
  63059. #endif
  63060. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  63061. /* get session from DER and update the timeout */
  63062. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63063. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  63064. wolfSSL_SESSION_free(sess); sess = NULL;
  63065. sess = NULL;
  63066. ptr = sessDer;
  63067. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  63068. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  63069. (const unsigned char**)&ptr, sz));
  63070. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  63071. sessDer = NULL;
  63072. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  63073. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63074. #endif
  63075. /* successful set session test */
  63076. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63077. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  63078. #ifdef HAVE_SESSION_TICKET
  63079. /* Test set/get session ticket */
  63080. {
  63081. const char* ticket = "This is a session ticket";
  63082. char buf[64] = {0};
  63083. word32 bufSz = (word32)sizeof(buf);
  63084. ExpectIntEQ(SSL_SUCCESS,
  63085. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  63086. (word32)XSTRLEN(ticket)));
  63087. ExpectIntEQ(SSL_SUCCESS,
  63088. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  63089. ExpectStrEQ(ticket, buf);
  63090. }
  63091. #endif
  63092. #ifdef OPENSSL_EXTRA
  63093. /* session timeout case */
  63094. /* make the session to be expired */
  63095. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  63096. XSLEEP_MS(1200);
  63097. /* SSL_set_session should reject specified session but return success
  63098. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  63099. */
  63100. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63101. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  63102. #else
  63103. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63104. #endif
  63105. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63106. #ifdef WOLFSSL_SESSION_ID_CTX
  63107. /* fail case with miss match session context IDs (use compatibility API) */
  63108. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  63109. SSL_SUCCESS);
  63110. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63111. wolfSSL_free(ssl); ssl = NULL;
  63112. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  63113. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63114. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  63115. SSL_SUCCESS);
  63116. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63117. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63118. #endif
  63119. #endif /* OPENSSL_EXTRA */
  63120. wolfSSL_free(ssl);
  63121. wolfSSL_SESSION_free(sess);
  63122. wolfSSL_CTX_free(ctx);
  63123. #endif
  63124. return EXPECT_RESULT();
  63125. }
  63126. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63127. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63128. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63129. !defined(WOLFSSL_NO_TLS12)
  63130. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  63131. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  63132. {
  63133. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  63134. /* returns previous timeout value */
  63135. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  63136. #else
  63137. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  63138. #endif
  63139. }
  63140. /* set the session to timeout in a second */
  63141. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  63142. {
  63143. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  63144. }
  63145. /* store the client side session from the first successful connection */
  63146. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  63147. {
  63148. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  63149. NULL); /* ref count 1 */
  63150. }
  63151. /* wait till session is expired then set it in the WOLFSSL struct for use */
  63152. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  63153. {
  63154. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  63155. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63156. WOLFSSL_SUCCESS);
  63157. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  63158. }
  63159. /* set expired session in the WOLFSSL struct for use */
  63160. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  63161. {
  63162. XSLEEP_MS(1200); /* wait a second for session to expire */
  63163. /* set the expired session, call to set session fails but continuing on
  63164. after failure should be handled here */
  63165. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63166. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63167. WOLFSSL_SUCCESS);
  63168. #else
  63169. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63170. WOLFSSL_SUCCESS);
  63171. #endif
  63172. }
  63173. /* check that the expired session was not reused */
  63174. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  63175. {
  63176. /* since the session has expired it should not have been reused */
  63177. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  63178. }
  63179. #endif
  63180. static int test_wolfSSL_SESSION_expire_downgrade(void)
  63181. {
  63182. EXPECT_DECLS;
  63183. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63184. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63185. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63186. !defined(WOLFSSL_NO_TLS12)
  63187. WOLFSSL_CTX* ctx = NULL;
  63188. callback_functions server_cbf, client_cbf;
  63189. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  63190. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  63191. /* force server side to use TLS 1.2 */
  63192. server_cbf.ctx = ctx;
  63193. server_cbf.method = wolfTLSv1_2_server_method;
  63194. client_cbf.method = wolfSSLv23_client_method;
  63195. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63196. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  63197. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  63198. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63199. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63200. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63201. /* set the previously created session and wait till expired */
  63202. server_cbf.ctx = ctx;
  63203. client_cbf.method = wolfSSLv23_client_method;
  63204. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63205. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  63206. client_cbf.on_result =
  63207. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63208. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63209. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63210. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63211. /* set the previously created expired session */
  63212. server_cbf.ctx = ctx;
  63213. client_cbf.method = wolfSSLv23_client_method;
  63214. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63215. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  63216. client_cbf.on_result =
  63217. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63218. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63219. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63220. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63221. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  63222. wolfSSL_CTX_free(ctx);
  63223. #endif
  63224. return EXPECT_RESULT();
  63225. }
  63226. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63227. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63228. static int clientSessRemCountMalloc = 0;
  63229. static int serverSessRemCountMalloc = 0;
  63230. static int clientSessRemCountFree = 0;
  63231. static int serverSessRemCountFree = 0;
  63232. static WOLFSSL_CTX* serverSessCtx = NULL;
  63233. static WOLFSSL_SESSION* serverSess = NULL;
  63234. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63235. !defined(NO_SESSION_CACHE_REF)
  63236. static WOLFSSL_CTX* clientSessCtx = NULL;
  63237. static WOLFSSL_SESSION* clientSess = NULL;
  63238. #endif
  63239. static int serverSessRemIdx = 3;
  63240. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  63241. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  63242. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  63243. {
  63244. int* side;
  63245. (void)ctx;
  63246. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  63247. if (side != NULL) {
  63248. if (*side == WOLFSSL_CLIENT_END)
  63249. clientSessRemCountFree++;
  63250. else
  63251. serverSessRemCountFree++;
  63252. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  63253. }
  63254. }
  63255. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  63256. {
  63257. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  63258. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  63259. !defined(NO_SESSION_CACHE_REF)
  63260. {
  63261. EXPECT_DECLS;
  63262. /* Allow downgrade, set min version, and disable TLS 1.3.
  63263. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  63264. * reference to the session cache. But with WOLFSSL_TLS13 and without
  63265. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  63266. * the session in the cache. In this case we need to downgrade to
  63267. * previous versions to just use the legacy session ID field. */
  63268. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  63269. SSL_SUCCESS);
  63270. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  63271. SSL_SUCCESS);
  63272. return EXPECT_RESULT();
  63273. }
  63274. #else
  63275. return TEST_SUCCESS;
  63276. #endif
  63277. }
  63278. static int SessRemSslSetupCb(WOLFSSL* ssl)
  63279. {
  63280. EXPECT_DECLS;
  63281. int* side;
  63282. if (SSL_is_server(ssl)) {
  63283. side = &sessRemCtx_Server;
  63284. serverSessRemCountMalloc++;
  63285. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  63286. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  63287. SSL_SUCCESS);
  63288. }
  63289. else {
  63290. side = &sessRemCtx_Client;
  63291. clientSessRemCountMalloc++;
  63292. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63293. !defined(NO_SESSION_CACHE_REF)
  63294. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  63295. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  63296. SSL_SUCCESS);
  63297. #endif
  63298. }
  63299. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  63300. serverSessRemIdx, side), SSL_SUCCESS);
  63301. return EXPECT_RESULT();
  63302. }
  63303. #endif
  63304. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  63305. {
  63306. EXPECT_DECLS;
  63307. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63308. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63309. /* Check that the remove callback gets called for external data in a
  63310. * session object */
  63311. test_ssl_cbf func_cb;
  63312. XMEMSET(&func_cb, 0, sizeof(func_cb));
  63313. func_cb.ctx_ready = SessRemCtxSetupCb;
  63314. func_cb.on_result = SessRemSslSetupCb;
  63315. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  63316. NULL), TEST_SUCCESS);
  63317. /* Both should have been allocated */
  63318. ExpectIntEQ(clientSessRemCountMalloc, 1);
  63319. ExpectIntEQ(serverSessRemCountMalloc, 1);
  63320. /* This should not be called yet. Session wasn't evicted from cache yet. */
  63321. ExpectIntEQ(clientSessRemCountFree, 0);
  63322. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63323. !defined(NO_SESSION_CACHE_REF)
  63324. /* Force a cache lookup */
  63325. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63326. /* Force a cache update */
  63327. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  63328. /* This should set the timeout to 0 and call the remove callback from within
  63329. * the session cache. */
  63330. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  63331. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63332. ExpectIntEQ(clientSessRemCountFree, 1);
  63333. #endif
  63334. /* Server session is in the cache so ex_data isn't free'd with the SSL
  63335. * object */
  63336. ExpectIntEQ(serverSessRemCountFree, 0);
  63337. /* Force a cache lookup */
  63338. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63339. /* Force a cache update */
  63340. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  63341. /* This should set the timeout to 0 and call the remove callback from within
  63342. * the session cache. */
  63343. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  63344. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63345. ExpectIntEQ(serverSessRemCountFree, 1);
  63346. /* Need to free the references that we kept */
  63347. SSL_CTX_free(serverSessCtx);
  63348. SSL_SESSION_free(serverSess);
  63349. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63350. !defined(NO_SESSION_CACHE_REF)
  63351. SSL_CTX_free(clientSessCtx);
  63352. SSL_SESSION_free(clientSess);
  63353. #endif
  63354. #endif
  63355. return EXPECT_RESULT();
  63356. }
  63357. static int test_wolfSSL_ticket_keys(void)
  63358. {
  63359. EXPECT_DECLS;
  63360. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  63361. !defined(NO_WOLFSSL_SERVER)
  63362. WOLFSSL_CTX* ctx = NULL;
  63363. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  63364. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  63365. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  63366. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63367. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  63368. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63369. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  63370. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63371. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  63372. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63373. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63374. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63375. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63376. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63377. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63378. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63379. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  63380. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63381. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  63382. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63383. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  63384. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63385. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  63386. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63387. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63388. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63389. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63390. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63391. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63392. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63393. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63394. WOLFSSL_SUCCESS);
  63395. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63396. WOLFSSL_SUCCESS);
  63397. wolfSSL_CTX_free(ctx);
  63398. #endif
  63399. return EXPECT_RESULT();
  63400. }
  63401. #ifndef NO_BIO
  63402. static int test_wolfSSL_d2i_PUBKEY(void)
  63403. {
  63404. EXPECT_DECLS;
  63405. #if defined(OPENSSL_EXTRA)
  63406. BIO* bio = NULL;
  63407. EVP_PKEY* pkey = NULL;
  63408. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63409. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  63410. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  63411. /* RSA PUBKEY test */
  63412. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  63413. sizeof_client_keypub_der_2048), 0);
  63414. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63415. EVP_PKEY_free(pkey);
  63416. pkey = NULL;
  63417. #endif
  63418. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  63419. /* ECC PUBKEY test */
  63420. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  63421. sizeof_ecc_clikeypub_der_256), 0);
  63422. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63423. EVP_PKEY_free(pkey);
  63424. pkey = NULL;
  63425. #endif
  63426. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  63427. /* DSA PUBKEY test */
  63428. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  63429. sizeof_dsa_pub_key_der_2048), 0);
  63430. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63431. EVP_PKEY_free(pkey);
  63432. pkey = NULL;
  63433. #endif
  63434. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  63435. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  63436. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  63437. (HAVE_FIPS_VERSION > 2))
  63438. /* DH PUBKEY test */
  63439. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  63440. sizeof_dh_pub_key_der_2048), 0);
  63441. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63442. EVP_PKEY_free(pkey);
  63443. pkey = NULL;
  63444. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  63445. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  63446. BIO_free(bio);
  63447. (void)pkey;
  63448. #endif
  63449. return EXPECT_RESULT();
  63450. }
  63451. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  63452. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  63453. {
  63454. EXPECT_DECLS;
  63455. BIO* bio = NULL;
  63456. EVP_PKEY* pkey = NULL;
  63457. WOLFSSL_CTX* ctx = NULL;
  63458. #if defined(WOLFSSL_KEY_GEN)
  63459. unsigned char buff[4096];
  63460. unsigned char* bufPtr = buff;
  63461. #endif
  63462. /* test creating new EVP_PKEY with bad arg */
  63463. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  63464. /* test loading RSA key using BIO */
  63465. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  63466. {
  63467. XFILE file = XBADFILE;
  63468. const char* fname = "./certs/server-key.der";
  63469. size_t sz = 0;
  63470. byte* buf = NULL;
  63471. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63472. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63473. ExpectTrue((sz = XFTELL(file)) != 0);
  63474. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63475. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63476. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63477. if (file != XBADFILE) {
  63478. XFCLOSE(file);
  63479. }
  63480. /* Test using BIO new mem and loading DER private key */
  63481. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63482. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63483. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63484. BIO_free(bio);
  63485. bio = NULL;
  63486. EVP_PKEY_free(pkey);
  63487. pkey = NULL;
  63488. }
  63489. #endif
  63490. /* test loading ECC key using BIO */
  63491. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  63492. {
  63493. XFILE file = XBADFILE;
  63494. const char* fname = "./certs/ecc-key.der";
  63495. size_t sz = 0;
  63496. byte* buf = NULL;
  63497. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63498. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63499. ExpectTrue((sz = XFTELL(file)) != 0);
  63500. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63501. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63502. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63503. if (file != XBADFILE)
  63504. XFCLOSE(file);
  63505. /* Test using BIO new mem and loading DER private key */
  63506. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63507. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63508. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63509. BIO_free(bio);
  63510. bio = NULL;
  63511. EVP_PKEY_free(pkey);
  63512. pkey = NULL;
  63513. }
  63514. #endif
  63515. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63516. #ifndef NO_WOLFSSL_SERVER
  63517. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  63518. #else
  63519. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  63520. #endif
  63521. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  63522. {
  63523. RSA* rsa = NULL;
  63524. /* Tests bad parameters */
  63525. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  63526. /* RSA not set yet, expecting to fail*/
  63527. rsa = wolfSSL_RSA_new();
  63528. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63529. wolfSSL_RSA_free(rsa);
  63530. rsa = NULL;
  63531. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  63532. /* set RSA using bio*/
  63533. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63534. sizeof_client_key_der_2048), 0);
  63535. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  63536. ExpectNotNull(rsa);
  63537. /* Tests bad parameters */
  63538. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63539. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63540. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63541. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  63542. /* i2d RSAprivate key tests */
  63543. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63544. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  63545. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63546. sizeof_client_key_der_2048);
  63547. bufPtr -= sizeof_client_key_der_2048;
  63548. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63549. sizeof_client_key_der_2048), 0);
  63550. bufPtr = NULL;
  63551. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63552. sizeof_client_key_der_2048);
  63553. ExpectNotNull(bufPtr);
  63554. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63555. sizeof_client_key_der_2048), 0);
  63556. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  63557. RSA_free(rsa);
  63558. rsa = NULL;
  63559. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63560. sizeof_client_key_der_2048), 0);
  63561. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  63562. (void)BIO_reset(bio);
  63563. RSA_free(rsa);
  63564. rsa = RSA_new();
  63565. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  63566. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  63567. RSA_free(rsa);
  63568. }
  63569. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  63570. SSL_CTX_free(ctx);
  63571. ctx = NULL;
  63572. BIO_free(bio);
  63573. bio = NULL;
  63574. return EXPECT_RESULT();
  63575. }
  63576. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  63577. #endif /* !NO_BIO */
  63578. static int test_wolfSSL_sk_GENERAL_NAME(void)
  63579. {
  63580. EXPECT_DECLS;
  63581. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63582. !defined(NO_RSA)
  63583. X509* x509 = NULL;
  63584. GENERAL_NAME* gn = NULL;
  63585. unsigned char buf[4096];
  63586. const unsigned char* bufPt = NULL;
  63587. int bytes = 0;
  63588. int i;
  63589. int j;
  63590. XFILE f = XBADFILE;
  63591. STACK_OF(GENERAL_NAME)* sk = NULL;
  63592. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63593. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63594. if (f != XBADFILE)
  63595. XFCLOSE(f);
  63596. for (j = 0; j < 2; ++j) {
  63597. bufPt = buf;
  63598. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63599. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63600. NID_subject_alt_name, NULL, NULL));
  63601. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  63602. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  63603. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  63604. if (gn != NULL) {
  63605. switch (gn->type) {
  63606. case GEN_DNS:
  63607. fprintf(stderr, "found type GEN_DNS\n");
  63608. break;
  63609. case GEN_EMAIL:
  63610. fprintf(stderr, "found type GEN_EMAIL\n");
  63611. break;
  63612. case GEN_URI:
  63613. fprintf(stderr, "found type GEN_URI\n");
  63614. break;
  63615. }
  63616. }
  63617. }
  63618. X509_free(x509);
  63619. x509 = NULL;
  63620. if (j == 0) {
  63621. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63622. }
  63623. else {
  63624. /*
  63625. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  63626. * it was supposed to. This is a regression test for that bug.
  63627. */
  63628. GENERAL_NAMES_free(sk);
  63629. }
  63630. sk = NULL;
  63631. }
  63632. #endif
  63633. return EXPECT_RESULT();
  63634. }
  63635. static int test_wolfSSL_GENERAL_NAME_print(void)
  63636. {
  63637. EXPECT_DECLS;
  63638. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  63639. X509* x509 = NULL;
  63640. GENERAL_NAME* gn = NULL;
  63641. unsigned char buf[4096];
  63642. const unsigned char* bufPt = NULL;
  63643. int bytes;
  63644. XFILE f = XBADFILE;
  63645. STACK_OF(GENERAL_NAME)* sk = NULL;
  63646. BIO* out = NULL;
  63647. unsigned char outbuf[128];
  63648. X509_EXTENSION* ext = NULL;
  63649. AUTHORITY_INFO_ACCESS* aia = NULL;
  63650. ACCESS_DESCRIPTION* ad = NULL;
  63651. ASN1_IA5STRING *dnsname = NULL;
  63652. const unsigned char v4Addr[] = {192,168,53,1};
  63653. const unsigned char v6Addr[] =
  63654. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  63655. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  63656. const unsigned char email[] =
  63657. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  63658. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  63659. const char* dnsStr = "DNS:example.com";
  63660. const char* uriStr = "URI:http://127.0.0.1:22220";
  63661. const char* v4addStr = "IP Address:192.168.53.1";
  63662. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  63663. const char* emailStr = "email:info@wolfssl.com";
  63664. const char* othrStr = "othername:<unsupported>";
  63665. const char* x400Str = "X400Name:<unsupported>";
  63666. const char* ediStr = "EdiPartyName:<unsupported>";
  63667. /* BIO to output */
  63668. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  63669. /* test for NULL param */
  63670. gn = NULL;
  63671. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  63672. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  63673. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  63674. /* test for GEN_DNS */
  63675. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63676. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63677. if (f != XBADFILE) {
  63678. XFCLOSE(f);
  63679. f = XBADFILE;
  63680. }
  63681. bufPt = buf;
  63682. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63683. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63684. NID_subject_alt_name, NULL, NULL));
  63685. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  63686. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63687. XMEMSET(outbuf, 0, sizeof(outbuf));
  63688. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63689. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63690. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63691. gn = NULL;
  63692. sk = NULL;
  63693. X509_free(x509);
  63694. x509 = NULL;
  63695. /* Lets test for setting as well. */
  63696. ExpectNotNull(gn = GENERAL_NAME_new());
  63697. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  63698. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  63699. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  63700. dnsname = NULL;
  63701. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63702. XMEMSET(outbuf, 0, sizeof(outbuf));
  63703. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63704. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63705. GENERAL_NAME_free(gn);
  63706. /* test for GEN_URI */
  63707. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  63708. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  63709. if (f != XBADFILE) {
  63710. XFCLOSE(f);
  63711. f = XBADFILE;
  63712. }
  63713. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  63714. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  63715. ext));
  63716. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  63717. if (ad != NULL) {
  63718. gn = ad->location;
  63719. }
  63720. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63721. gn = NULL;
  63722. XMEMSET(outbuf,0,sizeof(outbuf));
  63723. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63724. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  63725. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  63726. aia = NULL;
  63727. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  63728. ExpectNotNull(aia);
  63729. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  63730. aia = NULL;
  63731. X509_free(x509);
  63732. x509 = NULL;
  63733. /* test for GEN_IPADD */
  63734. /* ip v4 address */
  63735. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63736. if (gn != NULL) {
  63737. gn->type = GEN_IPADD;
  63738. if (gn->d.iPAddress != NULL) {
  63739. gn->d.iPAddress->length = sizeof(v4Addr);
  63740. }
  63741. }
  63742. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  63743. sizeof(v4Addr)), 1);
  63744. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63745. XMEMSET(outbuf,0,sizeof(outbuf));
  63746. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63747. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  63748. GENERAL_NAME_free(gn);
  63749. gn = NULL;
  63750. /* ip v6 address */
  63751. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63752. if (gn != NULL) {
  63753. gn->type = GEN_IPADD;
  63754. if (gn->d.iPAddress != NULL) {
  63755. gn->d.iPAddress->length = sizeof(v6Addr);
  63756. }
  63757. }
  63758. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  63759. sizeof(v6Addr)), 1);
  63760. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63761. XMEMSET(outbuf,0,sizeof(outbuf));
  63762. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63763. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  63764. GENERAL_NAME_free(gn);
  63765. gn = NULL;
  63766. /* test for GEN_EMAIL */
  63767. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63768. if (gn != NULL) {
  63769. gn->type = GEN_EMAIL;
  63770. if (gn->d.rfc822Name != NULL) {
  63771. gn->d.rfc822Name->length = sizeof(email);
  63772. }
  63773. }
  63774. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  63775. 1);
  63776. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63777. XMEMSET(outbuf,0,sizeof(outbuf));
  63778. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63779. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  63780. GENERAL_NAME_free(gn);
  63781. gn = NULL;
  63782. /* test for GEN_OTHERNAME */
  63783. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63784. if (gn != NULL) {
  63785. gn->type = GEN_OTHERNAME;
  63786. }
  63787. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63788. XMEMSET(outbuf,0,sizeof(outbuf));
  63789. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63790. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  63791. GENERAL_NAME_free(gn);
  63792. gn = NULL;
  63793. /* test for GEN_X400 */
  63794. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63795. if (gn != NULL) {
  63796. gn->type = GEN_X400;
  63797. }
  63798. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63799. XMEMSET(outbuf,0,sizeof(outbuf));
  63800. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63801. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  63802. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  63803. if (gn != NULL) {
  63804. gn->type = GEN_IA5;
  63805. }
  63806. GENERAL_NAME_free(gn);
  63807. gn = NULL;
  63808. /* test for GEN_EDIPARTY */
  63809. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  63810. if (gn != NULL) {
  63811. gn->type = GEN_EDIPARTY;
  63812. }
  63813. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63814. XMEMSET(outbuf,0,sizeof(outbuf));
  63815. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63816. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  63817. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  63818. if (gn != NULL) {
  63819. gn->type = GEN_IA5;
  63820. }
  63821. GENERAL_NAME_free(gn);
  63822. gn = NULL;
  63823. BIO_free(out);
  63824. #endif /* OPENSSL_ALL */
  63825. return EXPECT_RESULT();
  63826. }
  63827. static int test_wolfSSL_sk_DIST_POINT(void)
  63828. {
  63829. EXPECT_DECLS;
  63830. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63831. !defined(NO_RSA)
  63832. X509* x509 = NULL;
  63833. unsigned char buf[4096];
  63834. const unsigned char* bufPt;
  63835. int bytes = 0;
  63836. int i = 0;
  63837. int j = 0;
  63838. XFILE f = XBADFILE;
  63839. DIST_POINT* dp = NULL;
  63840. DIST_POINT_NAME* dpn = NULL;
  63841. GENERAL_NAME* gn = NULL;
  63842. ASN1_IA5STRING* uri = NULL;
  63843. STACK_OF(DIST_POINT)* dps = NULL;
  63844. STACK_OF(GENERAL_NAME)* gns = NULL;
  63845. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  63846. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  63847. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63848. if (f != XBADFILE)
  63849. XFCLOSE(f);
  63850. bufPt = buf;
  63851. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63852. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  63853. NID_crl_distribution_points, NULL, NULL));
  63854. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  63855. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  63856. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  63857. ExpectNotNull(dpn = dp->distpoint);
  63858. /* this should be type 0, fullname */
  63859. ExpectIntEQ(dpn->type, 0);
  63860. ExpectNotNull(gns = dp->distpoint->name.fullname);
  63861. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  63862. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  63863. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  63864. ExpectIntEQ(gn->type, GEN_URI);
  63865. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  63866. ExpectNotNull(uri->data);
  63867. ExpectIntGT(uri->length, 0);
  63868. }
  63869. }
  63870. X509_free(x509);
  63871. CRL_DIST_POINTS_free(dps);
  63872. #endif
  63873. return EXPECT_RESULT();
  63874. }
  63875. static int test_wolfSSL_verify_mode(void)
  63876. {
  63877. EXPECT_DECLS;
  63878. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  63879. WOLFSSL* ssl = NULL;
  63880. WOLFSSL_CTX* ctx = NULL;
  63881. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63882. ExpectNotNull(ssl = SSL_new(ctx));
  63883. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63884. SSL_free(ssl);
  63885. ssl = NULL;
  63886. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  63887. ExpectNotNull(ssl = SSL_new(ctx));
  63888. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63889. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  63890. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  63891. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  63892. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  63893. SSL_free(ssl);
  63894. ssl = NULL;
  63895. wolfSSL_CTX_set_verify(ctx,
  63896. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  63897. ExpectNotNull(ssl = SSL_new(ctx));
  63898. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  63899. ExpectIntEQ(SSL_get_verify_mode(ssl),
  63900. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63901. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  63902. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  63903. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63904. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  63905. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  63906. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  63907. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  63908. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63909. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  63910. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  63911. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  63912. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  63913. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  63914. #endif
  63915. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  63916. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  63917. SSL_free(ssl);
  63918. SSL_CTX_free(ctx);
  63919. #endif
  63920. return EXPECT_RESULT();
  63921. }
  63922. static int test_wolfSSL_verify_depth(void)
  63923. {
  63924. EXPECT_DECLS;
  63925. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63926. WOLFSSL* ssl = NULL;
  63927. WOLFSSL_CTX* ctx = NULL;
  63928. long depth;
  63929. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63930. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  63931. ExpectNotNull(ssl = SSL_new(ctx));
  63932. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  63933. SSL_free(ssl);
  63934. ssl = NULL;
  63935. SSL_CTX_set_verify_depth(ctx, -1);
  63936. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  63937. SSL_CTX_set_verify_depth(ctx, 2);
  63938. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  63939. ExpectNotNull(ssl = SSL_new(ctx));
  63940. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  63941. SSL_free(ssl);
  63942. SSL_CTX_free(ctx);
  63943. #endif
  63944. return EXPECT_RESULT();
  63945. }
  63946. static int test_wolfSSL_verify_result(void)
  63947. {
  63948. EXPECT_DECLS;
  63949. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  63950. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  63951. WOLFSSL* ssl = NULL;
  63952. WOLFSSL_CTX* ctx = NULL;
  63953. long result = 0xDEADBEEF;
  63954. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  63955. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63956. ExpectNotNull(ssl = SSL_new(ctx));
  63957. wolfSSL_set_verify_result(ssl, result);
  63958. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  63959. SSL_free(ssl);
  63960. SSL_CTX_free(ctx);
  63961. #endif
  63962. return EXPECT_RESULT();
  63963. }
  63964. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63965. static void sslMsgCb(int w, int version, int type, const void* buf,
  63966. size_t sz, SSL* ssl, void* arg)
  63967. {
  63968. int i;
  63969. unsigned char* pt = (unsigned char*)buf;
  63970. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  63971. (w)?"Writing":"Reading", (int)sz, version, type);
  63972. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  63973. fprintf(stderr, "\n");
  63974. (void)ssl;
  63975. (void)arg;
  63976. }
  63977. #endif /* OPENSSL_EXTRA */
  63978. static int test_wolfSSL_msg_callback(void)
  63979. {
  63980. EXPECT_DECLS;
  63981. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  63982. WOLFSSL* ssl = NULL;
  63983. WOLFSSL_CTX* ctx = NULL;
  63984. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63985. ExpectNotNull(ssl = SSL_new(ctx));
  63986. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  63987. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  63988. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63989. SSL_free(ssl);
  63990. SSL_CTX_free(ctx);
  63991. #endif
  63992. return EXPECT_RESULT();
  63993. }
  63994. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  63995. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  63996. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  63997. static void binary_dump(void *ptr, int size)
  63998. {
  63999. #ifdef WOLFSSL_EVP_PRINT
  64000. int i = 0;
  64001. unsigned char *p = (unsigned char *) ptr;
  64002. fprintf(stderr, "{");
  64003. while ((p != NULL) && (i < size)) {
  64004. if ((i % 8) == 0) {
  64005. fprintf(stderr, "\n");
  64006. fprintf(stderr, " ");
  64007. }
  64008. fprintf(stderr, "0x%02x, ", p[i]);
  64009. i++;
  64010. }
  64011. fprintf(stderr, "\n};\n");
  64012. #else
  64013. (void) ptr;
  64014. (void) size;
  64015. #endif
  64016. }
  64017. static int last_val = 0x0f;
  64018. static int check_result(unsigned char *data, int len)
  64019. {
  64020. int i;
  64021. for ( ; len; ) {
  64022. last_val = (last_val + 1) % 16;
  64023. for (i = 0; i < 16; len--, i++, data++)
  64024. if (*data != last_val) {
  64025. return -1;
  64026. }
  64027. }
  64028. return 0;
  64029. }
  64030. static int r_offset;
  64031. static int w_offset;
  64032. static void init_offset(void)
  64033. {
  64034. r_offset = 0;
  64035. w_offset = 0;
  64036. }
  64037. static void get_record(unsigned char *data, unsigned char *buf, int len)
  64038. {
  64039. XMEMCPY(buf, data+r_offset, len);
  64040. r_offset += len;
  64041. }
  64042. static void set_record(unsigned char *data, unsigned char *buf, int len)
  64043. {
  64044. XMEMCPY(data+w_offset, buf, len);
  64045. w_offset += len;
  64046. }
  64047. static void set_plain(unsigned char *plain, int rec)
  64048. {
  64049. int i, j;
  64050. unsigned char *p = plain;
  64051. #define BLOCKSZ 16
  64052. for (i=0; i<(rec/BLOCKSZ); i++) {
  64053. for (j=0; j<BLOCKSZ; j++)
  64054. *p++ = (i % 16);
  64055. }
  64056. }
  64057. #endif
  64058. static int test_wolfSSL_EVP_Cipher_extra(void)
  64059. {
  64060. EXPECT_DECLS;
  64061. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  64062. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  64063. /* aes128-cbc, keylen=16, ivlen=16 */
  64064. byte aes128_cbc_key[] = {
  64065. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64066. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64067. };
  64068. byte aes128_cbc_iv[] = {
  64069. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  64070. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  64071. };
  64072. /* teset data size table */
  64073. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  64074. int test_drive2[] = {8, 3, 8, 512, 0};
  64075. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  64076. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  64077. int test_drive_len[100];
  64078. int ret = 0;
  64079. EVP_CIPHER_CTX *evp = NULL;
  64080. int ilen = 0;
  64081. int klen = 0;
  64082. int i, j;
  64083. const EVP_CIPHER *type;
  64084. byte *iv;
  64085. byte *key;
  64086. int ivlen;
  64087. int keylen;
  64088. #define RECORDS 16
  64089. #define BUFFSZ 512
  64090. byte plain [BUFFSZ * RECORDS];
  64091. byte cipher[BUFFSZ * RECORDS];
  64092. byte inb[BUFFSZ];
  64093. byte outb[BUFFSZ+16];
  64094. int outl = 0;
  64095. int inl;
  64096. iv = aes128_cbc_iv;
  64097. ivlen = sizeof(aes128_cbc_iv);
  64098. key = aes128_cbc_key;
  64099. keylen = sizeof(aes128_cbc_key);
  64100. type = EVP_aes_128_cbc();
  64101. set_plain(plain, BUFFSZ * RECORDS);
  64102. SSL_library_init();
  64103. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64104. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64105. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64106. klen = EVP_CIPHER_CTX_key_length(evp);
  64107. if (klen > 0 && keylen != klen) {
  64108. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64109. }
  64110. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64111. if (ilen > 0 && ivlen != ilen) {
  64112. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64113. }
  64114. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64115. for (j = 0; j<RECORDS; j++)
  64116. {
  64117. inl = BUFFSZ;
  64118. get_record(plain, inb, inl);
  64119. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  64120. set_record(cipher, outb, outl);
  64121. }
  64122. for (i = 0; test_drive[i]; i++) {
  64123. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64124. init_offset();
  64125. test_drive_len[i] = 0;
  64126. for (j = 0; test_drive[i][j]; j++)
  64127. {
  64128. inl = test_drive[i][j];
  64129. test_drive_len[i] += inl;
  64130. get_record(plain, inb, inl);
  64131. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  64132. 0);
  64133. /* output to cipher buffer, so that following Dec test can detect
  64134. if any error */
  64135. set_record(cipher, outb, outl);
  64136. }
  64137. EVP_CipherFinal(evp, outb, &outl);
  64138. if (outl > 0)
  64139. set_record(cipher, outb, outl);
  64140. }
  64141. for (i = 0; test_drive[i]; i++) {
  64142. last_val = 0x0f;
  64143. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  64144. init_offset();
  64145. for (j = 0; test_drive[i][j]; j++) {
  64146. inl = test_drive[i][j];
  64147. get_record(cipher, inb, inl);
  64148. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  64149. 0);
  64150. binary_dump(outb, outl);
  64151. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  64152. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  64153. }
  64154. ret = EVP_CipherFinal(evp, outb, &outl);
  64155. binary_dump(outb, outl);
  64156. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  64157. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  64158. ExpectTrue(ret);
  64159. }
  64160. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  64161. EVP_CIPHER_CTX_free(evp);
  64162. evp = NULL;
  64163. /* Do an extra test to verify correct behavior with empty input. */
  64164. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64165. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64166. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64167. klen = EVP_CIPHER_CTX_key_length(evp);
  64168. if (klen > 0 && keylen != klen) {
  64169. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64170. }
  64171. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64172. if (ilen > 0 && ivlen != ilen) {
  64173. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64174. }
  64175. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64176. /* outl should be set to 0 after passing NULL, 0 for input args. */
  64177. outl = -1;
  64178. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  64179. ExpectIntEQ(outl, 0);
  64180. EVP_CIPHER_CTX_free(evp);
  64181. #endif /* test_EVP_Cipher */
  64182. return EXPECT_RESULT();
  64183. }
  64184. static int test_wolfSSL_PEM_read_DHparams(void)
  64185. {
  64186. EXPECT_DECLS;
  64187. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  64188. !defined(NO_FILESYSTEM)
  64189. DH* dh = NULL;
  64190. XFILE fp = XBADFILE;
  64191. unsigned char derOut[300];
  64192. unsigned char* derOutBuf = derOut;
  64193. int derOutSz = 0;
  64194. unsigned char derExpected[300];
  64195. int derExpectedSz = 0;
  64196. XMEMSET(derOut, 0, sizeof(derOut));
  64197. XMEMSET(derExpected, 0, sizeof(derExpected));
  64198. /* open DH param file, read into DH struct */
  64199. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  64200. /* bad args */
  64201. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  64202. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  64203. /* good args */
  64204. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64205. if (fp != XBADFILE) {
  64206. XFCLOSE(fp);
  64207. fp = XBADFILE;
  64208. }
  64209. /* read in certs/dh2048.der for comparison against exported params */
  64210. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  64211. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  64212. fp), 0);
  64213. if (fp != XBADFILE) {
  64214. XFCLOSE(fp);
  64215. fp = XBADFILE;
  64216. }
  64217. /* export DH back to DER and compare */
  64218. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  64219. ExpectIntEQ(derOutSz, derExpectedSz);
  64220. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  64221. DH_free(dh);
  64222. dh = NULL;
  64223. /* Test parsing with X9.42 header */
  64224. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  64225. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64226. if (fp != XBADFILE)
  64227. XFCLOSE(fp);
  64228. DH_free(dh);
  64229. dh = NULL;
  64230. #endif
  64231. return EXPECT_RESULT();
  64232. }
  64233. static int test_wolfSSL_X509_get_serialNumber(void)
  64234. {
  64235. EXPECT_DECLS;
  64236. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  64237. ASN1_INTEGER* a = NULL;
  64238. BIGNUM* bn = NULL;
  64239. X509* x509 = NULL;
  64240. char *serialHex = NULL;
  64241. byte serial[3];
  64242. int serialSz;
  64243. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64244. SSL_FILETYPE_PEM));
  64245. ExpectNotNull(a = X509_get_serialNumber(x509));
  64246. /* check on value of ASN1 Integer */
  64247. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  64248. a = NULL;
  64249. /* test setting serial number and then retrieving it */
  64250. ExpectNotNull(a = ASN1_INTEGER_new());
  64251. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  64252. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64253. serialSz = sizeof(serial);
  64254. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64255. WOLFSSL_SUCCESS);
  64256. ExpectIntEQ(serialSz, 1);
  64257. ExpectIntEQ(serial[0], 3);
  64258. ASN1_INTEGER_free(a);
  64259. a = NULL;
  64260. /* test setting serial number with 0's in it */
  64261. serial[0] = 0x01;
  64262. serial[1] = 0x00;
  64263. serial[2] = 0x02;
  64264. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  64265. if (a != NULL) {
  64266. a->data[0] = ASN_INTEGER;
  64267. a->data[1] = sizeof(serial);
  64268. XMEMCPY(&a->data[2], serial, sizeof(serial));
  64269. a->length = sizeof(serial) + 2;
  64270. }
  64271. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64272. XMEMSET(serial, 0, sizeof(serial));
  64273. serialSz = sizeof(serial);
  64274. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64275. WOLFSSL_SUCCESS);
  64276. ExpectIntEQ(serialSz, 3);
  64277. ExpectIntEQ(serial[0], 0x01);
  64278. ExpectIntEQ(serial[1], 0x00);
  64279. ExpectIntEQ(serial[2], 0x02);
  64280. ASN1_INTEGER_free(a);
  64281. a = NULL;
  64282. X509_free(x509); /* free's a */
  64283. ExpectNotNull(serialHex = BN_bn2hex(bn));
  64284. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  64285. ExpectStrEQ(serialHex, "01");
  64286. #else
  64287. ExpectStrEQ(serialHex, "1");
  64288. #endif
  64289. OPENSSL_free(serialHex);
  64290. ExpectIntEQ(BN_get_word(bn), 1);
  64291. BN_free(bn);
  64292. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  64293. ExpectNotNull(a = ASN1_INTEGER_new());
  64294. if (a != NULL) {
  64295. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  64296. DYNAMIC_TYPE_OPENSSL));
  64297. a->isDynamic = 1;
  64298. ASN1_INTEGER_free(a);
  64299. }
  64300. #endif
  64301. return EXPECT_RESULT();
  64302. }
  64303. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  64304. {
  64305. EXPECT_DECLS;
  64306. #if defined(OPENSSL_EXTRA)
  64307. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  64308. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  64309. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  64310. #endif
  64311. return EXPECT_RESULT();
  64312. }
  64313. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  64314. {
  64315. EXPECT_DECLS;
  64316. #if defined(OPENSSL_EXTRA)
  64317. #define MAX_HEXSTR_BUFSZ 9
  64318. #define NUM_CASES 5
  64319. struct Output {
  64320. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  64321. long ret;
  64322. };
  64323. int i;
  64324. int j;
  64325. const char* inputs[NUM_CASES] = {
  64326. "aabcd1357e",
  64327. "01:12:23:34:a5:b6:c7:d8:e9",
  64328. ":01:02",
  64329. "012",
  64330. ":ab:ac:d"
  64331. };
  64332. struct Output expectedOutputs[NUM_CASES] = {
  64333. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  64334. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  64335. {{0x01, 0x02}, 2},
  64336. {{0x00}, 0},
  64337. {{0x00}, 0}
  64338. };
  64339. long len = 0;
  64340. unsigned char* returnedBuf = NULL;
  64341. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  64342. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  64343. if (returnedBuf == NULL) {
  64344. ExpectIntEQ(expectedOutputs[i].ret, 0);
  64345. continue;
  64346. }
  64347. ExpectIntEQ(expectedOutputs[i].ret, len);
  64348. for (j = 0; j < len; ++j) {
  64349. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  64350. }
  64351. OPENSSL_free(returnedBuf);
  64352. returnedBuf = NULL;
  64353. }
  64354. #endif
  64355. return EXPECT_RESULT();
  64356. }
  64357. static int test_wolfSSL_X509_CA_num(void)
  64358. {
  64359. EXPECT_DECLS;
  64360. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  64361. defined(HAVE_ECC) && !defined(NO_RSA)
  64362. WOLFSSL_X509_STORE *store = NULL;
  64363. WOLFSSL_X509 *x509_1 = NULL;
  64364. WOLFSSL_X509 *x509_2 = NULL;
  64365. int ca_num = 0;
  64366. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  64367. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64368. WOLFSSL_FILETYPE_PEM));
  64369. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  64370. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  64371. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  64372. WOLFSSL_FILETYPE_PEM));
  64373. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  64374. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  64375. wolfSSL_X509_free(x509_1);
  64376. wolfSSL_X509_free(x509_2);
  64377. wolfSSL_X509_STORE_free(store);
  64378. #endif
  64379. return EXPECT_RESULT();
  64380. }
  64381. static int test_wolfSSL_X509_check_ca(void)
  64382. {
  64383. EXPECT_DECLS;
  64384. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64385. WOLFSSL_X509 *x509 = NULL;
  64386. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64387. WOLFSSL_FILETYPE_PEM));
  64388. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  64389. wolfSSL_X509_free(x509);
  64390. #endif
  64391. return EXPECT_RESULT();
  64392. }
  64393. static int test_wolfSSL_X509_check_ip_asc(void)
  64394. {
  64395. EXPECT_DECLS;
  64396. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64397. WOLFSSL_X509 *x509 = NULL;
  64398. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  64399. WOLFSSL_FILETYPE_PEM));
  64400. #if 0
  64401. /* TODO: add cert gen for testing positive case */
  64402. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  64403. #endif
  64404. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  64405. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  64406. wolfSSL_X509_free(x509);
  64407. #endif
  64408. return EXPECT_RESULT();
  64409. }
  64410. static int test_wolfSSL_make_cert(void)
  64411. {
  64412. EXPECT_DECLS;
  64413. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  64414. defined(WOLFSSL_CERT_EXT)
  64415. int ret = 0;
  64416. Cert cert;
  64417. CertName name;
  64418. RsaKey key;
  64419. WC_RNG rng;
  64420. byte der[FOURK_BUF];
  64421. word32 idx = 0;
  64422. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  64423. #ifdef OPENSSL_EXTRA
  64424. const unsigned char* pt = NULL;
  64425. int certSz = 0;
  64426. X509* x509 = NULL;
  64427. X509_NAME* x509name = NULL;
  64428. X509_NAME_ENTRY* entry = NULL;
  64429. ASN1_STRING* entryValue = NULL;
  64430. #endif
  64431. XMEMSET(&name, 0, sizeof(CertName));
  64432. /* set up cert name */
  64433. XMEMCPY(name.country, "US", sizeof("US"));
  64434. name.countryEnc = CTC_PRINTABLE;
  64435. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  64436. name.stateEnc = CTC_UTF8;
  64437. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  64438. name.localityEnc = CTC_UTF8;
  64439. XMEMCPY(name.sur, "Test", sizeof("Test"));
  64440. name.surEnc = CTC_UTF8;
  64441. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  64442. name.orgEnc = CTC_UTF8;
  64443. XMEMCPY(name.unit, "Development", sizeof("Development"));
  64444. name.unitEnc = CTC_UTF8;
  64445. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  64446. name.commonNameEnc = CTC_UTF8;
  64447. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  64448. name.serialDevEnc = CTC_PRINTABLE;
  64449. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  64450. name.userIdEnc = CTC_PRINTABLE;
  64451. #ifdef WOLFSSL_MULTI_ATTRIB
  64452. #if CTC_MAX_ATTRIB > 2
  64453. {
  64454. NameAttrib* n;
  64455. n = &name.name[0];
  64456. n->id = ASN_DOMAIN_COMPONENT;
  64457. n->type = CTC_UTF8;
  64458. n->sz = sizeof("com");
  64459. XMEMCPY(n->value, "com", sizeof("com"));
  64460. n = &name.name[1];
  64461. n->id = ASN_DOMAIN_COMPONENT;
  64462. n->type = CTC_UTF8;
  64463. n->sz = sizeof("wolfssl");
  64464. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  64465. }
  64466. #endif
  64467. #endif /* WOLFSSL_MULTI_ATTRIB */
  64468. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  64469. #ifndef HAVE_FIPS
  64470. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  64471. #else
  64472. ExpectIntEQ(wc_InitRng(&rng), 0);
  64473. #endif
  64474. /* load test RSA key */
  64475. idx = 0;
  64476. #if defined(USE_CERT_BUFFERS_1024)
  64477. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  64478. sizeof_server_key_der_1024), 0);
  64479. #elif defined(USE_CERT_BUFFERS_2048)
  64480. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  64481. sizeof_server_key_der_2048), 0);
  64482. #else
  64483. /* error case, no RSA key loaded, happens later */
  64484. (void)idx;
  64485. #endif
  64486. XMEMSET(&cert, 0 , sizeof(Cert));
  64487. ExpectIntEQ(wc_InitCert(&cert), 0);
  64488. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  64489. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  64490. cert.serialSz = (int)sizeof(mySerial);
  64491. cert.isCA = 1;
  64492. #ifndef NO_SHA256
  64493. cert.sigType = CTC_SHA256wRSA;
  64494. #else
  64495. cert.sigType = CTC_SHAwRSA;
  64496. #endif
  64497. /* add SKID from the Public Key */
  64498. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64499. /* add AKID from the Public Key */
  64500. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64501. ret = 0;
  64502. do {
  64503. #if defined(WOLFSSL_ASYNC_CRYPT)
  64504. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  64505. #endif
  64506. if (ret >= 0) {
  64507. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  64508. }
  64509. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  64510. ExpectIntGT(ret, 0);
  64511. #ifdef OPENSSL_EXTRA
  64512. /* der holds a certificate with DC's now check X509 parsing of it */
  64513. certSz = ret;
  64514. pt = der;
  64515. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  64516. ExpectNotNull(x509name = X509_get_subject_name(x509));
  64517. #ifdef WOLFSSL_MULTI_ATTRIB
  64518. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64519. -1)), 5);
  64520. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64521. (int)idx)), 6);
  64522. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64523. (int)idx)), -1);
  64524. #endif /* WOLFSSL_MULTI_ATTRIB */
  64525. /* compare DN at index 0 */
  64526. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  64527. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64528. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  64529. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  64530. #ifndef WOLFSSL_MULTI_ATTRIB
  64531. /* compare Serial Number */
  64532. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  64533. -1)), 7);
  64534. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  64535. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64536. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  64537. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  64538. #endif
  64539. #ifdef WOLFSSL_MULTI_ATTRIB
  64540. /* get first and second DC and compare result */
  64541. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64542. -1)), 5);
  64543. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64544. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64545. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  64546. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64547. (int)idx)), 6);
  64548. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64549. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64550. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  64551. #endif /* WOLFSSL_MULTI_ATTRIB */
  64552. /* try invalid index locations for regression test and sanity check */
  64553. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  64554. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  64555. X509_free(x509);
  64556. #endif /* OPENSSL_EXTRA */
  64557. wc_FreeRsaKey(&key);
  64558. wc_FreeRng(&rng);
  64559. #endif
  64560. return EXPECT_RESULT();
  64561. }
  64562. static int test_x509_get_key_id(void)
  64563. {
  64564. EXPECT_DECLS;
  64565. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64566. X509 *x509 = NULL;
  64567. const ASN1_STRING* str = NULL;
  64568. byte* keyId = NULL;
  64569. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  64570. WOLFSSL_FILETYPE_PEM));
  64571. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  64572. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  64573. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  64574. ASN1_STRING_length(str));
  64575. X509_free(x509);
  64576. #endif
  64577. return EXPECT_RESULT();
  64578. }
  64579. static int test_wolfSSL_X509_get_version(void)
  64580. {
  64581. EXPECT_DECLS;
  64582. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64583. WOLFSSL_X509 *x509 = NULL;
  64584. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64585. WOLFSSL_FILETYPE_PEM));
  64586. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  64587. wolfSSL_X509_free(x509);
  64588. #endif
  64589. return EXPECT_RESULT();
  64590. }
  64591. #if defined(OPENSSL_ALL)
  64592. static int test_wolfSSL_sk_CIPHER_description(void)
  64593. {
  64594. EXPECT_DECLS;
  64595. #if !defined(NO_RSA)
  64596. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64597. int i;
  64598. int numCiphers = 0;
  64599. const SSL_METHOD *method = NULL;
  64600. const SSL_CIPHER *cipher = NULL;
  64601. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64602. SSL_CTX *ctx = NULL;
  64603. SSL *ssl = NULL;
  64604. char buf[256];
  64605. char test_str[9] = "0000000";
  64606. const char badStr[] = "unknown";
  64607. const char certPath[] = "./certs/client-cert.pem";
  64608. XMEMSET(buf, 0, sizeof(buf));
  64609. ExpectNotNull(method = TLSv1_2_client_method());
  64610. ExpectNotNull(ctx = SSL_CTX_new(method));
  64611. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64612. SSL_CTX_set_verify_depth(ctx, 4);
  64613. SSL_CTX_set_options(ctx, flags);
  64614. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64615. WOLFSSL_SUCCESS);
  64616. ExpectNotNull(ssl = SSL_new(ctx));
  64617. /* SSL_get_ciphers returns a stack of all configured ciphers
  64618. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  64619. */
  64620. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64621. /* loop through the amount of supportedCiphers */
  64622. numCiphers = sk_num(supportedCiphers);
  64623. for (i = 0; i < numCiphers; ++i) {
  64624. int j;
  64625. /* sk_value increments "sk->data.cipher->cipherOffset".
  64626. * wolfSSL_sk_CIPHER_description sets the description for
  64627. * the cipher based on the provided offset.
  64628. */
  64629. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  64630. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  64631. }
  64632. /* Search cipher description string for "unknown" descriptor */
  64633. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  64634. int k = 0;
  64635. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  64636. test_str[k] = badStr[k];
  64637. j++;
  64638. k++;
  64639. }
  64640. }
  64641. /* Fail if test_str == badStr == "unknown" */
  64642. ExpectStrNE(test_str,badStr);
  64643. }
  64644. SSL_free(ssl);
  64645. SSL_CTX_free(ctx);
  64646. #endif
  64647. return EXPECT_RESULT();
  64648. }
  64649. static int test_wolfSSL_get_ciphers_compat(void)
  64650. {
  64651. EXPECT_DECLS;
  64652. #if !defined(NO_RSA)
  64653. const SSL_METHOD *method = NULL;
  64654. const char certPath[] = "./certs/client-cert.pem";
  64655. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64656. SSL_CTX *ctx = NULL;
  64657. WOLFSSL *ssl = NULL;
  64658. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64659. ExpectNotNull(method = SSLv23_client_method());
  64660. ExpectNotNull(ctx = SSL_CTX_new(method));
  64661. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64662. SSL_CTX_set_verify_depth(ctx, 4);
  64663. SSL_CTX_set_options(ctx, flags);
  64664. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64665. WOLFSSL_SUCCESS);
  64666. ExpectNotNull(ssl = SSL_new(ctx));
  64667. /* Test Bad NULL input */
  64668. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  64669. /* Test for Good input */
  64670. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64671. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  64672. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  64673. SSL_free(ssl);
  64674. SSL_CTX_free(ctx);
  64675. #endif
  64676. return EXPECT_RESULT();
  64677. }
  64678. static int test_wolfSSL_X509_PUBKEY_get(void)
  64679. {
  64680. EXPECT_DECLS;
  64681. WOLFSSL_X509_PUBKEY pubkey;
  64682. WOLFSSL_X509_PUBKEY* key;
  64683. WOLFSSL_EVP_PKEY evpkey ;
  64684. WOLFSSL_EVP_PKEY* evpPkey;
  64685. WOLFSSL_EVP_PKEY* retEvpPkey;
  64686. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  64687. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  64688. key = &pubkey;
  64689. evpPkey = &evpkey;
  64690. evpPkey->type = WOLFSSL_SUCCESS;
  64691. key->pkey = evpPkey;
  64692. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64693. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  64694. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  64695. key->pkey = NULL;
  64696. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64697. return EXPECT_RESULT();
  64698. }
  64699. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  64700. {
  64701. EXPECT_DECLS;
  64702. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  64703. DSA *dsa = NULL;
  64704. DSA *setDsa = NULL;
  64705. EVP_PKEY *pkey = NULL;
  64706. EVP_PKEY *set1Pkey = NULL;
  64707. SHA_CTX sha;
  64708. byte signature[DSA_SIG_SIZE];
  64709. byte hash[WC_SHA_DIGEST_SIZE];
  64710. word32 bytes;
  64711. int answer;
  64712. #ifdef USE_CERT_BUFFERS_1024
  64713. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  64714. int dsaKeySz = sizeof_dsa_key_der_1024;
  64715. byte tmp[ONEK_BUF];
  64716. XMEMSET(tmp, 0, sizeof(tmp));
  64717. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64718. bytes = dsaKeySz;
  64719. #elif defined(USE_CERT_BUFFERS_2048)
  64720. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  64721. int dsaKeySz = sizeof_dsa_key_der_2048;
  64722. byte tmp[TWOK_BUF];
  64723. XMEMSET(tmp, 0, sizeof(tmp));
  64724. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64725. bytes = (word32)dsaKeySz;
  64726. #else
  64727. byte tmp[TWOK_BUF];
  64728. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  64729. int dsaKeySz;
  64730. XFILE fp = XBADFILE;
  64731. XMEMSET(tmp, 0, sizeof(tmp));
  64732. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  64733. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  64734. if (fp != XBADFILE)
  64735. XFCLOSE(fp);
  64736. #endif /* END USE_CERT_BUFFERS_1024 */
  64737. /* Create hash to later Sign and Verify */
  64738. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  64739. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  64740. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  64741. /* Initialize pkey with der format dsa key */
  64742. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  64743. (long)dsaKeySz));
  64744. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  64745. /* Should Fail: NULL argument */
  64746. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  64747. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  64748. /* Should Pass: Initialized pkey argument */
  64749. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  64750. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  64751. #ifdef USE_CERT_BUFFERS_1024
  64752. ExpectIntEQ(DSA_bits(dsa), 1024);
  64753. #else
  64754. ExpectIntEQ(DSA_bits(dsa), 2048);
  64755. #endif
  64756. /* Sign */
  64757. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  64758. /* Verify. */
  64759. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  64760. WOLFSSL_SUCCESS);
  64761. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  64762. /* Should Fail: set1Pkey not initialized */
  64763. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  64764. /* Initialize set1Pkey */
  64765. set1Pkey = EVP_PKEY_new();
  64766. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  64767. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  64768. WOLFSSL_SUCCESS);
  64769. /* Should Pass: set dsa into set1Pkey */
  64770. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  64771. DSA_free(dsa);
  64772. DSA_free(setDsa);
  64773. EVP_PKEY_free(pkey);
  64774. EVP_PKEY_free(set1Pkey);
  64775. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  64776. return EXPECT_RESULT();
  64777. } /* END test_EVP_PKEY_set1_get1_DSA */
  64778. static int test_wolfSSL_DSA_generate_parameters(void)
  64779. {
  64780. EXPECT_DECLS;
  64781. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  64782. !defined(HAVE_FIPS)
  64783. DSA *dsa = NULL;
  64784. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  64785. NULL));
  64786. DSA_free(dsa);
  64787. #endif
  64788. return EXPECT_RESULT();
  64789. }
  64790. static int test_wolfSSL_DSA_SIG(void)
  64791. {
  64792. EXPECT_DECLS;
  64793. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  64794. !defined(HAVE_FIPS)
  64795. DSA *dsa = NULL;
  64796. DSA *dsa2 = NULL;
  64797. DSA_SIG *sig = NULL;
  64798. const BIGNUM *p = NULL;
  64799. const BIGNUM *q = NULL;
  64800. const BIGNUM *g = NULL;
  64801. const BIGNUM *pub = NULL;
  64802. const BIGNUM *priv = NULL;
  64803. BIGNUM *dup_p = NULL;
  64804. BIGNUM *dup_q = NULL;
  64805. BIGNUM *dup_g = NULL;
  64806. BIGNUM *dup_pub = NULL;
  64807. BIGNUM *dup_priv = NULL;
  64808. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  64809. ExpectNotNull(dsa = DSA_new());
  64810. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  64811. NULL), 1);
  64812. ExpectIntEQ(DSA_generate_key(dsa), 1);
  64813. DSA_get0_pqg(dsa, &p, &q, &g);
  64814. DSA_get0_key(dsa, &pub, &priv);
  64815. ExpectNotNull(dup_p = BN_dup(p));
  64816. ExpectNotNull(dup_q = BN_dup(q));
  64817. ExpectNotNull(dup_g = BN_dup(g));
  64818. ExpectNotNull(dup_pub = BN_dup(pub));
  64819. ExpectNotNull(dup_priv = BN_dup(priv));
  64820. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  64821. ExpectNotNull(dsa2 = DSA_new());
  64822. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  64823. if (EXPECT_FAIL()) {
  64824. BN_free(dup_p);
  64825. BN_free(dup_q);
  64826. BN_free(dup_g);
  64827. }
  64828. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  64829. if (EXPECT_FAIL()) {
  64830. BN_free(dup_pub);
  64831. BN_free(dup_priv);
  64832. }
  64833. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  64834. DSA_free(dsa);
  64835. DSA_free(dsa2);
  64836. DSA_SIG_free(sig);
  64837. #endif
  64838. return EXPECT_RESULT();
  64839. }
  64840. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  64841. {
  64842. EXPECT_DECLS;
  64843. #ifdef HAVE_ECC
  64844. WOLFSSL_EC_KEY* ecKey = NULL;
  64845. WOLFSSL_EC_KEY* ecGet1 = NULL;
  64846. EVP_PKEY* pkey = NULL;
  64847. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  64848. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64849. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  64850. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64851. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64852. /* Should fail since ecKey is empty */
  64853. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64854. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  64855. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  64856. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  64857. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  64858. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  64859. wolfSSL_EC_KEY_free(ecKey);
  64860. wolfSSL_EC_KEY_free(ecGet1);
  64861. EVP_PKEY_free(pkey);
  64862. #endif /* HAVE_ECC */
  64863. return EXPECT_RESULT();
  64864. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  64865. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  64866. {
  64867. EXPECT_DECLS;
  64868. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  64869. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  64870. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  64871. DH *dh = NULL;
  64872. DH *setDh = NULL;
  64873. EVP_PKEY *pkey = NULL;
  64874. XFILE f = XBADFILE;
  64875. unsigned char buf[4096];
  64876. const unsigned char* pt = buf;
  64877. const char* dh2048 = "./certs/dh2048.der";
  64878. long len = 0;
  64879. int code = -1;
  64880. XMEMSET(buf, 0, sizeof(buf));
  64881. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  64882. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  64883. if (f != XBADFILE)
  64884. XFCLOSE(f);
  64885. /* Load dh2048.der into DH with internal format */
  64886. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  64887. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  64888. ExpectIntEQ(code, 0);
  64889. code = -1;
  64890. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  64891. /* Set DH into PKEY */
  64892. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  64893. /* Get DH from PKEY */
  64894. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  64895. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  64896. ExpectIntEQ(code, 0);
  64897. EVP_PKEY_free(pkey);
  64898. DH_free(setDh);
  64899. setDh = NULL;
  64900. DH_free(dh);
  64901. dh = NULL;
  64902. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  64903. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  64904. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  64905. return EXPECT_RESULT();
  64906. } /* END test_EVP_PKEY_set1_get1_DH */
  64907. static int test_wolfSSL_CTX_ctrl(void)
  64908. {
  64909. EXPECT_DECLS;
  64910. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  64911. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64912. char caFile[] = "./certs/client-ca.pem";
  64913. char clientFile[] = "./certs/client-cert.pem";
  64914. SSL_CTX* ctx = NULL;
  64915. X509* x509 = NULL;
  64916. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  64917. byte buf[6000];
  64918. char file[] = "./certs/dsaparams.pem";
  64919. XFILE f = XBADFILE;
  64920. int bytes = 0;
  64921. BIO* bio = NULL;
  64922. DSA* dsa = NULL;
  64923. DH* dh = NULL;
  64924. #endif
  64925. #ifdef HAVE_ECC
  64926. WOLFSSL_EC_KEY* ecKey = NULL;
  64927. #endif
  64928. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  64929. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  64930. WOLFSSL_FILETYPE_PEM));
  64931. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  64932. if (EXPECT_FAIL()) {
  64933. wolfSSL_X509_free(x509);
  64934. }
  64935. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  64936. WOLFSSL_FILETYPE_PEM));
  64937. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  64938. /* Initialize DH */
  64939. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  64940. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  64941. if (f != XBADFILE)
  64942. XFCLOSE(f);
  64943. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  64944. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  64945. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  64946. #endif
  64947. #ifdef HAVE_ECC
  64948. /* Initialize WOLFSSL_EC_KEY */
  64949. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  64950. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  64951. #endif
  64952. /* additional test of getting EVP_PKEY key size from X509
  64953. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  64954. * allowed with user RSA */
  64955. {
  64956. EVP_PKEY* pkey = NULL;
  64957. #if defined(HAVE_ECC)
  64958. X509* ecX509 = NULL;
  64959. #endif /* HAVE_ECC */
  64960. ExpectNotNull(pkey = X509_get_pubkey(x509));
  64961. /* current RSA key is 2048 bit (256 bytes) */
  64962. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  64963. EVP_PKEY_free(pkey);
  64964. pkey = NULL;
  64965. #if defined(HAVE_ECC)
  64966. #if defined(USE_CERT_BUFFERS_256)
  64967. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  64968. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  64969. SSL_FILETYPE_ASN1));
  64970. #else
  64971. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  64972. cliEccCertFile, SSL_FILETYPE_PEM));
  64973. #endif
  64974. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  64975. /* current ECC key is 256 bit (32 bytes) */
  64976. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  64977. X509_free(ecX509);
  64978. EVP_PKEY_free(pkey);
  64979. #endif /* HAVE_ECC */
  64980. }
  64981. /* Tests should fail with passed in NULL pointer */
  64982. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  64983. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64984. #if !defined(NO_DH) && !defined(NO_DSA)
  64985. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  64986. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64987. #endif
  64988. #ifdef HAVE_ECC
  64989. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  64990. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64991. #endif
  64992. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  64993. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  64994. */
  64995. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  64996. SSL_SUCCESS);
  64997. if (EXPECT_FAIL()) {
  64998. wolfSSL_X509_free(x509);
  64999. }
  65000. /* Test with SSL_CTRL_OPTIONS
  65001. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  65002. */
  65003. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  65004. NULL) == SSL_OP_NO_TLSv1);
  65005. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  65006. /* Test with SSL_CTRL_SET_TMP_DH
  65007. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  65008. */
  65009. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65010. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  65011. SSL_SUCCESS);
  65012. #endif
  65013. /* Test with SSL_CTRL_SET_TMP_ECDH
  65014. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  65015. */
  65016. #ifdef HAVE_ECC
  65017. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  65018. SSL_SUCCESS);
  65019. #endif
  65020. #ifdef WOLFSSL_ENCRYPTED_KEYS
  65021. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  65022. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  65023. #endif
  65024. /* Test for min/max proto */
  65025. #ifndef WOLFSSL_NO_TLS12
  65026. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65027. 0, NULL), SSL_SUCCESS);
  65028. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65029. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65030. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  65031. #endif
  65032. #ifdef WOLFSSL_TLS13
  65033. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65034. 0, NULL), SSL_SUCCESS);
  65035. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65036. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  65037. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  65038. #ifndef WOLFSSL_NO_TLS12
  65039. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65040. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65041. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  65042. #endif
  65043. #endif
  65044. /* Cleanup and Pass */
  65045. #if !defined(NO_DH) && !defined(NO_DSA)
  65046. #ifndef NO_BIO
  65047. BIO_free(bio);
  65048. DSA_free(dsa);
  65049. DH_free(dh);
  65050. dh = NULL;
  65051. #endif
  65052. #endif
  65053. #ifdef HAVE_ECC
  65054. wolfSSL_EC_KEY_free(ecKey);
  65055. #endif
  65056. SSL_CTX_free(ctx);
  65057. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65058. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  65059. return EXPECT_RESULT();
  65060. }
  65061. static int test_wolfSSL_EVP_PKEY_assign(void)
  65062. {
  65063. EXPECT_DECLS;
  65064. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  65065. int type;
  65066. WOLFSSL_EVP_PKEY* pkey = NULL;
  65067. #ifndef NO_RSA
  65068. WOLFSSL_RSA* rsa = NULL;
  65069. #endif
  65070. #ifndef NO_DSA
  65071. WOLFSSL_DSA* dsa = NULL;
  65072. #endif
  65073. #ifdef HAVE_ECC
  65074. WOLFSSL_EC_KEY* ecKey = NULL;
  65075. #endif
  65076. #ifndef NO_RSA
  65077. type = EVP_PKEY_RSA;
  65078. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65079. ExpectNotNull(rsa = wolfSSL_RSA_new());
  65080. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65081. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65082. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65083. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  65084. if (EXPECT_FAIL()) {
  65085. wolfSSL_RSA_free(rsa);
  65086. }
  65087. wolfSSL_EVP_PKEY_free(pkey);
  65088. pkey = NULL;
  65089. #endif /* NO_RSA */
  65090. #ifndef NO_DSA
  65091. type = EVP_PKEY_DSA;
  65092. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65093. ExpectNotNull(dsa = wolfSSL_DSA_new());
  65094. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65095. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65096. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65097. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  65098. if (EXPECT_FAIL()) {
  65099. wolfSSL_DSA_free(dsa);
  65100. }
  65101. wolfSSL_EVP_PKEY_free(pkey);
  65102. pkey = NULL;
  65103. #endif /* NO_DSA */
  65104. #ifdef HAVE_ECC
  65105. type = EVP_PKEY_EC;
  65106. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65107. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65108. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65109. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65110. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65111. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65112. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65113. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  65114. if (EXPECT_FAIL()) {
  65115. wolfSSL_EC_KEY_free(ecKey);
  65116. }
  65117. wolfSSL_EVP_PKEY_free(pkey);
  65118. pkey = NULL;
  65119. #endif /* HAVE_ECC */
  65120. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  65121. return EXPECT_RESULT();
  65122. }
  65123. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  65124. {
  65125. EXPECT_DECLS;
  65126. #if !defined(NO_DH) && \
  65127. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65128. XFILE f = XBADFILE;
  65129. unsigned char buf[4096];
  65130. const unsigned char* pt = buf;
  65131. const char* params1 = "./certs/dh2048.der";
  65132. long len = 0;
  65133. WOLFSSL_DH* dh = NULL;
  65134. WOLFSSL_EVP_PKEY* pkey = NULL;
  65135. XMEMSET(buf, 0, sizeof(buf));
  65136. /* Load DH parameters DER. */
  65137. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  65138. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65139. if (f != XBADFILE)
  65140. XFCLOSE(f);
  65141. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65142. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  65143. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65144. /* Bad cases */
  65145. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65146. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65147. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65148. /* Good case */
  65149. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  65150. if (EXPECT_FAIL()) {
  65151. wolfSSL_DH_free(dh);
  65152. }
  65153. EVP_PKEY_free(pkey);
  65154. #endif
  65155. return EXPECT_RESULT();
  65156. }
  65157. static int test_wolfSSL_EVP_PKEY_base_id(void)
  65158. {
  65159. EXPECT_DECLS;
  65160. WOLFSSL_EVP_PKEY* pkey = NULL;
  65161. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65162. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  65163. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  65164. EVP_PKEY_free(pkey);
  65165. return EXPECT_RESULT();
  65166. }
  65167. static int test_wolfSSL_EVP_PKEY_id(void)
  65168. {
  65169. EXPECT_DECLS;
  65170. WOLFSSL_EVP_PKEY* pkey = NULL;
  65171. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65172. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  65173. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  65174. EVP_PKEY_free(pkey);
  65175. return EXPECT_RESULT();
  65176. }
  65177. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  65178. {
  65179. EXPECT_DECLS;
  65180. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  65181. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  65182. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  65183. ECC_MIN_KEY_SZ <= 256)
  65184. EVP_PKEY_CTX* ctx = NULL;
  65185. EVP_PKEY* pkey = NULL;
  65186. /* Test error conditions. */
  65187. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65188. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65189. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65190. #ifndef NO_RSA
  65191. EVP_PKEY_CTX_free(ctx);
  65192. /* Parameter generation for RSA not supported yet. */
  65193. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  65194. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65195. #endif
  65196. #ifdef HAVE_ECC
  65197. EVP_PKEY_CTX_free(ctx);
  65198. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65199. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  65200. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  65201. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  65202. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  65203. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  65204. WOLFSSL_SUCCESS);
  65205. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65206. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65207. #endif
  65208. EVP_PKEY_CTX_free(ctx);
  65209. EVP_PKEY_free(pkey);
  65210. #endif
  65211. return EXPECT_RESULT();
  65212. }
  65213. static int test_wolfSSL_EVP_PKEY_keygen(void)
  65214. {
  65215. EXPECT_DECLS;
  65216. WOLFSSL_EVP_PKEY* pkey = NULL;
  65217. EVP_PKEY_CTX* ctx = NULL;
  65218. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65219. WOLFSSL_EVP_PKEY* params = NULL;
  65220. DH* dh = NULL;
  65221. const BIGNUM* pubkey = NULL;
  65222. const BIGNUM* privkey = NULL;
  65223. ASN1_INTEGER* asn1int = NULL;
  65224. unsigned int length = 0;
  65225. byte* derBuffer = NULL;
  65226. #endif
  65227. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65228. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65229. /* Bad cases */
  65230. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  65231. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  65232. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  65233. /* Good case */
  65234. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  65235. EVP_PKEY_CTX_free(ctx);
  65236. ctx = NULL;
  65237. EVP_PKEY_free(pkey);
  65238. pkey = NULL;
  65239. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65240. /* Test DH keygen */
  65241. {
  65242. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65243. ExpectNotNull(dh = DH_get_2048_256());
  65244. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65245. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  65246. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65247. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65248. DH_free(dh);
  65249. dh = NULL;
  65250. EVP_PKEY_CTX_free(ctx);
  65251. EVP_PKEY_free(params);
  65252. /* try exporting generated key to DER, to verify */
  65253. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  65254. DH_get0_key(dh, &pubkey, &privkey);
  65255. ExpectNotNull(pubkey);
  65256. ExpectNotNull(privkey);
  65257. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  65258. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  65259. ASN1_INTEGER_free(asn1int);
  65260. DH_free(dh);
  65261. dh = NULL;
  65262. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  65263. EVP_PKEY_free(pkey);
  65264. }
  65265. #endif
  65266. return EXPECT_RESULT();
  65267. }
  65268. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  65269. {
  65270. EXPECT_DECLS;
  65271. WOLFSSL_EVP_PKEY* pkey = NULL;
  65272. EVP_PKEY_CTX *ctx = NULL;
  65273. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65274. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65275. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65276. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  65277. EVP_PKEY_CTX_free(ctx);
  65278. EVP_PKEY_free(pkey);
  65279. return EXPECT_RESULT();
  65280. }
  65281. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  65282. {
  65283. EXPECT_DECLS;
  65284. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  65285. WOLFSSL_EVP_PKEY* pkey = NULL;
  65286. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65287. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  65288. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  65289. EVP_PKEY_free(pkey);
  65290. #endif
  65291. return EXPECT_RESULT();
  65292. }
  65293. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  65294. {
  65295. EXPECT_DECLS;
  65296. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  65297. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  65298. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  65299. !defined(NO_FILESYSTEM)
  65300. WOLFSSL_EVP_PKEY* params = NULL;
  65301. WOLFSSL_EVP_PKEY* copy = NULL;
  65302. DH* dh = NULL;
  65303. BIGNUM* p1;
  65304. BIGNUM* g1;
  65305. BIGNUM* q1;
  65306. BIGNUM* p2;
  65307. BIGNUM* g2;
  65308. BIGNUM* q2;
  65309. /* create DH with DH_get_2048_256 params */
  65310. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65311. ExpectNotNull(dh = DH_get_2048_256());
  65312. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65313. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  65314. (const BIGNUM**)&q1,
  65315. (const BIGNUM**)&g1);
  65316. DH_free(dh);
  65317. dh = NULL;
  65318. /* create DH with random generated DH params */
  65319. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  65320. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  65321. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  65322. DH_free(dh);
  65323. dh = NULL;
  65324. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  65325. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  65326. ExpectNotNull(dh->p);
  65327. ExpectNotNull(dh->g);
  65328. ExpectNotNull(dh->q);
  65329. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  65330. (const BIGNUM**)&q2,
  65331. (const BIGNUM**)&g2);
  65332. ExpectIntEQ(BN_cmp(p1, p2), 0);
  65333. ExpectIntEQ(BN_cmp(q1, q2), 0);
  65334. ExpectIntEQ(BN_cmp(g1, g2), 0);
  65335. DH_free(dh);
  65336. dh = NULL;
  65337. EVP_PKEY_free(copy);
  65338. EVP_PKEY_free(params);
  65339. #endif
  65340. return EXPECT_RESULT();
  65341. }
  65342. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  65343. {
  65344. EXPECT_DECLS;
  65345. WOLFSSL_EVP_PKEY* pkey = NULL;
  65346. EVP_PKEY_CTX* ctx = NULL;
  65347. int bits = 2048;
  65348. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65349. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65350. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  65351. WOLFSSL_SUCCESS);
  65352. EVP_PKEY_CTX_free(ctx);
  65353. EVP_PKEY_free(pkey);
  65354. return EXPECT_RESULT();
  65355. }
  65356. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  65357. {
  65358. EXPECT_DECLS;
  65359. /* This is large enough to be used for all key sizes */
  65360. byte key[AES_256_KEY_SIZE] = {0};
  65361. byte iv[AES_BLOCK_SIZE] = {0};
  65362. int i;
  65363. int nids[] = {
  65364. #ifdef HAVE_AES_CBC
  65365. NID_aes_128_cbc,
  65366. #endif
  65367. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65368. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65369. #ifdef HAVE_AESGCM
  65370. NID_aes_128_gcm,
  65371. #endif
  65372. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65373. #ifdef WOLFSSL_AES_COUNTER
  65374. NID_aes_128_ctr,
  65375. #endif
  65376. #ifndef NO_DES3
  65377. NID_des_cbc,
  65378. NID_des_ede3_cbc,
  65379. #endif
  65380. };
  65381. int iv_lengths[] = {
  65382. #ifdef HAVE_AES_CBC
  65383. AES_BLOCK_SIZE,
  65384. #endif
  65385. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65386. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65387. #ifdef HAVE_AESGCM
  65388. GCM_NONCE_MID_SZ,
  65389. #endif
  65390. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65391. #ifdef WOLFSSL_AES_COUNTER
  65392. AES_BLOCK_SIZE,
  65393. #endif
  65394. #ifndef NO_DES3
  65395. DES_BLOCK_SIZE,
  65396. DES_BLOCK_SIZE,
  65397. #endif
  65398. };
  65399. int nidsLen = (sizeof(nids)/sizeof(int));
  65400. for (i = 0; i < nidsLen; i++) {
  65401. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65402. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65403. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65404. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65405. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  65406. EVP_CIPHER_CTX_free(ctx);
  65407. }
  65408. return EXPECT_RESULT();
  65409. }
  65410. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  65411. {
  65412. EXPECT_DECLS;
  65413. byte key[AES_256_KEY_SIZE] = {0};
  65414. byte iv[AES_BLOCK_SIZE] = {0};
  65415. int i;
  65416. int nids[] = {
  65417. #ifdef HAVE_AES_CBC
  65418. NID_aes_128_cbc,
  65419. NID_aes_256_cbc,
  65420. #endif
  65421. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65422. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65423. #ifdef HAVE_AESGCM
  65424. NID_aes_128_gcm,
  65425. NID_aes_256_gcm,
  65426. #endif
  65427. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65428. #ifdef WOLFSSL_AES_COUNTER
  65429. NID_aes_128_ctr,
  65430. NID_aes_256_ctr,
  65431. #endif
  65432. #ifndef NO_DES3
  65433. NID_des_cbc,
  65434. NID_des_ede3_cbc,
  65435. #endif
  65436. };
  65437. int key_lengths[] = {
  65438. #ifdef HAVE_AES_CBC
  65439. AES_128_KEY_SIZE,
  65440. AES_256_KEY_SIZE,
  65441. #endif
  65442. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65443. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65444. #ifdef HAVE_AESGCM
  65445. AES_128_KEY_SIZE,
  65446. AES_256_KEY_SIZE,
  65447. #endif
  65448. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65449. #ifdef WOLFSSL_AES_COUNTER
  65450. AES_128_KEY_SIZE,
  65451. AES_256_KEY_SIZE,
  65452. #endif
  65453. #ifndef NO_DES3
  65454. DES_KEY_SIZE,
  65455. DES3_KEY_SIZE,
  65456. #endif
  65457. };
  65458. int nidsLen = (sizeof(nids)/sizeof(int));
  65459. for (i = 0; i < nidsLen; i++) {
  65460. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65461. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65462. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65463. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65464. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  65465. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  65466. WOLFSSL_SUCCESS);
  65467. EVP_CIPHER_CTX_free(ctx);
  65468. }
  65469. return EXPECT_RESULT();
  65470. }
  65471. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  65472. {
  65473. EXPECT_DECLS;
  65474. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  65475. int ivLen, keyLen;
  65476. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  65477. #ifdef HAVE_AESGCM
  65478. byte key[AES_128_KEY_SIZE] = {0};
  65479. byte iv[AES_BLOCK_SIZE] = {0};
  65480. const EVP_CIPHER *init = EVP_aes_128_gcm();
  65481. #else
  65482. byte key[DES3_KEY_SIZE] = {0};
  65483. byte iv[DES_BLOCK_SIZE] = {0};
  65484. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  65485. #endif
  65486. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65487. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65488. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  65489. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  65490. /* Bad cases */
  65491. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  65492. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65493. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  65494. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65495. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65496. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65497. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  65498. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65499. /* Good case */
  65500. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  65501. EVP_CIPHER_CTX_free(ctx);
  65502. #endif
  65503. return EXPECT_RESULT();
  65504. }
  65505. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  65506. {
  65507. EXPECT_DECLS;
  65508. WOLFSSL_ENGINE* e = NULL;
  65509. int id = 0;
  65510. EVP_PKEY_CTX *ctx = NULL;
  65511. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  65512. EVP_PKEY_CTX_free(ctx);
  65513. return EXPECT_RESULT();
  65514. }
  65515. static int test_wolfSSL_EVP_rc4(void)
  65516. {
  65517. EXPECT_DECLS;
  65518. #if !defined(NO_RC4)
  65519. ExpectNotNull(wolfSSL_EVP_rc4());
  65520. #endif
  65521. return EXPECT_RESULT();
  65522. }
  65523. static int test_wolfSSL_EVP_enc_null(void)
  65524. {
  65525. EXPECT_DECLS;
  65526. ExpectNotNull(wolfSSL_EVP_enc_null());
  65527. return EXPECT_RESULT();
  65528. }
  65529. static int test_wolfSSL_EVP_rc2_cbc(void)
  65530. {
  65531. EXPECT_DECLS;
  65532. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  65533. ExpectNull(wolfSSL_EVP_rc2_cbc());
  65534. #endif
  65535. return EXPECT_RESULT();
  65536. }
  65537. static int test_wolfSSL_EVP_mdc2(void)
  65538. {
  65539. EXPECT_DECLS;
  65540. #if !defined(NO_WOLFSSL_STUB)
  65541. ExpectNull(wolfSSL_EVP_mdc2());
  65542. #endif
  65543. return EXPECT_RESULT();
  65544. }
  65545. static int test_wolfSSL_EVP_md4(void)
  65546. {
  65547. EXPECT_DECLS;
  65548. #if !defined(NO_MD4)
  65549. ExpectNotNull(wolfSSL_EVP_md4());
  65550. #endif
  65551. return EXPECT_RESULT();
  65552. }
  65553. static int test_wolfSSL_EVP_aes_256_gcm(void)
  65554. {
  65555. EXPECT_DECLS;
  65556. #ifdef HAVE_AESGCM
  65557. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  65558. #endif
  65559. return EXPECT_RESULT();
  65560. }
  65561. static int test_wolfSSL_EVP_aes_192_gcm(void)
  65562. {
  65563. EXPECT_DECLS;
  65564. #ifdef HAVE_AESGCM
  65565. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  65566. #endif
  65567. return EXPECT_RESULT();
  65568. }
  65569. static int test_wolfSSL_EVP_aes_256_ccm(void)
  65570. {
  65571. EXPECT_DECLS;
  65572. #ifdef HAVE_AESCCM
  65573. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  65574. #endif
  65575. return EXPECT_RESULT();
  65576. }
  65577. static int test_wolfSSL_EVP_aes_192_ccm(void)
  65578. {
  65579. EXPECT_DECLS;
  65580. #ifdef HAVE_AESCCM
  65581. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  65582. #endif
  65583. return EXPECT_RESULT();
  65584. }
  65585. static int test_wolfSSL_EVP_aes_128_ccm(void)
  65586. {
  65587. EXPECT_DECLS;
  65588. #ifdef HAVE_AESCCM
  65589. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  65590. #endif
  65591. return EXPECT_RESULT();
  65592. }
  65593. static int test_wolfSSL_EVP_ripemd160(void)
  65594. {
  65595. EXPECT_DECLS;
  65596. #if !defined(NO_WOLFSSL_STUB)
  65597. ExpectNull(wolfSSL_EVP_ripemd160());
  65598. #endif
  65599. return EXPECT_RESULT();
  65600. }
  65601. static int test_wolfSSL_EVP_get_digestbynid(void)
  65602. {
  65603. EXPECT_DECLS;
  65604. #ifndef NO_MD5
  65605. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  65606. #endif
  65607. #ifndef NO_SHA
  65608. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  65609. #endif
  65610. #ifndef NO_SHA256
  65611. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  65612. #endif
  65613. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  65614. return EXPECT_RESULT();
  65615. }
  65616. static int test_wolfSSL_EVP_MD_nid(void)
  65617. {
  65618. EXPECT_DECLS;
  65619. #ifndef NO_MD5
  65620. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  65621. #endif
  65622. #ifndef NO_SHA
  65623. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  65624. #endif
  65625. #ifndef NO_SHA256
  65626. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  65627. #endif
  65628. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  65629. return EXPECT_RESULT();
  65630. }
  65631. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  65632. {
  65633. EXPECT_DECLS;
  65634. #if defined(HAVE_ECC)
  65635. WOLFSSL_EVP_PKEY* pkey = NULL;
  65636. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  65637. ExpectNotNull(pkey = EVP_PKEY_new());
  65638. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  65639. EVP_PKEY_free(pkey);
  65640. #endif
  65641. return EXPECT_RESULT();
  65642. }
  65643. static int test_wolfSSL_EVP_X_STATE(void)
  65644. {
  65645. EXPECT_DECLS;
  65646. #if !defined(NO_DES3) && !defined(NO_RC4)
  65647. byte key[DES3_KEY_SIZE] = {0};
  65648. byte iv[DES_IV_SIZE] = {0};
  65649. EVP_CIPHER_CTX *ctx = NULL;
  65650. const EVP_CIPHER *init = NULL;
  65651. /* Bad test cases */
  65652. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65653. ExpectNotNull(init = EVP_des_ede3_cbc());
  65654. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65655. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65656. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  65657. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  65658. EVP_CIPHER_CTX_free(ctx);
  65659. ctx = NULL;
  65660. /* Good test case */
  65661. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65662. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65663. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65664. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65665. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  65666. EVP_CIPHER_CTX_free(ctx);
  65667. #endif
  65668. return EXPECT_RESULT();
  65669. }
  65670. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  65671. {
  65672. EXPECT_DECLS;
  65673. #if !defined(NO_DES3) && !defined(NO_RC4)
  65674. byte key[DES3_KEY_SIZE] = {0};
  65675. byte iv[DES_IV_SIZE] = {0};
  65676. EVP_CIPHER_CTX *ctx = NULL;
  65677. const EVP_CIPHER *init = NULL;
  65678. /* Bad test cases */
  65679. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65680. ExpectNotNull(init = EVP_des_ede3_cbc());
  65681. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65682. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65683. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  65684. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  65685. EVP_CIPHER_CTX_free(ctx);
  65686. ctx = NULL;
  65687. /* Good test case */
  65688. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65689. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65690. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65691. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65692. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  65693. EVP_CIPHER_CTX_free(ctx);
  65694. #endif
  65695. return EXPECT_RESULT();
  65696. }
  65697. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  65698. {
  65699. EXPECT_DECLS;
  65700. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  65701. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  65702. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  65703. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  65704. #ifdef HAVE_AES_CBC
  65705. #ifdef WOLFSSL_AES_128
  65706. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  65707. #endif
  65708. #ifdef WOLFSSL_AES_192
  65709. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  65710. #endif
  65711. #ifdef WOLFSSL_AES_256
  65712. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  65713. #endif
  65714. #endif
  65715. #ifdef HAVE_AESGCM
  65716. #ifdef WOLFSSL_AES_128
  65717. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  65718. #endif
  65719. #ifdef WOLFSSL_AES_192
  65720. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  65721. #endif
  65722. #ifdef WOLFSSL_AES_256
  65723. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  65724. #endif
  65725. #endif
  65726. #ifdef HAVE_AESCCM
  65727. #ifdef WOLFSSL_AES_128
  65728. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  65729. #endif
  65730. #ifdef WOLFSSL_AES_192
  65731. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  65732. #endif
  65733. #ifdef WOLFSSL_AES_256
  65734. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  65735. #endif
  65736. #endif
  65737. #ifdef WOLFSSL_AES_COUNTER
  65738. #ifdef WOLFSSL_AES_128
  65739. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  65740. #endif
  65741. #ifdef WOLFSSL_AES_192
  65742. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  65743. #endif
  65744. #ifdef WOLFSSL_AES_256
  65745. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  65746. #endif
  65747. #endif
  65748. #ifdef HAVE_AES_ECB
  65749. #ifdef WOLFSSL_AES_128
  65750. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  65751. #endif
  65752. #ifdef WOLFSSL_AES_192
  65753. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  65754. #endif
  65755. #ifdef WOLFSSL_AES_256
  65756. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  65757. #endif
  65758. #endif
  65759. #ifdef WOLFSSL_AES_OFB
  65760. #ifdef WOLFSSL_AES_128
  65761. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  65762. #endif
  65763. #ifdef WOLFSSL_AES_192
  65764. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  65765. #endif
  65766. #ifdef WOLFSSL_AES_256
  65767. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  65768. #endif
  65769. #endif
  65770. #ifndef NO_RC4
  65771. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  65772. #endif
  65773. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65774. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  65775. #endif
  65776. #endif
  65777. #ifdef WOLFSSL_SM4_ECB
  65778. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  65779. #endif
  65780. #ifdef WOLFSSL_SM4_CBC
  65781. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  65782. #endif
  65783. #ifdef WOLFSSL_SM4_CTR
  65784. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  65785. #endif
  65786. #ifdef WOLFSSL_SM4_GCM
  65787. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  65788. #endif
  65789. #ifdef WOLFSSL_SM4_CCM
  65790. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  65791. #endif
  65792. return EXPECT_RESULT();
  65793. }
  65794. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  65795. {
  65796. EXPECT_DECLS;
  65797. int nids[] = {
  65798. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  65799. #ifdef WOLFSSL_AES_128
  65800. NID_aes_128_cbc,
  65801. #endif
  65802. #ifdef WOLFSSL_AES_192
  65803. NID_aes_192_cbc,
  65804. #endif
  65805. #ifdef WOLFSSL_AES_256
  65806. NID_aes_256_cbc,
  65807. #endif
  65808. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  65809. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65810. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65811. #ifdef HAVE_AESGCM
  65812. #ifdef WOLFSSL_AES_128
  65813. NID_aes_128_gcm,
  65814. #endif
  65815. #ifdef WOLFSSL_AES_192
  65816. NID_aes_192_gcm,
  65817. #endif
  65818. #ifdef WOLFSSL_AES_256
  65819. NID_aes_256_gcm,
  65820. #endif
  65821. #endif /* HAVE_AESGCM */
  65822. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65823. #ifdef WOLFSSL_AES_COUNTER
  65824. #ifdef WOLFSSL_AES_128
  65825. NID_aes_128_ctr,
  65826. #endif
  65827. #ifdef WOLFSSL_AES_192
  65828. NID_aes_192_ctr,
  65829. #endif
  65830. #ifdef WOLFSSL_AES_256
  65831. NID_aes_256_ctr,
  65832. #endif
  65833. #endif
  65834. #ifndef NO_DES3
  65835. NID_des_cbc,
  65836. NID_des_ede3_cbc,
  65837. #endif
  65838. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65839. NID_chacha20_poly1305,
  65840. #endif
  65841. };
  65842. int iv_lengths[] = {
  65843. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  65844. #ifdef WOLFSSL_AES_128
  65845. AES_BLOCK_SIZE,
  65846. #endif
  65847. #ifdef WOLFSSL_AES_192
  65848. AES_BLOCK_SIZE,
  65849. #endif
  65850. #ifdef WOLFSSL_AES_256
  65851. AES_BLOCK_SIZE,
  65852. #endif
  65853. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  65854. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65855. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65856. #ifdef HAVE_AESGCM
  65857. #ifdef WOLFSSL_AES_128
  65858. GCM_NONCE_MID_SZ,
  65859. #endif
  65860. #ifdef WOLFSSL_AES_192
  65861. GCM_NONCE_MID_SZ,
  65862. #endif
  65863. #ifdef WOLFSSL_AES_256
  65864. GCM_NONCE_MID_SZ,
  65865. #endif
  65866. #endif /* HAVE_AESGCM */
  65867. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65868. #ifdef WOLFSSL_AES_COUNTER
  65869. #ifdef WOLFSSL_AES_128
  65870. AES_BLOCK_SIZE,
  65871. #endif
  65872. #ifdef WOLFSSL_AES_192
  65873. AES_BLOCK_SIZE,
  65874. #endif
  65875. #ifdef WOLFSSL_AES_256
  65876. AES_BLOCK_SIZE,
  65877. #endif
  65878. #endif
  65879. #ifndef NO_DES3
  65880. DES_BLOCK_SIZE,
  65881. DES_BLOCK_SIZE,
  65882. #endif
  65883. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  65884. CHACHA20_POLY1305_AEAD_IV_SIZE,
  65885. #endif
  65886. };
  65887. int i;
  65888. int nidsLen = (sizeof(nids)/sizeof(int));
  65889. for (i = 0; i < nidsLen; i++) {
  65890. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  65891. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  65892. }
  65893. return EXPECT_RESULT();
  65894. }
  65895. static int test_wolfSSL_EVP_SignInit_ex(void)
  65896. {
  65897. EXPECT_DECLS;
  65898. WOLFSSL_EVP_MD_CTX mdCtx;
  65899. WOLFSSL_ENGINE* e = 0;
  65900. const EVP_MD* md = EVP_sha256();
  65901. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65902. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  65903. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  65904. return EXPECT_RESULT();
  65905. }
  65906. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  65907. {
  65908. EXPECT_DECLS;
  65909. #if !defined(NO_SHA256)
  65910. WOLFSSL_EVP_MD_CTX mdCtx;
  65911. unsigned int s = 0;
  65912. unsigned char md[WC_SHA256_DIGEST_SIZE];
  65913. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  65914. /* Bad Case */
  65915. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  65916. (HAVE_FIPS_VERSION > 2))
  65917. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65918. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  65919. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  65920. #else
  65921. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65922. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  65923. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  65924. #endif
  65925. /* Good Case */
  65926. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  65927. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  65928. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  65929. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  65930. #endif
  65931. return EXPECT_RESULT();
  65932. }
  65933. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  65934. {
  65935. EXPECT_DECLS;
  65936. #if defined(OPENSSL_EXTRA)
  65937. EVP_PKEY* pkey = NULL;
  65938. EVP_PKEY_CTX* ctx = NULL;
  65939. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65940. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65941. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  65942. /* void */
  65943. EVP_PKEY_CTX_free(ctx);
  65944. #else
  65945. /* int */
  65946. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  65947. #endif
  65948. EVP_PKEY_free(pkey);
  65949. #endif
  65950. return EXPECT_RESULT();
  65951. }
  65952. static int test_wolfSSL_EVP_PKEY_param_check(void)
  65953. {
  65954. EXPECT_DECLS;
  65955. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  65956. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  65957. DH *dh = NULL;
  65958. DH *setDh = NULL;
  65959. EVP_PKEY *pkey = NULL;
  65960. EVP_PKEY_CTX* ctx = NULL;
  65961. FILE* f = NULL;
  65962. unsigned char buf[512];
  65963. const unsigned char* pt = buf;
  65964. const char* dh2048 = "./certs/dh2048.der";
  65965. long len = 0;
  65966. int code = -1;
  65967. XMEMSET(buf, 0, sizeof(buf));
  65968. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  65969. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65970. if (f != XBADFILE)
  65971. XFCLOSE(f);
  65972. /* Load dh2048.der into DH with internal format */
  65973. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  65974. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  65975. ExpectIntEQ(code, 0);
  65976. code = -1;
  65977. pkey = wolfSSL_EVP_PKEY_new();
  65978. /* Set DH into PKEY */
  65979. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  65980. /* create ctx from pkey */
  65981. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65982. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  65983. /* TODO: more invalid cases */
  65984. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  65985. EVP_PKEY_CTX_free(ctx);
  65986. EVP_PKEY_free(pkey);
  65987. DH_free(setDh);
  65988. setDh = NULL;
  65989. DH_free(dh);
  65990. dh = NULL;
  65991. #endif
  65992. #endif
  65993. return EXPECT_RESULT();
  65994. }
  65995. static int test_wolfSSL_EVP_BytesToKey(void)
  65996. {
  65997. EXPECT_DECLS;
  65998. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  65999. byte key[AES_BLOCK_SIZE] = {0};
  66000. byte iv[AES_BLOCK_SIZE] = {0};
  66001. int count = 0;
  66002. const EVP_MD* md = EVP_sha256();
  66003. const EVP_CIPHER *type;
  66004. const unsigned char *salt = (unsigned char *)"salt1234";
  66005. int sz = 5;
  66006. const byte data[] = {
  66007. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  66008. 0x72,0x6c,0x64
  66009. };
  66010. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  66011. /* Bad cases */
  66012. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  66013. 0);
  66014. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  66015. 16);
  66016. md = "2";
  66017. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66018. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66019. /* Good case */
  66020. md = EVP_sha256();
  66021. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66022. 16);
  66023. #endif
  66024. return EXPECT_RESULT();
  66025. }
  66026. static int test_evp_cipher_aes_gcm(void)
  66027. {
  66028. EXPECT_DECLS;
  66029. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  66030. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  66031. (HAVE_FIPS_VERSION >= 2)))
  66032. /*
  66033. * This test checks data at various points in the encrypt/decrypt process
  66034. * against known values produced using the same test with OpenSSL. This
  66035. * interop testing is critical for verifying the correctness of our
  66036. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  66037. * a flow supported by OpenSSL that uses the control command
  66038. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  66039. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  66040. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  66041. * wolfSSL OpenSSH clients because there was a bug in this flow that
  66042. * happened to "cancel out" if both sides of the connection had the bug.
  66043. */
  66044. enum {
  66045. NUM_ENCRYPTIONS = 3,
  66046. AAD_SIZE = 4
  66047. };
  66048. byte plainText1[] = {
  66049. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  66050. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  66051. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  66052. };
  66053. byte plainText2[] = {
  66054. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  66055. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  66056. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  66057. };
  66058. byte plainText3[] = {
  66059. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  66060. 0x5b, 0x57, 0x10
  66061. };
  66062. byte* plainTexts[NUM_ENCRYPTIONS] = {
  66063. plainText1,
  66064. plainText2,
  66065. plainText3
  66066. };
  66067. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  66068. sizeof(plainText1),
  66069. sizeof(plainText2),
  66070. sizeof(plainText3)
  66071. };
  66072. byte aad1[AAD_SIZE] = {
  66073. 0x00, 0x00, 0x00, 0x01
  66074. };
  66075. byte aad2[AAD_SIZE] = {
  66076. 0x00, 0x00, 0x00, 0x10
  66077. };
  66078. byte aad3[AAD_SIZE] = {
  66079. 0x00, 0x00, 0x01, 0x00
  66080. };
  66081. byte* aads[NUM_ENCRYPTIONS] = {
  66082. aad1,
  66083. aad2,
  66084. aad3
  66085. };
  66086. const byte iv[GCM_NONCE_MID_SZ] = {
  66087. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  66088. };
  66089. byte currentIv[GCM_NONCE_MID_SZ];
  66090. const byte key[] = {
  66091. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  66092. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  66093. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  66094. };
  66095. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  66096. {
  66097. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66098. 0xEF
  66099. },
  66100. {
  66101. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66102. 0xF0
  66103. },
  66104. {
  66105. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66106. 0xF1
  66107. }
  66108. };
  66109. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  66110. {
  66111. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  66112. 0x3D, 0x32, 0x18, 0x34, 0xA9
  66113. },
  66114. {
  66115. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  66116. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  66117. },
  66118. {
  66119. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  66120. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  66121. }
  66122. };
  66123. const byte expCipherText1[] = {
  66124. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  66125. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  66126. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  66127. };
  66128. const byte expCipherText2[] = {
  66129. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  66130. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  66131. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  66132. };
  66133. const byte expCipherText3[] = {
  66134. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  66135. 0x80, 0x5E, 0x6B,
  66136. };
  66137. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  66138. expCipherText1,
  66139. expCipherText2,
  66140. expCipherText3
  66141. };
  66142. byte* cipherText = NULL;
  66143. byte* calcPlainText = NULL;
  66144. byte tag[AES_BLOCK_SIZE];
  66145. EVP_CIPHER_CTX* encCtx = NULL;
  66146. EVP_CIPHER_CTX* decCtx = NULL;
  66147. int i, j, outl;
  66148. /****************************************************/
  66149. for (i = 0; i < 3; ++i) {
  66150. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  66151. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  66152. /* First iteration, set key before IV. */
  66153. if (i == 0) {
  66154. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  66155. SSL_SUCCESS);
  66156. /*
  66157. * The call to EVP_CipherInit below (with NULL key) should clear the
  66158. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  66159. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  66160. * behavior.
  66161. */
  66162. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66163. (void*)iv), SSL_SUCCESS);
  66164. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  66165. SSL_SUCCESS);
  66166. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66167. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66168. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  66169. SSL_SUCCESS);
  66170. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  66171. SSL_SUCCESS);
  66172. }
  66173. /* Second iteration, IV before key. */
  66174. else {
  66175. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  66176. SSL_SUCCESS);
  66177. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  66178. SSL_SUCCESS);
  66179. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  66180. SSL_SUCCESS);
  66181. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  66182. SSL_SUCCESS);
  66183. }
  66184. /*
  66185. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  66186. * been issued first.
  66187. */
  66188. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66189. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66190. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66191. (void*)iv), SSL_SUCCESS);
  66192. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66193. (void*)iv), SSL_SUCCESS);
  66194. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  66195. /*************** Encrypt ***************/
  66196. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66197. currentIv), SSL_SUCCESS);
  66198. /* Check current IV against expected. */
  66199. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66200. /* Add AAD. */
  66201. if (i == 2) {
  66202. /* Test streaming API. */
  66203. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  66204. AAD_SIZE), SSL_SUCCESS);
  66205. }
  66206. else {
  66207. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  66208. AAD_SIZE);
  66209. }
  66210. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66211. DYNAMIC_TYPE_TMP_BUFFER));
  66212. /* Encrypt plaintext. */
  66213. if (i == 2) {
  66214. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  66215. plainTexts[j], plainTextSzs[j]),
  66216. SSL_SUCCESS);
  66217. }
  66218. else {
  66219. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  66220. plainTextSzs[j]), plainTextSzs[j]);
  66221. }
  66222. if (i == 2) {
  66223. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  66224. SSL_SUCCESS);
  66225. }
  66226. else {
  66227. /*
  66228. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  66229. * akin to calling EVP_CipherFinal.
  66230. */
  66231. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  66232. }
  66233. /* Check ciphertext against expected. */
  66234. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  66235. 0);
  66236. /* Get and check tag against expected. */
  66237. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  66238. sizeof(tag), tag), SSL_SUCCESS);
  66239. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  66240. /*************** Decrypt ***************/
  66241. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66242. currentIv), SSL_SUCCESS);
  66243. /* Check current IV against expected. */
  66244. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66245. /* Add AAD. */
  66246. if (i == 2) {
  66247. /* Test streaming API. */
  66248. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  66249. AAD_SIZE), SSL_SUCCESS);
  66250. }
  66251. else {
  66252. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  66253. AAD_SIZE);
  66254. }
  66255. /* Set expected tag. */
  66256. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  66257. sizeof(tag), tag), SSL_SUCCESS);
  66258. /* Decrypt ciphertext. */
  66259. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66260. DYNAMIC_TYPE_TMP_BUFFER));
  66261. if (i == 2) {
  66262. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  66263. cipherText, plainTextSzs[j]),
  66264. SSL_SUCCESS);
  66265. }
  66266. else {
  66267. /* This first EVP_Cipher call will check the tag, too. */
  66268. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  66269. plainTextSzs[j]), plainTextSzs[j]);
  66270. }
  66271. if (i == 2) {
  66272. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  66273. SSL_SUCCESS);
  66274. }
  66275. else {
  66276. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  66277. }
  66278. /* Check plaintext against expected. */
  66279. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  66280. 0);
  66281. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66282. cipherText = NULL;
  66283. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66284. calcPlainText = NULL;
  66285. }
  66286. EVP_CIPHER_CTX_free(encCtx);
  66287. encCtx = NULL;
  66288. EVP_CIPHER_CTX_free(decCtx);
  66289. decCtx = NULL;
  66290. }
  66291. #endif
  66292. return EXPECT_RESULT();
  66293. }
  66294. static int test_wolfSSL_OBJ_ln(void)
  66295. {
  66296. EXPECT_DECLS;
  66297. const int nid_set[] = {
  66298. NID_commonName,
  66299. NID_serialNumber,
  66300. NID_countryName,
  66301. NID_localityName,
  66302. NID_stateOrProvinceName,
  66303. NID_organizationName,
  66304. NID_organizationalUnitName,
  66305. NID_domainComponent,
  66306. NID_businessCategory,
  66307. NID_jurisdictionCountryName,
  66308. NID_jurisdictionStateOrProvinceName,
  66309. NID_emailAddress
  66310. };
  66311. const char* ln_set[] = {
  66312. "commonName",
  66313. "serialNumber",
  66314. "countryName",
  66315. "localityName",
  66316. "stateOrProvinceName",
  66317. "organizationName",
  66318. "organizationalUnitName",
  66319. "domainComponent",
  66320. "businessCategory",
  66321. "jurisdictionCountryName",
  66322. "jurisdictionStateOrProvinceName",
  66323. "emailAddress",
  66324. };
  66325. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  66326. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  66327. #ifdef HAVE_ECC
  66328. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  66329. {
  66330. EC_builtin_curve r[27];
  66331. size_t nCurves = sizeof(r) / sizeof(r[0]);
  66332. nCurves = EC_get_builtin_curves(r, nCurves);
  66333. for (i = 0; i < nCurves; i++) {
  66334. /* skip ECC_CURVE_INVALID */
  66335. if (r[i].nid != ECC_CURVE_INVALID) {
  66336. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  66337. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  66338. }
  66339. }
  66340. }
  66341. #endif
  66342. #endif
  66343. for (i = 0; i < maxIdx; i++) {
  66344. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  66345. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  66346. }
  66347. return EXPECT_RESULT();
  66348. }
  66349. static int test_wolfSSL_OBJ_sn(void)
  66350. {
  66351. EXPECT_DECLS;
  66352. int i = 0, maxIdx = 7;
  66353. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  66354. NID_stateOrProvinceName,NID_organizationName,
  66355. NID_organizationalUnitName,NID_emailAddress};
  66356. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  66357. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  66358. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  66359. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  66360. WOLFSSL_EMAIL_ADDR};
  66361. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  66362. for (i = 0; i < maxIdx; i++) {
  66363. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  66364. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  66365. }
  66366. return EXPECT_RESULT();
  66367. }
  66368. #if !defined(NO_BIO)
  66369. static unsigned long TXT_DB_hash(const WOLFSSL_STRING *s)
  66370. {
  66371. return lh_strhash(s[3]);
  66372. }
  66373. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  66374. {
  66375. return XSTRCMP(a[3], b[3]);
  66376. }
  66377. #endif
  66378. static int test_wolfSSL_TXT_DB(void)
  66379. {
  66380. EXPECT_DECLS;
  66381. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66382. BIO *bio = NULL;
  66383. TXT_DB *db = NULL;
  66384. const int columns = 6;
  66385. const char *fields[6] = {
  66386. "V",
  66387. "320926161116Z",
  66388. "",
  66389. "12BD",
  66390. "unknown",
  66391. "/CN=rsa doe",
  66392. };
  66393. char** fields_copy = NULL;
  66394. /* Test read */
  66395. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  66396. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  66397. ExpectNotNull(db = TXT_DB_read(bio, columns));
  66398. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  66399. DYNAMIC_TYPE_OPENSSL));
  66400. if (fields_copy != NULL) {
  66401. XMEMCPY(fields_copy, fields, sizeof(fields));
  66402. }
  66403. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  66404. if (EXPECT_FAIL()) {
  66405. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  66406. }
  66407. BIO_free(bio);
  66408. bio = NULL;
  66409. /* Test write */
  66410. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  66411. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  66412. BIO_free(bio);
  66413. /* Test index */
  66414. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)TXT_DB_hash,
  66415. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  66416. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66417. fields[3] = "12DA";
  66418. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66419. fields[3] = "FFFF";
  66420. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66421. fields[3] = "";
  66422. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66423. TXT_DB_free(db);
  66424. #endif
  66425. return EXPECT_RESULT();
  66426. }
  66427. static int test_wolfSSL_NCONF(void)
  66428. {
  66429. EXPECT_DECLS;
  66430. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66431. const char* confFile = "./tests/NCONF_test.cnf";
  66432. CONF* conf = NULL;
  66433. long eline = 0;
  66434. long num = 0;
  66435. ExpectNotNull(conf = NCONF_new(NULL));
  66436. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  66437. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  66438. ExpectIntEQ(num, 1234);
  66439. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  66440. ExpectIntEQ(num, 4321);
  66441. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  66442. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  66443. "./test-dir/file1");
  66444. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  66445. "./test-dir/file1:./test-dir/file2:./section1:file2");
  66446. NCONF_free(conf);
  66447. #endif
  66448. return EXPECT_RESULT();
  66449. }
  66450. #endif /* OPENSSL_ALL */
  66451. static int test_wolfSSL_X509V3_EXT_get(void) {
  66452. EXPECT_DECLS;
  66453. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66454. XFILE f = XBADFILE;
  66455. int numOfExt =0;
  66456. int extNid = 0;
  66457. int i = 0;
  66458. WOLFSSL_X509* x509 = NULL;
  66459. WOLFSSL_X509_EXTENSION* ext = NULL;
  66460. const WOLFSSL_v3_ext_method* method = NULL;
  66461. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66462. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66463. if (f != XBADFILE)
  66464. XFCLOSE(f);
  66465. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  66466. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66467. for (i = 0; i < numOfExt; i++) {
  66468. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66469. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  66470. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66471. ExpectIntEQ(method->ext_nid, extNid);
  66472. }
  66473. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  66474. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  66475. wolfSSL_X509_free(x509);
  66476. #endif
  66477. return EXPECT_RESULT();
  66478. }
  66479. static int test_wolfSSL_X509V3_EXT_nconf(void)
  66480. {
  66481. EXPECT_DECLS;
  66482. #ifdef OPENSSL_ALL
  66483. const char *ext_names[] = {
  66484. "subjectKeyIdentifier",
  66485. "authorityKeyIdentifier",
  66486. "subjectAltName",
  66487. "keyUsage",
  66488. "extendedKeyUsage",
  66489. };
  66490. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  66491. int ext_nids[] = {
  66492. NID_subject_key_identifier,
  66493. NID_authority_key_identifier,
  66494. NID_subject_alt_name,
  66495. NID_key_usage,
  66496. NID_ext_key_usage,
  66497. };
  66498. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  66499. const char *ext_values[] = {
  66500. "hash",
  66501. "hash",
  66502. "DNS:example.com, IP:127.0.0.1",
  66503. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  66504. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  66505. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  66506. "OCSPSigning",
  66507. };
  66508. size_t i;
  66509. X509_EXTENSION* ext = NULL;
  66510. X509* x509 = NULL;
  66511. unsigned int keyUsageFlags;
  66512. unsigned int extKeyUsageFlags;
  66513. ExpectNotNull(x509 = X509_new());
  66514. /* keyUsage / extKeyUsage should match string above */
  66515. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66516. | KU_NON_REPUDIATION
  66517. | KU_KEY_ENCIPHERMENT
  66518. | KU_DATA_ENCIPHERMENT
  66519. | KU_KEY_AGREEMENT
  66520. | KU_KEY_CERT_SIGN
  66521. | KU_CRL_SIGN
  66522. | KU_ENCIPHER_ONLY
  66523. | KU_DECIPHER_ONLY;
  66524. extKeyUsageFlags = XKU_SSL_CLIENT
  66525. | XKU_SSL_SERVER
  66526. | XKU_CODE_SIGN
  66527. | XKU_SMIME
  66528. | XKU_TIMESTAMP
  66529. | XKU_OCSP_SIGN;
  66530. for (i = 0; i < ext_names_count; i++) {
  66531. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66532. ext_values[i]));
  66533. X509_EXTENSION_free(ext);
  66534. ext = NULL;
  66535. }
  66536. for (i = 0; i < ext_nids_count; i++) {
  66537. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  66538. ext_values[i]));
  66539. X509_EXTENSION_free(ext);
  66540. ext = NULL;
  66541. }
  66542. /* Test adding extension to X509 */
  66543. for (i = 0; i < ext_nids_count; i++) {
  66544. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66545. ext_values[i]));
  66546. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  66547. if (ext_nids[i] == NID_key_usage) {
  66548. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66549. }
  66550. else if (ext_nids[i] == NID_ext_key_usage) {
  66551. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66552. }
  66553. X509_EXTENSION_free(ext);
  66554. ext = NULL;
  66555. }
  66556. X509_free(x509);
  66557. #endif
  66558. return EXPECT_RESULT();
  66559. }
  66560. static int test_wolfSSL_X509V3_EXT(void) {
  66561. EXPECT_DECLS;
  66562. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66563. XFILE f = XBADFILE;
  66564. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  66565. char* str = NULL;
  66566. unsigned char* data = NULL;
  66567. const WOLFSSL_v3_ext_method* method = NULL;
  66568. WOLFSSL_X509* x509 = NULL;
  66569. WOLFSSL_X509_EXTENSION* ext = NULL;
  66570. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  66571. WOLFSSL_ASN1_OBJECT *obj = NULL;
  66572. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  66573. WOLFSSL_ASN1_STRING* asn1str = NULL;
  66574. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  66575. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  66576. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  66577. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  66578. WOLFSSL_GENERAL_NAME* gn = NULL;
  66579. /* Check NULL argument */
  66580. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  66581. /* Using OCSP cert with X509V3 extensions */
  66582. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  66583. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66584. if (f != XBADFILE)
  66585. XFCLOSE(f);
  66586. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66587. /* Basic Constraints */
  66588. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66589. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66590. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  66591. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  66592. ExpectIntEQ(bc->ca, 1);
  66593. ExpectNull(bc->pathlen);
  66594. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  66595. bc = NULL;
  66596. i++;
  66597. /* Subject Key Identifier */
  66598. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66599. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66600. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  66601. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66602. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  66603. asn1str));
  66604. X509_EXTENSION_free(ext2);
  66605. ext2 = NULL;
  66606. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66607. ExpectNotNull(method->i2s);
  66608. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  66609. wolfSSL_ASN1_STRING_free(asn1str);
  66610. asn1str = NULL;
  66611. if (str != NULL) {
  66612. actual = strcmp(str,
  66613. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66614. }
  66615. ExpectIntEQ(actual, 0);
  66616. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66617. str = NULL;
  66618. i++;
  66619. /* Authority Key Identifier */
  66620. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66621. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66622. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  66623. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  66624. ext));
  66625. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66626. ExpectNotNull(asn1str = aKeyId->keyid);
  66627. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  66628. asn1str));
  66629. asn1str = NULL;
  66630. if (str != NULL) {
  66631. actual = strcmp(str,
  66632. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66633. }
  66634. ExpectIntEQ(actual, 0);
  66635. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66636. str = NULL;
  66637. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  66638. aKeyId = NULL;
  66639. i++;
  66640. /* Key Usage */
  66641. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66642. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66643. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  66644. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66645. #if defined(WOLFSSL_QT)
  66646. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  66647. #else
  66648. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  66649. #endif
  66650. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  66651. if (data != NULL) {
  66652. #ifdef BIG_ENDIAN_ORDER
  66653. actual = data[1];
  66654. #else
  66655. actual = data[0];
  66656. #endif
  66657. }
  66658. ExpectIntEQ(actual, expected);
  66659. wolfSSL_ASN1_STRING_free(asn1str);
  66660. asn1str = NULL;
  66661. #if 1
  66662. i++;
  66663. /* Authority Info Access */
  66664. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66665. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66666. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  66667. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  66668. ext));
  66669. #if defined(WOLFSSL_QT)
  66670. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66671. #else
  66672. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66673. #endif
  66674. /* URI entry is an ACCESS_DESCRIPTION type */
  66675. #if defined(WOLFSSL_QT)
  66676. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  66677. #else
  66678. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  66679. #endif
  66680. ExpectNotNull(adObj = ad->method);
  66681. /* Make sure nid is OCSP */
  66682. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  66683. /* GENERAL_NAME stores URI as an ASN1_STRING */
  66684. ExpectNotNull(gn = ad->location);
  66685. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  66686. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  66687. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  66688. #if defined(WOLFSSL_QT)
  66689. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  66690. #else
  66691. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  66692. #endif
  66693. if (str != NULL) {
  66694. actual = strcmp(str, "http://127.0.0.1:22220");
  66695. }
  66696. ExpectIntEQ(actual, 0);
  66697. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  66698. aia = NULL;
  66699. #else
  66700. (void) aia; (void) ad; (void) adObj; (void) gn;
  66701. #endif
  66702. wolfSSL_X509_free(x509);
  66703. #endif
  66704. return EXPECT_RESULT();
  66705. }
  66706. static int test_wolfSSL_X509_get_extension_flags(void)
  66707. {
  66708. EXPECT_DECLS;
  66709. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66710. XFILE f = XBADFILE;
  66711. X509* x509 = NULL;
  66712. unsigned int extFlags;
  66713. unsigned int keyUsageFlags;
  66714. unsigned int extKeyUsageFlags;
  66715. /* client-int-cert.pem has the following extension flags. */
  66716. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  66717. /* and the following key usage flags. */
  66718. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66719. | KU_NON_REPUDIATION
  66720. | KU_KEY_ENCIPHERMENT;
  66721. /* and the following extended key usage flags. */
  66722. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  66723. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  66724. XBADFILE);
  66725. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66726. if (f != XBADFILE) {
  66727. XFCLOSE(f);
  66728. f = XBADFILE;
  66729. }
  66730. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  66731. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66732. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66733. X509_free(x509);
  66734. x509 = NULL;
  66735. /* client-cert-ext.pem has the following extension flags. */
  66736. extFlags = EXFLAG_KUSAGE;
  66737. /* and the following key usage flags. */
  66738. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66739. | KU_KEY_CERT_SIGN
  66740. | KU_CRL_SIGN;
  66741. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  66742. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66743. if (f != XBADFILE)
  66744. XFCLOSE(f);
  66745. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  66746. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66747. X509_free(x509);
  66748. #endif /* OPENSSL_ALL */
  66749. return EXPECT_RESULT();
  66750. }
  66751. static int test_wolfSSL_X509_get_ext(void)
  66752. {
  66753. EXPECT_DECLS;
  66754. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66755. int ret = 0;
  66756. XFILE f = XBADFILE;
  66757. WOLFSSL_X509* x509 = NULL;
  66758. WOLFSSL_X509_EXTENSION* foundExtension;
  66759. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66760. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66761. if (f != XBADFILE)
  66762. XFCLOSE(f);
  66763. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  66764. /* wolfSSL_X509_get_ext() valid input */
  66765. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  66766. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  66767. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  66768. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  66769. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  66770. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  66771. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  66772. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  66773. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  66774. wolfSSL_X509_free(x509);
  66775. #endif
  66776. return EXPECT_RESULT();
  66777. }
  66778. static int test_wolfSSL_X509_get_ext_by_NID(void)
  66779. {
  66780. EXPECT_DECLS;
  66781. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66782. int rc = 0;
  66783. XFILE f = XBADFILE;
  66784. WOLFSSL_X509* x509 = NULL;
  66785. ASN1_OBJECT* obj = NULL;
  66786. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66787. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66788. if (f != XBADFILE)
  66789. XFCLOSE(f);
  66790. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66791. -1), 0);
  66792. /* Start search from last location (should fail) */
  66793. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66794. rc), -1);
  66795. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  66796. -2), -1);
  66797. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  66798. -1), -1);
  66799. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  66800. /* NID_ext_key_usage, check also its nid and oid */
  66801. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  66802. -1);
  66803. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  66804. x509, rc)));
  66805. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  66806. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  66807. wolfSSL_X509_free(x509);
  66808. #endif
  66809. return EXPECT_RESULT();
  66810. }
  66811. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  66812. {
  66813. EXPECT_DECLS;
  66814. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66815. int rc = 0;
  66816. XFILE f = XBADFILE;
  66817. WOLFSSL_X509* x509 = NULL;
  66818. WOLFSSL_X509_EXTENSION* ext = NULL;
  66819. WOLFSSL_ASN1_STRING* sanString = NULL;
  66820. byte* sanDer = NULL;
  66821. const byte expectedDer[] = {
  66822. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  66823. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  66824. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66825. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66826. if (f != XBADFILE)
  66827. XFCLOSE(f);
  66828. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  66829. ExpectNotNull(ext = X509_get_ext(x509, rc));
  66830. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  66831. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  66832. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  66833. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  66834. X509_free(x509);
  66835. #endif
  66836. return EXPECT_RESULT();
  66837. }
  66838. static int test_wolfSSL_X509_EXTENSION_new(void)
  66839. {
  66840. EXPECT_DECLS;
  66841. #if defined (OPENSSL_ALL)
  66842. WOLFSSL_X509_EXTENSION* ext = NULL;
  66843. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  66844. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  66845. wolfSSL_X509_EXTENSION_free(ext);
  66846. #endif
  66847. return EXPECT_RESULT();
  66848. }
  66849. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  66850. {
  66851. EXPECT_DECLS;
  66852. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66853. WOLFSSL_X509* x509 = NULL;
  66854. WOLFSSL_X509_EXTENSION* ext = NULL;
  66855. WOLFSSL_ASN1_OBJECT* o = NULL;
  66856. XFILE file = XBADFILE;
  66857. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66858. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66859. if (file != XBADFILE)
  66860. XFCLOSE(file);
  66861. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  66862. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66863. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  66864. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  66865. ExpectIntEQ(o->nid, 128);
  66866. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  66867. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  66868. wolfSSL_X509_free(x509);
  66869. #endif
  66870. return EXPECT_RESULT();
  66871. }
  66872. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  66873. {
  66874. EXPECT_DECLS;
  66875. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66876. WOLFSSL_X509* x509 = NULL;
  66877. WOLFSSL_X509_EXTENSION* ext = NULL;
  66878. WOLFSSL_ASN1_STRING* str = NULL;
  66879. XFILE file = XBADFILE;
  66880. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66881. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66882. if (file != XBADFILE)
  66883. XFCLOSE(file);
  66884. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66885. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  66886. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  66887. wolfSSL_X509_free(x509);
  66888. #endif
  66889. return EXPECT_RESULT();
  66890. }
  66891. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  66892. {
  66893. EXPECT_DECLS;
  66894. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66895. WOLFSSL_X509* x509 = NULL;
  66896. WOLFSSL_X509_EXTENSION* ext = NULL;
  66897. XFILE file = XBADFILE;
  66898. int crit = 0;
  66899. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66900. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  66901. if (file != XBADFILE)
  66902. XFCLOSE(file);
  66903. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  66904. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  66905. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  66906. wolfSSL_X509_free(x509);
  66907. #endif
  66908. return EXPECT_RESULT();
  66909. }
  66910. static int test_wolfSSL_X509V3_EXT_print(void)
  66911. {
  66912. EXPECT_DECLS;
  66913. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  66914. !defined(NO_RSA)
  66915. {
  66916. XFILE f = XBADFILE;
  66917. WOLFSSL_X509* x509 = NULL;
  66918. X509_EXTENSION * ext = NULL;
  66919. int loc = 0;
  66920. BIO *bio = NULL;
  66921. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  66922. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66923. if (f != XBADFILE)
  66924. fclose(f);
  66925. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  66926. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66927. NID_basic_constraints, -1), -1);
  66928. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66929. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66930. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66931. NID_subject_key_identifier, -1), -1);
  66932. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66933. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66934. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  66935. NID_authority_key_identifier, -1), -1);
  66936. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  66937. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  66938. wolfSSL_BIO_free(bio);
  66939. wolfSSL_X509_free(x509);
  66940. }
  66941. {
  66942. X509 *x509 = NULL;
  66943. BIO *bio = NULL;
  66944. X509_EXTENSION *ext = NULL;
  66945. unsigned int i = 0;
  66946. unsigned int idx = 0;
  66947. /* Some NIDs to test with */
  66948. int nids[] = {
  66949. /* NID_key_usage, currently X509_get_ext returns this as a bit
  66950. * string, which messes up X509V3_EXT_print */
  66951. /* NID_ext_key_usage, */
  66952. NID_subject_alt_name,
  66953. };
  66954. int* n = NULL;
  66955. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  66956. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  66957. WOLFSSL_FILETYPE_PEM));
  66958. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  66959. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  66960. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  66961. * update the index */
  66962. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  66963. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  66964. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  66965. ExpectIntGT(fprintf(stderr, "\n"), 0);
  66966. }
  66967. BIO_free(bio);
  66968. X509_free(x509);
  66969. }
  66970. #endif
  66971. return EXPECT_RESULT();
  66972. }
  66973. static int test_wolfSSL_X509_cmp(void)
  66974. {
  66975. EXPECT_DECLS;
  66976. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66977. XFILE file1 = XBADFILE;
  66978. XFILE file2 = XBADFILE;
  66979. WOLFSSL_X509* cert1 = NULL;
  66980. WOLFSSL_X509* cert2 = NULL;
  66981. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66982. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  66983. XBADFILE);
  66984. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  66985. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  66986. if (file1 != XBADFILE)
  66987. fclose(file1);
  66988. if (file2 != XBADFILE)
  66989. fclose(file2);
  66990. /* wolfSSL_X509_cmp() testing matching certs */
  66991. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  66992. /* wolfSSL_X509_cmp() testing mismatched certs */
  66993. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  66994. /* wolfSSL_X509_cmp() testing NULL, valid args */
  66995. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  66996. /* wolfSSL_X509_cmp() testing valid, NULL args */
  66997. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  66998. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  66999. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  67000. wolfSSL_X509_free(cert1);
  67001. wolfSSL_X509_free(cert2);
  67002. #endif
  67003. return EXPECT_RESULT();
  67004. }
  67005. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  67006. {
  67007. EXPECT_DECLS;
  67008. #if defined(OPENSSL_ALL)
  67009. EVP_PKEY* pkey;
  67010. pkey = EVP_PKEY_new();
  67011. ExpectNotNull(pkey);
  67012. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  67013. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67014. EVP_PKEY_free(pkey);
  67015. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67016. EVP_PKEY_free(pkey);
  67017. EVP_PKEY_free(pkey);
  67018. #endif
  67019. return EXPECT_RESULT();
  67020. }
  67021. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  67022. {
  67023. EXPECT_DECLS;
  67024. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  67025. EVP_PKEY* pkey = NULL;
  67026. const unsigned char* p;
  67027. unsigned char *der = NULL;
  67028. unsigned char *tmp = NULL;
  67029. int derLen;
  67030. p = client_keypub_der_2048;
  67031. /* Check that key can be successfully decoded. */
  67032. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  67033. sizeof_client_keypub_der_2048));
  67034. /* Check that key can be successfully encoded. */
  67035. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67036. /* Ensure that the encoded version matches the original. */
  67037. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67038. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67039. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67040. * is advanced. */
  67041. tmp = der;
  67042. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67043. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67044. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67045. ExpectTrue(der + derLen == tmp);
  67046. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67047. EVP_PKEY_free(pkey);
  67048. #endif
  67049. return EXPECT_RESULT();
  67050. }
  67051. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  67052. {
  67053. EXPECT_DECLS;
  67054. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  67055. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67056. EVP_PKEY* pkey = NULL;
  67057. const unsigned char* p;
  67058. unsigned char *der = NULL;
  67059. unsigned char *tmp = NULL;
  67060. int derLen;
  67061. unsigned char pub_buf[65];
  67062. const int pub_len = 65;
  67063. BN_CTX* ctx;
  67064. EC_GROUP* curve = NULL;
  67065. EC_KEY* ephemeral_key = NULL;
  67066. const EC_POINT* h;
  67067. /* Generate an x963 key pair and get public part into pub_buf */
  67068. ExpectNotNull(ctx = BN_CTX_new());
  67069. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  67070. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  67071. NID_X9_62_prime256v1));
  67072. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  67073. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  67074. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  67075. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  67076. /* Prepare the EVP_PKEY */
  67077. ExpectNotNull(pkey = EVP_PKEY_new());
  67078. p = pub_buf;
  67079. /* Check that key can be successfully decoded. */
  67080. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  67081. pub_len));
  67082. /* Check that key can be successfully encoded. */
  67083. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67084. /* Ensure that the encoded version matches the original. */
  67085. ExpectIntEQ(derLen, pub_len);
  67086. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67087. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67088. * is advanced. */
  67089. tmp = der;
  67090. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67091. ExpectIntEQ(derLen, pub_len);
  67092. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67093. ExpectTrue(der + derLen == tmp);
  67094. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67095. EVP_PKEY_free(pkey);
  67096. EC_KEY_free(ephemeral_key);
  67097. EC_GROUP_free(curve);
  67098. #endif
  67099. return EXPECT_RESULT();
  67100. }
  67101. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  67102. {
  67103. EXPECT_DECLS;
  67104. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  67105. DSA* dsa = NULL;
  67106. byte derIn[] = {
  67107. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  67108. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  67109. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  67110. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  67111. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  67112. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  67113. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  67114. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  67115. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  67116. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  67117. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  67118. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  67119. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  67120. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  67121. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  67122. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  67123. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  67124. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  67125. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  67126. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  67127. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  67128. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  67129. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  67130. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  67131. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  67132. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  67133. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  67134. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  67135. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  67136. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  67137. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  67138. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  67139. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  67140. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  67141. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  67142. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  67143. 0x1e, 0xde, 0xc4
  67144. };
  67145. int derInLen = sizeof(derIn);
  67146. byte* derOut = NULL;
  67147. int derOutLen;
  67148. byte* p = derIn;
  67149. /* Check that params can be successfully decoded. */
  67150. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  67151. /* Check that params can be successfully encoded. */
  67152. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  67153. /* Ensure that the encoded version matches the original. */
  67154. ExpectIntEQ(derInLen, derOutLen);
  67155. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  67156. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67157. DSA_free(dsa);
  67158. #endif
  67159. return EXPECT_RESULT();
  67160. }
  67161. static int test_wolfSSL_i2d_PrivateKey(void)
  67162. {
  67163. EXPECT_DECLS;
  67164. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  67165. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67166. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  67167. {
  67168. EVP_PKEY* pkey = NULL;
  67169. const unsigned char* server_key =
  67170. (const unsigned char*)server_key_der_2048;
  67171. unsigned char buf[FOURK_BUF];
  67172. unsigned char* pt = NULL;
  67173. int bufSz = 0;
  67174. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  67175. (long)sizeof_server_key_der_2048));
  67176. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  67177. pt = buf;
  67178. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  67179. ExpectIntNE((pt - buf), 0);
  67180. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  67181. EVP_PKEY_free(pkey);
  67182. }
  67183. #endif
  67184. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  67185. {
  67186. EVP_PKEY* pkey = NULL;
  67187. const unsigned char* client_key =
  67188. (const unsigned char*)ecc_clikey_der_256;
  67189. unsigned char buf[FOURK_BUF];
  67190. unsigned char* pt = NULL;
  67191. int bufSz = 0;
  67192. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  67193. (long)sizeof_ecc_clikey_der_256)));
  67194. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  67195. pt = buf;
  67196. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  67197. ExpectIntNE((pt - buf), 0);
  67198. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  67199. EVP_PKEY_free(pkey);
  67200. }
  67201. #endif
  67202. #endif
  67203. return EXPECT_RESULT();
  67204. }
  67205. static int test_wolfSSL_OCSP_id_get0_info(void)
  67206. {
  67207. EXPECT_DECLS;
  67208. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  67209. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  67210. X509* cert = NULL;
  67211. X509* issuer = NULL;
  67212. OCSP_CERTID* id = NULL;
  67213. OCSP_CERTID* id2 = NULL;
  67214. ASN1_STRING* name = NULL;
  67215. ASN1_OBJECT* pmd = NULL;
  67216. ASN1_STRING* keyHash = NULL;
  67217. ASN1_INTEGER* serial = NULL;
  67218. ASN1_INTEGER* x509Int = NULL;
  67219. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  67220. SSL_FILETYPE_PEM));
  67221. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  67222. SSL_FILETYPE_PEM));
  67223. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  67224. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  67225. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  67226. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  67227. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  67228. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  67229. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  67230. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  67231. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  67232. ExpectNotNull(serial);
  67233. /* compare serial number to one in cert, should be equal */
  67234. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  67235. ExpectIntEQ(x509Int->length, serial->length);
  67236. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  67237. /* test OCSP_id_cmp */
  67238. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67239. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  67240. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  67241. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  67242. if (id != NULL) {
  67243. id->issuerHash[0] = ~id->issuerHash[0];
  67244. }
  67245. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  67246. OCSP_CERTID_free(id);
  67247. OCSP_CERTID_free(id2);
  67248. X509_free(cert); /* free's x509Int */
  67249. X509_free(issuer);
  67250. #endif
  67251. return EXPECT_RESULT();
  67252. }
  67253. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  67254. {
  67255. EXPECT_DECLS;
  67256. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67257. WOLFSSL_OCSP_CERTID certId;
  67258. byte* targetBuffer = NULL;
  67259. byte* p;
  67260. /* OCSP CertID bytes taken from PCAP */
  67261. byte rawCertId[] = {
  67262. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67263. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67264. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67265. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67266. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67267. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67268. 0xcf, 0xbc, 0x91
  67269. };
  67270. int ret = 0;
  67271. int i;
  67272. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  67273. certId.rawCertId = rawCertId;
  67274. certId.rawCertIdSize = sizeof(rawCertId);
  67275. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  67276. DYNAMIC_TYPE_TMP_BUFFER));
  67277. p = targetBuffer;
  67278. /* Function returns the size of the encoded data. */
  67279. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  67280. /* If target buffer is not null, function increments targetBuffer to point
  67281. * just past the end of the encoded data. */
  67282. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  67283. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67284. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67285. }
  67286. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67287. targetBuffer = NULL;
  67288. /* If target buffer is null, function allocates memory for a buffer and
  67289. * copies the encoded data into it. targetBuffer then points to the start of
  67290. * this newly allocate buffer. */
  67291. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  67292. sizeof(rawCertId));
  67293. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67294. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67295. }
  67296. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  67297. #endif
  67298. return EXPECT_RESULT();
  67299. }
  67300. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  67301. {
  67302. EXPECT_DECLS;
  67303. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67304. WOLFSSL_OCSP_CERTID* certId;
  67305. WOLFSSL_OCSP_CERTID* certIdGood;
  67306. WOLFSSL_OCSP_CERTID* certIdBad;
  67307. const unsigned char* rawCertIdPtr;
  67308. const unsigned char rawCertId[] = {
  67309. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67310. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67311. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67312. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67313. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67314. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67315. 0xcf, 0xbc, 0x91
  67316. };
  67317. rawCertIdPtr = &rawCertId[0];
  67318. /* If the cert ID is NULL the function should allocate it and copy the
  67319. * data to it. */
  67320. certId = NULL;
  67321. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67322. sizeof(rawCertId)));
  67323. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67324. if (certId != NULL) {
  67325. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67326. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  67327. }
  67328. /* If the cert ID is not NULL the function will just copy the data to it. */
  67329. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  67330. DYNAMIC_TYPE_TMP_BUFFER));
  67331. ExpectNotNull(certId);
  67332. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  67333. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  67334. rawCertIdPtr = &rawCertId[0];
  67335. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67336. sizeof(rawCertId)));
  67337. ExpectPtrEq(certIdGood, certId);
  67338. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67339. if (certId != NULL) {
  67340. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67341. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67342. certId = NULL;
  67343. }
  67344. /* The below tests should fail when passed bad parameters. NULL should
  67345. * always be returned. */
  67346. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  67347. sizeof(rawCertId)));
  67348. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  67349. sizeof(rawCertId)));
  67350. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  67351. #endif
  67352. return EXPECT_RESULT();
  67353. }
  67354. static int test_wolfSSL_OCSP_id_cmp(void)
  67355. {
  67356. EXPECT_DECLS;
  67357. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  67358. OCSP_CERTID id1;
  67359. OCSP_CERTID id2;
  67360. XMEMSET(&id1, 0, sizeof(id1));
  67361. XMEMSET(&id2, 0, sizeof(id2));
  67362. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  67363. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67364. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  67365. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  67366. #endif
  67367. return EXPECT_RESULT();
  67368. }
  67369. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  67370. {
  67371. EXPECT_DECLS;
  67372. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67373. WOLFSSL_OCSP_SINGLERESP single;
  67374. const WOLFSSL_OCSP_CERTID* certId;
  67375. XMEMSET(&single, 0, sizeof(single));
  67376. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  67377. ExpectPtrEq(&single, certId);
  67378. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  67379. #endif
  67380. return EXPECT_RESULT();
  67381. }
  67382. static int test_wolfSSL_OCSP_single_get0_status(void)
  67383. {
  67384. EXPECT_DECLS;
  67385. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  67386. defined(WOLFSSL_OCSP_PARSE_STATUS)
  67387. WOLFSSL_OCSP_SINGLERESP single;
  67388. CertStatus certStatus;
  67389. WOLFSSL_ASN1_TIME* thisDate;
  67390. WOLFSSL_ASN1_TIME* nextDate;
  67391. int ret, i;
  67392. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67393. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  67394. /* Fill the date fields with some dummy data. */
  67395. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  67396. certStatus.thisDateParsed.data[i] = i;
  67397. certStatus.nextDateParsed.data[i] = i;
  67398. }
  67399. certStatus.status = CERT_GOOD;
  67400. single.status = &certStatus;
  67401. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  67402. &nextDate);
  67403. ExpectIntEQ(ret, CERT_GOOD);
  67404. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  67405. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  67406. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  67407. CERT_GOOD);
  67408. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  67409. NULL), CERT_GOOD);
  67410. #endif
  67411. return EXPECT_RESULT();
  67412. }
  67413. static int test_wolfSSL_OCSP_resp_count(void)
  67414. {
  67415. EXPECT_DECLS;
  67416. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67417. WOLFSSL_OCSP_BASICRESP basicResp;
  67418. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67419. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67420. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67421. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67422. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67423. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  67424. basicResp.single = &singleRespOne;
  67425. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  67426. singleRespOne.next = &singleRespTwo;
  67427. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  67428. #endif
  67429. return EXPECT_RESULT();
  67430. }
  67431. static int test_wolfSSL_OCSP_resp_get0(void)
  67432. {
  67433. EXPECT_DECLS;
  67434. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67435. WOLFSSL_OCSP_BASICRESP basicResp;
  67436. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67437. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67438. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67439. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67440. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67441. basicResp.single = &singleRespOne;
  67442. singleRespOne.next = &singleRespTwo;
  67443. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  67444. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  67445. #endif
  67446. return EXPECT_RESULT();
  67447. }
  67448. static int test_wolfSSL_OCSP_parse_url(void)
  67449. {
  67450. EXPECT_DECLS;
  67451. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  67452. #define CK_OPU_OK(u, h, po, pa, s) do { \
  67453. char* host = NULL; \
  67454. char* port = NULL; \
  67455. char* path = NULL; \
  67456. int isSsl = 0; \
  67457. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  67458. ExpectStrEQ(host, h); \
  67459. ExpectStrEQ(port, po); \
  67460. ExpectStrEQ(path, pa); \
  67461. ExpectIntEQ(isSsl, s); \
  67462. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67463. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67464. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67465. } while(0)
  67466. #define CK_OPU_FAIL(u) do { \
  67467. char* host = NULL; \
  67468. char* port = NULL; \
  67469. char* path = NULL; \
  67470. int isSsl = 0; \
  67471. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  67472. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67473. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67474. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67475. } while(0)
  67476. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  67477. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  67478. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  67479. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  67480. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  67481. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  67482. CK_OPU_FAIL("ftp://localhost");
  67483. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  67484. CK_OPU_FAIL("http/""/localhost");
  67485. CK_OPU_FAIL("http:/localhost");
  67486. CK_OPU_FAIL("https://localhost/path:1234");
  67487. #undef CK_OPU_OK
  67488. #undef CK_OPU_FAIL
  67489. #endif
  67490. return EXPECT_RESULT();
  67491. }
  67492. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67493. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67494. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  67495. {
  67496. if (t != NULL) {
  67497. *t = 1722006780;
  67498. }
  67499. return 1722006780;
  67500. }
  67501. #endif
  67502. static int test_wolfSSL_OCSP_REQ_CTX(void)
  67503. {
  67504. EXPECT_DECLS;
  67505. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67506. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67507. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  67508. * response was captured in wireshark. It contains both the http and binary
  67509. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  67510. * the time check passes. */
  67511. unsigned char ocspRespBin[] = {
  67512. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  67513. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  67514. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  67515. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  67516. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  67517. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  67518. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  67519. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  67520. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  67521. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  67522. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  67523. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  67524. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  67525. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67526. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  67527. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  67528. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  67529. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  67530. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  67531. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  67532. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  67533. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  67534. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  67535. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  67536. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  67537. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  67538. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  67539. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  67540. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  67541. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  67542. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  67543. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  67544. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  67545. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67546. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  67547. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  67548. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  67549. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  67550. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  67551. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  67552. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  67553. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  67554. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  67555. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  67556. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  67557. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  67558. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  67559. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  67560. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  67561. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  67562. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  67563. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  67564. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  67565. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  67566. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  67567. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  67568. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  67569. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  67570. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67571. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  67572. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  67573. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  67574. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  67575. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  67576. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  67577. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  67578. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  67579. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  67580. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  67581. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  67582. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  67583. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  67584. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  67585. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  67586. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  67587. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  67588. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  67589. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  67590. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  67591. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  67592. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  67593. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  67594. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  67595. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  67596. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  67597. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  67598. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67599. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67600. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  67601. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  67602. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  67603. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  67604. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  67605. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  67606. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  67607. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  67608. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  67609. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  67610. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  67611. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  67612. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  67613. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  67614. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  67615. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  67616. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  67617. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  67618. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  67619. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  67620. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  67621. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  67622. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  67623. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  67624. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  67625. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  67626. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  67627. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  67628. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  67629. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  67630. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  67631. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  67632. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  67633. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  67634. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  67635. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  67636. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  67637. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67638. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  67639. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  67640. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  67641. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  67642. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  67643. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67644. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67645. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  67646. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  67647. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  67648. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  67649. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  67650. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  67651. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  67652. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  67653. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  67654. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  67655. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  67656. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  67657. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  67658. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  67659. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  67660. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  67661. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  67662. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  67663. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  67664. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  67665. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  67666. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  67667. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  67668. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  67669. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  67670. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  67671. };
  67672. OCSP_REQ_CTX *ctx = NULL;
  67673. OCSP_REQUEST *req = NULL;
  67674. OCSP_CERTID *cid = NULL;
  67675. OCSP_RESPONSE *rsp = NULL;
  67676. BIO* bio1 = NULL;
  67677. BIO* bio2 = NULL;
  67678. X509* cert = NULL;
  67679. X509 *issuer = NULL;
  67680. X509_LOOKUP *lookup = NULL;
  67681. X509_STORE *store = NULL;
  67682. STACK_OF(X509_OBJECT) *str_objs = NULL;
  67683. X509_OBJECT *x509_obj = NULL;
  67684. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  67685. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  67686. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  67687. /* Load the leaf cert */
  67688. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  67689. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  67690. ExpectNotNull(store = X509_STORE_new());
  67691. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  67692. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  67693. X509_FILETYPE_PEM), 1);
  67694. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  67695. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  67696. X509_LU_X509, X509_get_issuer_name(cert)));
  67697. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  67698. ExpectNotNull(req = OCSP_REQUEST_new());
  67699. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  67700. ExpectNotNull(OCSP_request_add0_id(req, cid));
  67701. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  67702. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  67703. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  67704. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  67705. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  67706. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  67707. sizeof(ocspRespBin));
  67708. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  67709. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  67710. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  67711. ExpectNotNull(rsp);
  67712. OCSP_REQ_CTX_free(ctx);
  67713. OCSP_REQUEST_free(req);
  67714. OCSP_RESPONSE_free(rsp);
  67715. BIO_free(bio1);
  67716. BIO_free(bio2);
  67717. X509_free(cert);
  67718. X509_STORE_free(store);
  67719. #endif
  67720. return EXPECT_RESULT();
  67721. }
  67722. static int test_wolfSSL_EVP_PKEY_derive(void)
  67723. {
  67724. EXPECT_DECLS;
  67725. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  67726. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  67727. EVP_PKEY_CTX *ctx = NULL;
  67728. unsigned char *skey = NULL;
  67729. size_t skeylen;
  67730. EVP_PKEY *pkey = NULL;
  67731. EVP_PKEY *peerkey = NULL;
  67732. const unsigned char* key;
  67733. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  67734. /* DH */
  67735. key = dh_key_der_2048;
  67736. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  67737. sizeof_dh_key_der_2048)));
  67738. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  67739. key = dh_key_der_2048;
  67740. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  67741. sizeof_dh_key_der_2048)));
  67742. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  67743. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67744. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  67745. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  67746. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  67747. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  67748. DYNAMIC_TYPE_OPENSSL));
  67749. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  67750. EVP_PKEY_CTX_free(ctx);
  67751. ctx = NULL;
  67752. EVP_PKEY_free(peerkey);
  67753. peerkey = NULL;
  67754. EVP_PKEY_free(pkey);
  67755. pkey = NULL;
  67756. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  67757. skey = NULL;
  67758. #endif
  67759. #ifdef HAVE_ECC
  67760. /* ECDH */
  67761. key = ecc_clikey_der_256;
  67762. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  67763. sizeof_ecc_clikey_der_256)));
  67764. key = ecc_clikeypub_der_256;
  67765. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  67766. sizeof_ecc_clikeypub_der_256)));
  67767. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67768. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  67769. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  67770. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  67771. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  67772. DYNAMIC_TYPE_OPENSSL));
  67773. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  67774. EVP_PKEY_CTX_free(ctx);
  67775. EVP_PKEY_free(peerkey);
  67776. EVP_PKEY_free(pkey);
  67777. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  67778. #endif /* HAVE_ECC */
  67779. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  67780. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  67781. return EXPECT_RESULT();
  67782. }
  67783. static int test_wolfSSL_EVP_PBE_scrypt(void)
  67784. {
  67785. EXPECT_DECLS;
  67786. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  67787. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  67788. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  67789. int ret;
  67790. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  67791. int pwdlen = sizeof(pwd);
  67792. const byte salt[] = {'N','a','C','l'};
  67793. int saltlen = sizeof(salt);
  67794. byte key[80];
  67795. word64 numOvr32 = (word64)INT32_MAX + 1;
  67796. /* expected derived key for N:16, r:1, p:1 */
  67797. const byte expectedKey[] = {
  67798. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  67799. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  67800. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  67801. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  67802. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  67803. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  67804. 0xE7, 0xE9, 0xC0, 0x9A};
  67805. /* N r p mx key keylen */
  67806. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  67807. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  67808. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  67809. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  67810. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  67811. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  67812. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  67813. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  67814. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  67815. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  67816. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  67817. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  67818. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  67819. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  67820. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  67821. ExpectIntEQ(ret, 1); /* should succeed */
  67822. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  67823. key, 64);
  67824. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  67825. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  67826. key, 64);
  67827. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  67828. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  67829. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  67830. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  67831. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  67832. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  67833. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  67834. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  67835. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  67836. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  67837. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  67838. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  67839. ExpectIntEQ(ret, 1);
  67840. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  67841. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  67842. #endif /* !NO_PWDBASED && !NO_SHA256 */
  67843. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  67844. return EXPECT_RESULT();
  67845. }
  67846. static int test_no_op_functions(void)
  67847. {
  67848. EXPECT_DECLS;
  67849. #if defined(OPENSSL_EXTRA)
  67850. /* this makes sure wolfSSL can compile and run these no-op functions */
  67851. SSL_load_error_strings();
  67852. ENGINE_load_builtin_engines();
  67853. OpenSSL_add_all_ciphers();
  67854. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  67855. #endif
  67856. return EXPECT_RESULT();
  67857. }
  67858. static int test_wolfSSL_CRYPTO_memcmp(void)
  67859. {
  67860. EXPECT_DECLS;
  67861. #ifdef OPENSSL_EXTRA
  67862. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67863. "implementation of TLS/SSL for embedded devices to the cloud.";
  67864. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67865. "implementation of TLS/SSL for embedded devices to the cloud.";
  67866. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  67867. "implementation of TLS/SSL for embedded devices to the cloud!";
  67868. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  67869. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  67870. #endif
  67871. return EXPECT_RESULT();
  67872. }
  67873. /*----------------------------------------------------------------------------*
  67874. | wolfCrypt ASN
  67875. *----------------------------------------------------------------------------*/
  67876. static int test_wc_CreateEncryptedPKCS8Key(void)
  67877. {
  67878. EXPECT_DECLS;
  67879. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  67880. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  67881. !defined(NO_ASN_CRYPT)
  67882. WC_RNG rng;
  67883. byte* encKey = NULL;
  67884. word32 encKeySz = 0;
  67885. word32 decKeySz = 0;
  67886. const char password[] = "Lorem ipsum dolor sit amet";
  67887. word32 passwordSz = (word32)XSTRLEN(password);
  67888. word32 tradIdx = 0;
  67889. XMEMSET(&rng, 0, sizeof(WC_RNG));
  67890. ExpectIntEQ(wc_InitRng(&rng), 0);
  67891. PRIVATE_KEY_UNLOCK();
  67892. /* Call with NULL for out buffer to get necessary length. */
  67893. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  67894. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  67895. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  67896. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  67897. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  67898. DYNAMIC_TYPE_TMP_BUFFER));
  67899. /* Call with the allocated out buffer. */
  67900. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  67901. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  67902. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  67903. 0);
  67904. /* Decrypt the encrypted PKCS8 key we just made. */
  67905. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  67906. (int)passwordSz)), 0);
  67907. /* encKey now holds the decrypted key (decrypted in place). */
  67908. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  67909. /* Check that the decrypted key matches the key prior to encryption. */
  67910. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  67911. sizeof_server_key_der_2048), 0);
  67912. PRIVATE_KEY_LOCK();
  67913. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  67914. wc_FreeRng(&rng);
  67915. #endif
  67916. return EXPECT_RESULT();
  67917. }
  67918. static int test_wc_GetPkcs8TraditionalOffset(void)
  67919. {
  67920. EXPECT_DECLS;
  67921. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  67922. int length;
  67923. int derSz = 0;
  67924. word32 inOutIdx;
  67925. const char* path = "./certs/server-keyPkcs8.der";
  67926. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  67927. XFILE file = XBADFILE;
  67928. byte der[2048];
  67929. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  67930. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  67931. if (file != XBADFILE)
  67932. XFCLOSE(file);
  67933. file = XBADFILE; /* reset file to avoid warning of use after close */
  67934. /* valid case */
  67935. inOutIdx = 0;
  67936. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67937. 0);
  67938. /* inOutIdx > sz */
  67939. inOutIdx = 4000;
  67940. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67941. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67942. /* null input */
  67943. inOutIdx = 0;
  67944. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  67945. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67946. /* invalid input, fill buffer with 1's */
  67947. XMEMSET(der, 1, sizeof(der));
  67948. inOutIdx = 0;
  67949. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  67950. WC_NO_ERR_TRACE(ASN_PARSE_E));
  67951. /* test parsing with attributes */
  67952. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  67953. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  67954. if (file != XBADFILE)
  67955. XFCLOSE(file);
  67956. inOutIdx = 0;
  67957. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  67958. (word32)derSz), 0);
  67959. #endif /* NO_ASN */
  67960. return EXPECT_RESULT();
  67961. }
  67962. static int test_wc_SetSubjectRaw(void)
  67963. {
  67964. EXPECT_DECLS;
  67965. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67966. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  67967. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  67968. WOLFSSL_X509* x509 = NULL;
  67969. int peerCertSz;
  67970. const byte* peerCertBuf = NULL;
  67971. Cert forgedCert;
  67972. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  67973. WOLFSSL_FILETYPE_ASN1));
  67974. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  67975. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  67976. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  67977. wolfSSL_FreeX509(x509);
  67978. #endif
  67979. return EXPECT_RESULT();
  67980. }
  67981. static int test_wc_GetSubjectRaw(void)
  67982. {
  67983. EXPECT_DECLS;
  67984. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67985. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  67986. Cert cert;
  67987. byte *subjectRaw;
  67988. ExpectIntEQ(0, wc_InitCert(&cert));
  67989. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  67990. #endif
  67991. return EXPECT_RESULT();
  67992. }
  67993. static int test_wc_SetIssuerRaw(void)
  67994. {
  67995. EXPECT_DECLS;
  67996. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  67997. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  67998. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  67999. WOLFSSL_X509* x509 = NULL;
  68000. int peerCertSz;
  68001. const byte* peerCertBuf;
  68002. Cert forgedCert;
  68003. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68004. WOLFSSL_FILETYPE_ASN1));
  68005. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68006. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68007. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  68008. wolfSSL_FreeX509(x509);
  68009. #endif
  68010. return EXPECT_RESULT();
  68011. }
  68012. static int test_wc_SetIssueBuffer(void)
  68013. {
  68014. EXPECT_DECLS;
  68015. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68016. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68017. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68018. WOLFSSL_X509* x509 = NULL;
  68019. int peerCertSz;
  68020. const byte* peerCertBuf;
  68021. Cert forgedCert;
  68022. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68023. WOLFSSL_FILETYPE_ASN1));
  68024. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68025. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68026. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  68027. wolfSSL_FreeX509(x509);
  68028. #endif
  68029. return EXPECT_RESULT();
  68030. }
  68031. /*
  68032. * Testing wc_SetSubjectKeyId
  68033. */
  68034. static int test_wc_SetSubjectKeyId(void)
  68035. {
  68036. EXPECT_DECLS;
  68037. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68038. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68039. Cert cert;
  68040. const char* file = "certs/ecc-client-keyPub.pem";
  68041. ExpectIntEQ(0, wc_InitCert(&cert));
  68042. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  68043. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  68044. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  68045. #endif
  68046. return EXPECT_RESULT();
  68047. } /* END test_wc_SetSubjectKeyId */
  68048. /*
  68049. * Testing wc_SetSubject
  68050. */
  68051. static int test_wc_SetSubject(void)
  68052. {
  68053. EXPECT_DECLS;
  68054. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68055. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68056. Cert cert;
  68057. const char* file = "./certs/ca-ecc-cert.pem";
  68058. ExpectIntEQ(0, wc_InitCert(&cert));
  68059. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  68060. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  68061. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  68062. #endif
  68063. return EXPECT_RESULT();
  68064. } /* END test_wc_SetSubject */
  68065. static int test_CheckCertSignature(void)
  68066. {
  68067. EXPECT_DECLS;
  68068. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  68069. WOLFSSL_CERT_MANAGER* cm = NULL;
  68070. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68071. XFILE fp = XBADFILE;
  68072. byte cert[4096];
  68073. int certSz;
  68074. #endif
  68075. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  68076. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68077. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  68078. #ifndef NO_RSA
  68079. #ifdef USE_CERT_BUFFERS_1024
  68080. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  68081. sizeof_server_cert_der_1024, NULL, cm));
  68082. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68083. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  68084. WOLFSSL_FILETYPE_ASN1));
  68085. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  68086. sizeof_server_cert_der_1024, NULL, cm));
  68087. #elif defined(USE_CERT_BUFFERS_2048)
  68088. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  68089. sizeof_server_cert_der_2048, NULL, cm));
  68090. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68091. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  68092. WOLFSSL_FILETYPE_ASN1));
  68093. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  68094. sizeof_server_cert_der_2048, NULL, cm));
  68095. #endif
  68096. #endif
  68097. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68098. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  68099. sizeof_serv_ecc_der_256, NULL, cm));
  68100. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68101. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  68102. WOLFSSL_FILETYPE_ASN1));
  68103. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  68104. NULL, cm));
  68105. #endif
  68106. #if !defined(NO_FILESYSTEM)
  68107. wolfSSL_CertManagerFree(cm);
  68108. cm = NULL;
  68109. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68110. #ifndef NO_RSA
  68111. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  68112. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68113. if (fp != XBADFILE) {
  68114. XFCLOSE(fp);
  68115. fp = XBADFILE;
  68116. }
  68117. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68118. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68119. "./certs/ca-cert.pem", NULL));
  68120. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68121. #endif
  68122. #ifdef HAVE_ECC
  68123. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  68124. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68125. if (fp != XBADFILE) {
  68126. XFCLOSE(fp);
  68127. fp = XBADFILE;
  68128. }
  68129. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68130. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68131. "./certs/ca-ecc-cert.pem", NULL));
  68132. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68133. #endif
  68134. #endif
  68135. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68136. (void)fp;
  68137. (void)cert;
  68138. (void)certSz;
  68139. #endif
  68140. wolfSSL_CertManagerFree(cm);
  68141. #endif
  68142. return EXPECT_RESULT();
  68143. }
  68144. static int test_wc_ParseCert(void)
  68145. {
  68146. EXPECT_DECLS;
  68147. #if !defined(NO_CERTS) && !defined(NO_RSA)
  68148. DecodedCert decodedCert;
  68149. const byte* rawCert = client_cert_der_2048;
  68150. const int rawCertSize = sizeof_client_cert_der_2048;
  68151. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  68152. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68153. #ifndef IGNORE_NAME_CONSTRAINTS
  68154. /* check that the subjects emailAddress was not put in the alt name list */
  68155. ExpectNotNull(decodedCert.subjectEmail);
  68156. ExpectNull(decodedCert.altEmailNames);
  68157. #endif
  68158. wc_FreeDecodedCert(&decodedCert);
  68159. #endif
  68160. return EXPECT_RESULT();
  68161. }
  68162. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  68163. * the API safely errors out on badly-formed ASN input.
  68164. * NOTE: Test not compatible with released FIPS implementations!
  68165. */
  68166. static int test_wc_ParseCert_Error(void)
  68167. {
  68168. EXPECT_DECLS;
  68169. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  68170. (!defined(HAVE_FIPS) || \
  68171. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  68172. DecodedCert decodedCert;
  68173. int i;
  68174. /* Certificate data */
  68175. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  68176. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68177. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68178. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  68179. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  68180. /* Test data */
  68181. const struct testStruct {
  68182. const byte* c;
  68183. const int cSz;
  68184. const int expRet;
  68185. } t[] = {
  68186. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68187. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68188. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  68189. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  68190. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  68191. };
  68192. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  68193. for (i = 0; i < tSz; i++) {
  68194. WOLFSSL_MSG_EX("i == %d", i);
  68195. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  68196. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  68197. wc_FreeDecodedCert(&decodedCert);
  68198. }
  68199. #endif
  68200. return EXPECT_RESULT();
  68201. }
  68202. static int test_MakeCertWithPathLen(void)
  68203. {
  68204. EXPECT_DECLS;
  68205. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68206. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68207. const byte expectedPathLen = 7;
  68208. Cert cert;
  68209. DecodedCert decodedCert;
  68210. byte der[FOURK_BUF];
  68211. int derSize = 0;
  68212. WC_RNG rng;
  68213. ecc_key key;
  68214. int ret;
  68215. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68216. XMEMSET(&key, 0, sizeof(ecc_key));
  68217. XMEMSET(&cert, 0, sizeof(Cert));
  68218. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68219. ExpectIntEQ(wc_InitRng(&rng), 0);
  68220. ExpectIntEQ(wc_ecc_init(&key), 0);
  68221. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68222. ExpectIntEQ(wc_InitCert(&cert), 0);
  68223. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68224. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68225. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68226. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68227. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68228. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68229. CTC_NAME_SIZE);
  68230. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68231. CTC_NAME_SIZE);
  68232. cert.selfSigned = 1;
  68233. cert.isCA = 1;
  68234. cert.pathLen = expectedPathLen;
  68235. cert.pathLenSet = 1;
  68236. cert.sigType = CTC_SHA256wECDSA;
  68237. #ifdef WOLFSSL_CERT_EXT
  68238. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68239. #endif
  68240. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68241. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68242. FOURK_BUF, NULL, &key, &rng), 0);
  68243. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68244. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68245. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  68246. wc_FreeDecodedCert(&decodedCert);
  68247. ret = wc_ecc_free(&key);
  68248. ExpectIntEQ(ret, 0);
  68249. ret = wc_FreeRng(&rng);
  68250. ExpectIntEQ(ret, 0);
  68251. #endif
  68252. return EXPECT_RESULT();
  68253. }
  68254. static int test_MakeCertWith0Ser(void)
  68255. {
  68256. EXPECT_DECLS;
  68257. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68258. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  68259. defined(WOLFSSL_ASN_TEMPLATE)
  68260. Cert cert;
  68261. DecodedCert decodedCert;
  68262. byte der[FOURK_BUF];
  68263. int derSize = 0;
  68264. WC_RNG rng;
  68265. ecc_key key;
  68266. int ret;
  68267. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68268. XMEMSET(&key, 0, sizeof(ecc_key));
  68269. XMEMSET(&cert, 0, sizeof(Cert));
  68270. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68271. ExpectIntEQ(wc_InitRng(&rng), 0);
  68272. ExpectIntEQ(wc_ecc_init(&key), 0);
  68273. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68274. ExpectIntEQ(wc_InitCert(&cert), 0);
  68275. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68276. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68277. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68278. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68279. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68280. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68281. CTC_NAME_SIZE);
  68282. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68283. CTC_NAME_SIZE);
  68284. cert.selfSigned = 1;
  68285. cert.isCA = 1;
  68286. cert.sigType = CTC_SHA256wECDSA;
  68287. #ifdef WOLFSSL_CERT_EXT
  68288. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68289. #endif
  68290. /* set serial number to 0 */
  68291. cert.serialSz = 1;
  68292. cert.serial[0] = 0;
  68293. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68294. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68295. FOURK_BUF, NULL, &key, &rng), 0);
  68296. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68297. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  68298. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  68299. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68300. #else
  68301. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68302. #endif
  68303. wc_FreeDecodedCert(&decodedCert);
  68304. ret = wc_ecc_free(&key);
  68305. ExpectIntEQ(ret, 0);
  68306. ret = wc_FreeRng(&rng);
  68307. ExpectIntEQ(ret, 0);
  68308. #endif
  68309. return EXPECT_RESULT();
  68310. }
  68311. static int test_MakeCertWithCaFalse(void)
  68312. {
  68313. EXPECT_DECLS;
  68314. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  68315. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68316. const byte expectedIsCa = 0;
  68317. Cert cert;
  68318. DecodedCert decodedCert;
  68319. byte der[FOURK_BUF];
  68320. int derSize = 0;
  68321. WC_RNG rng;
  68322. ecc_key key;
  68323. int ret;
  68324. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68325. XMEMSET(&key, 0, sizeof(ecc_key));
  68326. XMEMSET(&cert, 0, sizeof(Cert));
  68327. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68328. ExpectIntEQ(wc_InitRng(&rng), 0);
  68329. ExpectIntEQ(wc_ecc_init(&key), 0);
  68330. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68331. ExpectIntEQ(wc_InitCert(&cert), 0);
  68332. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68333. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68334. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68335. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68336. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68337. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68338. CTC_NAME_SIZE);
  68339. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68340. CTC_NAME_SIZE);
  68341. cert.selfSigned = 1;
  68342. cert.isCA = expectedIsCa;
  68343. cert.isCaSet = 1;
  68344. cert.sigType = CTC_SHA256wECDSA;
  68345. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68346. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68347. FOURK_BUF, NULL, &key, &rng), 0);
  68348. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  68349. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68350. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  68351. wc_FreeDecodedCert(&decodedCert);
  68352. ret = wc_ecc_free(&key);
  68353. ExpectIntEQ(ret, 0);
  68354. ret = wc_FreeRng(&rng);
  68355. ExpectIntEQ(ret, 0);
  68356. #endif
  68357. return EXPECT_RESULT();
  68358. }
  68359. /*----------------------------------------------------------------------------*
  68360. | wolfCrypt ECC
  68361. *----------------------------------------------------------------------------*/
  68362. static int test_wc_ecc_get_curve_size_from_name(void)
  68363. {
  68364. EXPECT_DECLS;
  68365. #ifdef HAVE_ECC
  68366. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68367. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  68368. #endif
  68369. /* invalid case */
  68370. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  68371. /* NULL input */
  68372. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68373. #endif /* HAVE_ECC */
  68374. return EXPECT_RESULT();
  68375. }
  68376. static int test_wc_ecc_get_curve_id_from_name(void)
  68377. {
  68378. EXPECT_DECLS;
  68379. #ifdef HAVE_ECC
  68380. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68381. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  68382. ECC_SECP256R1);
  68383. #endif
  68384. /* invalid case */
  68385. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  68386. /* NULL input */
  68387. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68388. #endif /* HAVE_ECC */
  68389. return EXPECT_RESULT();
  68390. }
  68391. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  68392. !defined(HAVE_SELFTEST) && \
  68393. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  68394. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  68395. {
  68396. EXPECT_DECLS;
  68397. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68398. ecc_key* key;
  68399. const ecc_set_type* params = NULL;
  68400. int ret;
  68401. #endif
  68402. WOLFSSL_EC_KEY *ecKey = NULL;
  68403. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68404. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  68405. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  68406. if (EXPECT_SUCCESS()) {
  68407. ret = EC_KEY_generate_key(ecKey);
  68408. } else
  68409. ret = 0;
  68410. if (ret == 1) {
  68411. /* normal test */
  68412. key = (ecc_key*)ecKey->internal;
  68413. if (key != NULL) {
  68414. params = key->dp;
  68415. }
  68416. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  68417. ECC_SECP256R1);
  68418. }
  68419. #endif
  68420. /* invalid case, NULL input*/
  68421. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68422. wolfSSL_EC_KEY_free(ecKey);
  68423. return EXPECT_RESULT();
  68424. }
  68425. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  68426. static int test_wc_ecc_get_curve_id_from_params(void)
  68427. {
  68428. EXPECT_DECLS;
  68429. #ifdef HAVE_ECC
  68430. const byte prime[] =
  68431. {
  68432. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68433. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68434. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68435. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  68436. };
  68437. const byte primeInvalid[] =
  68438. {
  68439. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68440. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68441. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68442. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  68443. };
  68444. const byte Af[] =
  68445. {
  68446. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68447. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68448. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68449. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  68450. };
  68451. const byte Bf[] =
  68452. {
  68453. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  68454. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  68455. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  68456. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  68457. };
  68458. const byte order[] =
  68459. {
  68460. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  68461. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  68462. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  68463. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  68464. };
  68465. const byte Gx[] =
  68466. {
  68467. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  68468. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  68469. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  68470. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  68471. };
  68472. const byte Gy[] =
  68473. {
  68474. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  68475. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  68476. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  68477. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  68478. };
  68479. int cofactor = 1;
  68480. int fieldSize = 256;
  68481. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68482. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68483. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  68484. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  68485. ECC_SECP256R1);
  68486. #endif
  68487. /* invalid case, fieldSize = 0 */
  68488. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  68489. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68490. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68491. /* invalid case, NULL prime */
  68492. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  68493. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68494. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68495. /* invalid case, invalid prime */
  68496. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68497. primeInvalid, sizeof(primeInvalid),
  68498. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68499. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68500. #endif
  68501. return EXPECT_RESULT();
  68502. }
  68503. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  68504. {
  68505. EXPECT_DECLS;
  68506. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  68507. WOLFSSL_RSA* rsa = NULL;
  68508. WOLFSSL_EVP_PKEY* pkey = NULL;
  68509. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68510. const char* in = "What is easy to do is easy not to do.";
  68511. size_t inlen = XSTRLEN(in);
  68512. size_t outEncLen = 0;
  68513. byte* outEnc = NULL;
  68514. byte* outDec = NULL;
  68515. size_t outDecLen = 0;
  68516. size_t rsaKeySz = 2048/8; /* Bytes */
  68517. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68518. byte* inTmp = NULL;
  68519. byte* outEncTmp = NULL;
  68520. byte* outDecTmp = NULL;
  68521. #endif
  68522. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68523. DYNAMIC_TYPE_TMP_BUFFER));
  68524. if (outEnc != NULL) {
  68525. XMEMSET(outEnc, 0, rsaKeySz);
  68526. }
  68527. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68528. DYNAMIC_TYPE_TMP_BUFFER));
  68529. if (outDec != NULL) {
  68530. XMEMSET(outDec, 0, rsaKeySz);
  68531. }
  68532. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68533. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68534. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68535. if (EXPECT_FAIL()) {
  68536. RSA_free(rsa);
  68537. }
  68538. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68539. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68540. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68541. WOLFSSL_SUCCESS);
  68542. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  68543. since ctx uses it.*/
  68544. ExpectIntEQ(pkey->ref.count, 2);
  68545. EVP_PKEY_free(pkey);
  68546. ExpectIntEQ(pkey->ref.count, 1);
  68547. /* Encrypt data */
  68548. /* Check that we can get the required output buffer length by passing in a
  68549. * NULL output buffer. */
  68550. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  68551. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68552. ExpectIntEQ(rsaKeySz, outEncLen);
  68553. /* Now do the actual encryption. */
  68554. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  68555. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68556. /* Decrypt data */
  68557. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68558. /* Check that we can get the required output buffer length by passing in a
  68559. * NULL output buffer. */
  68560. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  68561. WOLFSSL_SUCCESS);
  68562. ExpectIntEQ(rsaKeySz, outDecLen);
  68563. /* Now do the actual decryption. */
  68564. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  68565. WOLFSSL_SUCCESS);
  68566. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  68567. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68568. /* The input length must be the same size as the RSA key.*/
  68569. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68570. DYNAMIC_TYPE_TMP_BUFFER));
  68571. if (inTmp != NULL) {
  68572. XMEMSET(inTmp, 9, rsaKeySz);
  68573. }
  68574. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68575. DYNAMIC_TYPE_TMP_BUFFER));
  68576. if (outEncTmp != NULL) {
  68577. XMEMSET(outEncTmp, 0, rsaKeySz);
  68578. }
  68579. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68580. DYNAMIC_TYPE_TMP_BUFFER));
  68581. if (outDecTmp != NULL) {
  68582. XMEMSET(outDecTmp, 0, rsaKeySz);
  68583. }
  68584. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68585. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68586. WOLFSSL_SUCCESS);
  68587. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  68588. WOLFSSL_SUCCESS);
  68589. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68590. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  68591. outEncLen), WOLFSSL_SUCCESS);
  68592. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  68593. #endif
  68594. EVP_PKEY_CTX_free(ctx);
  68595. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68596. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68597. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68598. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68599. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68600. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68601. #endif
  68602. #endif
  68603. return EXPECT_RESULT();
  68604. }
  68605. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68606. !defined(HAVE_SELFTEST)
  68607. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68608. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68609. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68610. #endif
  68611. #endif
  68612. #endif
  68613. #if defined(OPENSSL_EXTRA)
  68614. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68615. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68616. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68617. #endif
  68618. #endif
  68619. #endif
  68620. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68621. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68622. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68623. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68624. #endif
  68625. #endif
  68626. #endif
  68627. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68628. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  68629. {
  68630. EXPECT_DECLS;
  68631. #if defined(OPENSSL_EXTRA)
  68632. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68633. !defined(HAVE_SELFTEST)
  68634. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68635. WOLFSSL_RSA* rsa = NULL;
  68636. #endif
  68637. #endif
  68638. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68639. WOLFSSL_DSA* dsa = NULL;
  68640. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68641. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68642. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68643. WOLFSSL_EC_KEY* ecKey = NULL;
  68644. #endif
  68645. #endif
  68646. WOLFSSL_EVP_PKEY* pkey = NULL;
  68647. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68648. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  68649. const char* in = "What is easy to do is easy not to do.";
  68650. size_t inlen = XSTRLEN(in);
  68651. byte hash[SHA256_DIGEST_LENGTH] = {0};
  68652. byte zero[SHA256_DIGEST_LENGTH] = {0};
  68653. SHA256_CTX c;
  68654. byte* sig = NULL;
  68655. byte* sigVerify = NULL;
  68656. size_t siglen;
  68657. size_t siglenOnlyLen;
  68658. size_t keySz = 2048/8; /* Bytes */
  68659. ExpectNotNull(sig =
  68660. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68661. ExpectNotNull(sigVerify =
  68662. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68663. siglen = keySz;
  68664. ExpectNotNull(XMEMSET(sig, 0, keySz));
  68665. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  68666. /* Generate hash */
  68667. SHA256_Init(&c);
  68668. SHA256_Update(&c, in, inlen);
  68669. SHA256_Final(hash, &c);
  68670. #ifdef WOLFSSL_SMALL_STACK_CACHE
  68671. /* workaround for small stack cache case */
  68672. wc_Sha256Free((wc_Sha256*)&c);
  68673. #endif
  68674. /* Generate key */
  68675. ExpectNotNull(pkey = EVP_PKEY_new());
  68676. switch (keyType) {
  68677. case EVP_PKEY_RSA:
  68678. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68679. !defined(HAVE_SELFTEST)
  68680. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68681. {
  68682. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68683. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68684. }
  68685. #endif
  68686. #endif
  68687. break;
  68688. case EVP_PKEY_DSA:
  68689. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68690. ExpectNotNull(dsa = DSA_new());
  68691. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  68692. NULL, 0, NULL, NULL, NULL), 1);
  68693. ExpectIntEQ(DSA_generate_key(dsa), 1);
  68694. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  68695. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68696. break;
  68697. case EVP_PKEY_EC:
  68698. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68699. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68700. {
  68701. ExpectNotNull(ecKey = EC_KEY_new());
  68702. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  68703. ExpectIntEQ(
  68704. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68705. if (EXPECT_FAIL()) {
  68706. EC_KEY_free(ecKey);
  68707. }
  68708. }
  68709. #endif
  68710. #endif
  68711. break;
  68712. }
  68713. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68714. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68715. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68716. !defined(HAVE_SELFTEST)
  68717. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68718. if (keyType == EVP_PKEY_RSA)
  68719. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68720. WOLFSSL_SUCCESS);
  68721. #endif
  68722. #endif
  68723. /* Check returning only length */
  68724. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  68725. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68726. ExpectIntGT(siglenOnlyLen, 0);
  68727. /* Sign data */
  68728. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  68729. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68730. ExpectIntGE(siglenOnlyLen, siglen);
  68731. /* Verify signature */
  68732. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  68733. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68734. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68735. !defined(HAVE_SELFTEST)
  68736. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68737. if (keyType == EVP_PKEY_RSA)
  68738. ExpectIntEQ(
  68739. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  68740. WOLFSSL_SUCCESS);
  68741. #endif
  68742. #endif
  68743. ExpectIntEQ(EVP_PKEY_verify(
  68744. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  68745. WOLFSSL_SUCCESS);
  68746. ExpectIntEQ(EVP_PKEY_verify(
  68747. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  68748. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68749. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68750. !defined(HAVE_SELFTEST)
  68751. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68752. if (keyType == EVP_PKEY_RSA) {
  68753. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  68754. /* Try RSA sign/verify with no padding. */
  68755. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68756. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68757. WOLFSSL_SUCCESS);
  68758. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  68759. siglen), WOLFSSL_SUCCESS);
  68760. ExpectIntGE(siglenOnlyLen, siglen);
  68761. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68762. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68763. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  68764. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  68765. siglen), WOLFSSL_SUCCESS);
  68766. #endif
  68767. /* Wrong padding schemes. */
  68768. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68769. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  68770. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  68771. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  68772. siglen), WOLFSSL_SUCCESS);
  68773. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68774. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68775. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  68776. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  68777. siglen), WOLFSSL_SUCCESS);
  68778. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68779. WOLFSSL_SUCCESS);
  68780. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  68781. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  68782. }
  68783. #endif
  68784. #endif
  68785. /* error cases */
  68786. siglen = keySz; /* Reset because sig size may vary slightly */
  68787. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  68788. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68789. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  68790. WOLFSSL_SUCCESS);
  68791. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  68792. WOLFSSL_SUCCESS);
  68793. EVP_PKEY_free(pkey);
  68794. pkey = NULL;
  68795. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68796. DSA_free(dsa);
  68797. dsa = NULL;
  68798. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68799. EVP_PKEY_CTX_free(ctx_verify);
  68800. ctx_verify = NULL;
  68801. EVP_PKEY_CTX_free(ctx);
  68802. ctx = NULL;
  68803. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68804. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68805. #endif /* OPENSSL_EXTRA */
  68806. return EXPECT_RESULT();
  68807. }
  68808. #endif
  68809. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  68810. {
  68811. EXPECT_DECLS;
  68812. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68813. !defined(HAVE_SELFTEST)
  68814. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68815. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  68816. #endif
  68817. #endif
  68818. return EXPECT_RESULT();
  68819. }
  68820. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  68821. {
  68822. EXPECT_DECLS;
  68823. #if defined(OPENSSL_EXTRA)
  68824. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68825. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  68826. #endif
  68827. #endif
  68828. return EXPECT_RESULT();
  68829. }
  68830. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  68831. {
  68832. EXPECT_DECLS;
  68833. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68834. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68835. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  68836. #endif
  68837. #endif
  68838. return EXPECT_RESULT();
  68839. }
  68840. static int test_EVP_PKEY_rsa(void)
  68841. {
  68842. EXPECT_DECLS;
  68843. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  68844. WOLFSSL_RSA* rsa = NULL;
  68845. WOLFSSL_EVP_PKEY* pkey = NULL;
  68846. ExpectNotNull(rsa = wolfSSL_RSA_new());
  68847. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68848. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68849. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68850. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68851. if (EXPECT_FAIL()) {
  68852. wolfSSL_RSA_free(rsa);
  68853. }
  68854. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  68855. wolfSSL_EVP_PKEY_free(pkey);
  68856. #endif
  68857. return EXPECT_RESULT();
  68858. }
  68859. static int test_EVP_PKEY_ec(void)
  68860. {
  68861. EXPECT_DECLS;
  68862. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68863. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68864. WOLFSSL_EC_KEY* ecKey = NULL;
  68865. WOLFSSL_EVP_PKEY* pkey = NULL;
  68866. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  68867. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68868. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68869. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68870. /* Should fail since ecKey is empty */
  68871. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  68872. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  68873. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68874. if (EXPECT_FAIL()) {
  68875. wolfSSL_EC_KEY_free(ecKey);
  68876. }
  68877. wolfSSL_EVP_PKEY_free(pkey);
  68878. #endif
  68879. #endif
  68880. return EXPECT_RESULT();
  68881. }
  68882. static int test_EVP_PKEY_cmp(void)
  68883. {
  68884. EXPECT_DECLS;
  68885. #if defined(OPENSSL_EXTRA)
  68886. EVP_PKEY *a = NULL;
  68887. EVP_PKEY *b = NULL;
  68888. const unsigned char *in;
  68889. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  68890. in = client_key_der_2048;
  68891. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68892. &in, (long)sizeof_client_key_der_2048));
  68893. in = client_key_der_2048;
  68894. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68895. &in, (long)sizeof_client_key_der_2048));
  68896. /* Test success case RSA */
  68897. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68898. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  68899. #else
  68900. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68901. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68902. EVP_PKEY_free(b);
  68903. b = NULL;
  68904. EVP_PKEY_free(a);
  68905. a = NULL;
  68906. #endif
  68907. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68908. in = ecc_clikey_der_256;
  68909. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68910. &in, (long)sizeof_ecc_clikey_der_256));
  68911. in = ecc_clikey_der_256;
  68912. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68913. &in, (long)sizeof_ecc_clikey_der_256));
  68914. /* Test success case ECC */
  68915. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68916. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  68917. #else
  68918. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68919. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68920. EVP_PKEY_free(b);
  68921. b = NULL;
  68922. EVP_PKEY_free(a);
  68923. a = NULL;
  68924. #endif
  68925. /* Test failure cases */
  68926. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  68927. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68928. in = client_key_der_2048;
  68929. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  68930. &in, (long)sizeof_client_key_der_2048));
  68931. in = ecc_clikey_der_256;
  68932. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  68933. &in, (long)sizeof_ecc_clikey_der_256));
  68934. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68935. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  68936. #else
  68937. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  68938. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  68939. EVP_PKEY_free(b);
  68940. b = NULL;
  68941. EVP_PKEY_free(a);
  68942. a = NULL;
  68943. #endif
  68944. /* invalid or empty failure cases */
  68945. a = EVP_PKEY_new();
  68946. b = EVP_PKEY_new();
  68947. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  68948. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  68949. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  68950. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  68951. #ifdef NO_RSA
  68952. /* Type check will fail since RSA is the default EVP key type */
  68953. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  68954. #else
  68955. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  68956. #endif
  68957. #else
  68958. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  68959. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  68960. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  68961. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  68962. #endif
  68963. EVP_PKEY_free(b);
  68964. EVP_PKEY_free(a);
  68965. (void)in;
  68966. #endif
  68967. return EXPECT_RESULT();
  68968. }
  68969. static int test_ERR_load_crypto_strings(void)
  68970. {
  68971. #if defined(OPENSSL_ALL)
  68972. ERR_load_crypto_strings();
  68973. return TEST_SUCCESS;
  68974. #else
  68975. return TEST_SKIPPED;
  68976. #endif
  68977. }
  68978. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  68979. static void free_x509(X509* x)
  68980. {
  68981. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  68982. }
  68983. #endif
  68984. static int test_sk_X509(void)
  68985. {
  68986. EXPECT_DECLS;
  68987. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  68988. {
  68989. STACK_OF(X509)* s = NULL;
  68990. ExpectNotNull(s = sk_X509_new_null());
  68991. ExpectIntEQ(sk_X509_num(s), 0);
  68992. sk_X509_pop_free(s, NULL);
  68993. ExpectNotNull(s = sk_X509_new_null());
  68994. ExpectIntEQ(sk_X509_num(s), 0);
  68995. sk_X509_pop_free(s, NULL);
  68996. ExpectNotNull(s = sk_X509_new_null());
  68997. sk_X509_push(s, (X509*)1);
  68998. ExpectIntEQ(sk_X509_num(s), 1);
  68999. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  69000. sk_X509_push(s, (X509*)2);
  69001. ExpectIntEQ(sk_X509_num(s), 2);
  69002. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  69003. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  69004. sk_X509_push(s, (X509*)2);
  69005. sk_X509_pop_free(s, free_x509);
  69006. }
  69007. {
  69008. /* Push a list of 10 X509s onto stack, then verify that
  69009. * value(), push(), shift(), and pop() behave as expected. */
  69010. STACK_OF(X509)* s = NULL;
  69011. X509* xList[10];
  69012. int i = 0;
  69013. const int len = (sizeof(xList) / sizeof(xList[0]));
  69014. for (i = 0; i < len; ++i) {
  69015. xList[i] = NULL;
  69016. ExpectNotNull(xList[i] = X509_new());
  69017. }
  69018. /* test push, pop, and free */
  69019. ExpectNotNull(s = sk_X509_new_null());
  69020. for (i = 0; i < len; ++i) {
  69021. sk_X509_push(s, xList[i]);
  69022. ExpectIntEQ(sk_X509_num(s), i + 1);
  69023. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69024. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69025. }
  69026. /* pop returns and removes last pushed on stack, which is index 0
  69027. * in sk_x509_value */
  69028. for (i = 0; i < len; ++i) {
  69029. X509 * x = sk_X509_value(s, 0);
  69030. X509 * y = sk_X509_pop(s);
  69031. X509 * z = xList[len - 1 - i];
  69032. ExpectIntEQ((x == y), 1);
  69033. ExpectIntEQ((x == z), 1);
  69034. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69035. }
  69036. sk_free(s);
  69037. s = NULL;
  69038. /* test push, shift, and free */
  69039. ExpectNotNull(s = sk_X509_new_null());
  69040. for (i = 0; i < len; ++i) {
  69041. sk_X509_push(s, xList[i]);
  69042. ExpectIntEQ(sk_X509_num(s), i + 1);
  69043. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69044. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69045. }
  69046. /* shift returns and removes first pushed on stack, which is index i
  69047. * in sk_x509_value() */
  69048. for (i = 0; i < len; ++i) {
  69049. X509 * x = sk_X509_value(s, len - 1 - i);
  69050. X509 * y = sk_X509_shift(s);
  69051. X509 * z = xList[i];
  69052. ExpectIntEQ((x == y), 1);
  69053. ExpectIntEQ((x == z), 1);
  69054. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69055. }
  69056. sk_free(s);
  69057. for (i = 0; i < len; ++i)
  69058. X509_free(xList[i]);
  69059. }
  69060. #endif
  69061. return EXPECT_RESULT();
  69062. }
  69063. static int test_sk_X509_CRL(void)
  69064. {
  69065. EXPECT_DECLS;
  69066. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  69067. X509_CRL* crl = NULL;
  69068. XFILE fp = XBADFILE;
  69069. STACK_OF(X509_CRL)* s = NULL;
  69070. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  69071. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69072. NULL, NULL));
  69073. if (fp != XBADFILE)
  69074. XFCLOSE(fp);
  69075. ExpectNotNull(s = sk_X509_CRL_new());
  69076. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  69077. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  69078. if (EXPECT_FAIL()) {
  69079. X509_CRL_free(crl);
  69080. }
  69081. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  69082. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  69083. sk_X509_CRL_free(s);
  69084. #endif
  69085. return EXPECT_RESULT();
  69086. }
  69087. static int test_X509_get_signature_nid(void)
  69088. {
  69089. EXPECT_DECLS;
  69090. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69091. X509* x509 = NULL;
  69092. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  69093. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  69094. SSL_FILETYPE_PEM));
  69095. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  69096. X509_free(x509);
  69097. #endif
  69098. return EXPECT_RESULT();
  69099. }
  69100. static int test_X509_REQ(void)
  69101. {
  69102. EXPECT_DECLS;
  69103. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  69104. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  69105. X509_NAME* name = NULL;
  69106. #ifndef NO_RSA
  69107. X509_NAME* subject = NULL;
  69108. #endif
  69109. #if !defined(NO_RSA) || defined(HAVE_ECC)
  69110. X509_REQ* req = NULL;
  69111. EVP_PKEY* priv = NULL;
  69112. EVP_PKEY* pub = NULL;
  69113. unsigned char* der = NULL;
  69114. int len;
  69115. #endif
  69116. #ifndef NO_RSA
  69117. EVP_MD_CTX *mctx = NULL;
  69118. EVP_PKEY_CTX *pkctx = NULL;
  69119. #ifdef USE_CERT_BUFFERS_1024
  69120. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  69121. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  69122. #elif defined(USE_CERT_BUFFERS_2048)
  69123. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  69124. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  69125. #endif
  69126. #endif
  69127. #ifdef HAVE_ECC
  69128. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  69129. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  69130. #endif
  69131. ExpectNotNull(name = X509_NAME_new());
  69132. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  69133. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  69134. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  69135. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  69136. #ifndef NO_RSA
  69137. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  69138. (long)sizeof_client_key_der_2048));
  69139. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  69140. (long)sizeof_client_keypub_der_2048));
  69141. ExpectNotNull(req = X509_REQ_new());
  69142. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69143. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69144. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69145. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69146. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69147. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69148. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69149. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69150. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69151. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69152. len = i2d_X509_REQ(req, &der);
  69153. DEBUG_WRITE_DER(der, len, "req.der");
  69154. #ifdef USE_CERT_BUFFERS_1024
  69155. ExpectIntEQ(len, 381);
  69156. #else
  69157. ExpectIntEQ(len, 643);
  69158. #endif
  69159. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69160. der = NULL;
  69161. mctx = EVP_MD_CTX_new();
  69162. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  69163. WOLFSSL_SUCCESS);
  69164. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  69165. EVP_MD_CTX_free(mctx);
  69166. mctx = NULL;
  69167. X509_REQ_free(NULL);
  69168. X509_REQ_free(req);
  69169. req = NULL;
  69170. /* Test getting the subject from a newly created X509_REQ */
  69171. ExpectNotNull(req = X509_REQ_new());
  69172. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  69173. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  69174. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  69175. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  69176. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  69177. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  69178. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  69179. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  69180. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  69181. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  69182. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  69183. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  69184. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  69185. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69186. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69187. len = i2d_X509_REQ(req, &der);
  69188. DEBUG_WRITE_DER(der, len, "req2.der");
  69189. #ifdef USE_CERT_BUFFERS_1024
  69190. ExpectIntEQ(len, 435);
  69191. #else
  69192. ExpectIntEQ(len, 696);
  69193. #endif
  69194. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69195. der = NULL;
  69196. EVP_PKEY_free(pub);
  69197. pub = NULL;
  69198. EVP_PKEY_free(priv);
  69199. priv = NULL;
  69200. X509_REQ_free(req);
  69201. req = NULL;
  69202. #endif
  69203. #ifdef HAVE_ECC
  69204. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  69205. sizeof_ecc_clikey_der_256));
  69206. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  69207. sizeof_ecc_clikeypub_der_256));
  69208. ExpectNotNull(req = X509_REQ_new());
  69209. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69210. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69211. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69212. /* Signature is random and may be shorter or longer. */
  69213. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  69214. ExpectIntLE(len, 253);
  69215. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69216. X509_REQ_free(req);
  69217. EVP_PKEY_free(pub);
  69218. EVP_PKEY_free(priv);
  69219. #ifdef FP_ECC
  69220. wc_ecc_fp_free();
  69221. #endif
  69222. #endif /* HAVE_ECC */
  69223. X509_NAME_free(name);
  69224. #endif
  69225. return EXPECT_RESULT();
  69226. }
  69227. static int test_wolfssl_PKCS7(void)
  69228. {
  69229. EXPECT_DECLS;
  69230. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69231. !defined(NO_RSA)
  69232. PKCS7* pkcs7 = NULL;
  69233. byte data[FOURK_BUF];
  69234. word32 len = sizeof(data);
  69235. const byte* p = data;
  69236. byte content[] = "Test data to encode.";
  69237. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69238. BIO* bio = NULL;
  69239. byte key[sizeof(client_key_der_2048)];
  69240. word32 keySz = (word32)sizeof(key);
  69241. byte* out = NULL;
  69242. #endif
  69243. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  69244. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  69245. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  69246. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  69247. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69248. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  69249. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69250. PKCS7_free(pkcs7);
  69251. pkcs7 = NULL;
  69252. /* fail case, without PKCS7_NOVERIFY */
  69253. p = data;
  69254. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69255. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69256. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69257. PKCS7_free(pkcs7);
  69258. pkcs7 = NULL;
  69259. /* success case, with PKCS7_NOVERIFY */
  69260. p = data;
  69261. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69262. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69263. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  69264. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69265. /* test i2d */
  69266. XMEMCPY(key, client_key_der_2048, keySz);
  69267. if (pkcs7 != NULL) {
  69268. pkcs7->privateKey = key;
  69269. pkcs7->privateKeySz = (word32)sizeof(key);
  69270. pkcs7->encryptOID = RSAk;
  69271. #ifdef NO_SHA
  69272. pkcs7->hashOID = SHA256h;
  69273. #else
  69274. pkcs7->hashOID = SHAh;
  69275. #endif
  69276. }
  69277. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69278. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  69279. #ifndef NO_ASN_TIME
  69280. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  69281. #else
  69282. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  69283. #endif
  69284. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69285. BIO_free(bio);
  69286. #endif
  69287. PKCS7_free(NULL);
  69288. PKCS7_free(pkcs7);
  69289. #endif
  69290. return EXPECT_RESULT();
  69291. }
  69292. static int test_wolfSSL_PKCS7_sign(void)
  69293. {
  69294. EXPECT_DECLS;
  69295. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69296. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69297. PKCS7* p7 = NULL;
  69298. PKCS7* p7Ver = NULL;
  69299. byte* out = NULL;
  69300. byte* tmpPtr = NULL;
  69301. int outLen = 0;
  69302. int flags = 0;
  69303. byte data[] = "Test data to encode.";
  69304. const char* cert = "./certs/server-cert.pem";
  69305. const char* key = "./certs/server-key.pem";
  69306. const char* ca = "./certs/ca-cert.pem";
  69307. WOLFSSL_BIO* certBio = NULL;
  69308. WOLFSSL_BIO* keyBio = NULL;
  69309. WOLFSSL_BIO* caBio = NULL;
  69310. WOLFSSL_BIO* inBio = NULL;
  69311. X509* signCert = NULL;
  69312. EVP_PKEY* signKey = NULL;
  69313. X509* caCert = NULL;
  69314. X509_STORE* store = NULL;
  69315. #ifndef NO_PKCS7_STREAM
  69316. int z;
  69317. int ret;
  69318. #endif /* !NO_PKCS7_STREAM */
  69319. /* read signer cert/key into BIO */
  69320. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69321. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69322. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69323. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69324. /* read CA cert into store (for verify) */
  69325. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69326. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69327. ExpectNotNull(store = X509_STORE_new());
  69328. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69329. /* data to be signed into BIO */
  69330. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69331. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69332. /* PKCS7_sign, bad args: signer NULL */
  69333. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  69334. /* PKCS7_sign, bad args: signer key NULL */
  69335. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  69336. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  69337. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  69338. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  69339. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  69340. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  69341. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  69342. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  69343. {
  69344. flags = PKCS7_BINARY;
  69345. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69346. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69347. /* verify with d2i_PKCS7 */
  69348. tmpPtr = out;
  69349. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69350. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69351. PKCS7_free(p7Ver);
  69352. p7Ver = NULL;
  69353. /* verify with wc_PKCS7_VerifySignedData */
  69354. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69355. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69356. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69357. #ifndef NO_PKCS7_STREAM
  69358. /* verify with wc_PKCS7_VerifySignedData streaming */
  69359. wc_PKCS7_Free(p7Ver);
  69360. p7Ver = NULL;
  69361. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69362. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69363. /* test for streaming */
  69364. ret = -1;
  69365. for (z = 0; z < outLen && ret != 0; z++) {
  69366. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69367. if (ret < 0){
  69368. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69369. }
  69370. }
  69371. ExpectIntEQ(ret, 0);
  69372. #endif /* !NO_PKCS7_STREAM */
  69373. /* compare the signer found to expected signer */
  69374. ExpectIntNE(p7Ver->verifyCertSz, 0);
  69375. tmpPtr = NULL;
  69376. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  69377. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  69378. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  69379. tmpPtr = NULL;
  69380. wc_PKCS7_Free(p7Ver);
  69381. p7Ver = NULL;
  69382. ExpectNotNull(out);
  69383. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69384. out = NULL;
  69385. PKCS7_free(p7);
  69386. p7 = NULL;
  69387. }
  69388. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  69389. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  69390. {
  69391. /* re-populate input BIO, may have been consumed */
  69392. BIO_free(inBio);
  69393. inBio = NULL;
  69394. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69395. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69396. flags = PKCS7_BINARY | PKCS7_STREAM;
  69397. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69398. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69399. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69400. /* PKCS7_final, bad args: PKCS7 null */
  69401. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  69402. /* PKCS7_final, bad args: PKCS7 null */
  69403. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  69404. tmpPtr = out;
  69405. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69406. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69407. PKCS7_free(p7Ver);
  69408. p7Ver = NULL;
  69409. ExpectNotNull(out);
  69410. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69411. out = NULL;
  69412. PKCS7_free(p7);
  69413. p7 = NULL;
  69414. }
  69415. /* TEST SUCCESS: Detached, not streaming, not MIME */
  69416. {
  69417. /* re-populate input BIO, may have been consumed */
  69418. BIO_free(inBio);
  69419. inBio = NULL;
  69420. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69421. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69422. flags = PKCS7_BINARY | PKCS7_DETACHED;
  69423. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69424. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69425. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69426. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69427. if (p7Ver != NULL) {
  69428. p7Ver->content = data;
  69429. p7Ver->contentSz = sizeof(data);
  69430. }
  69431. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69432. wc_PKCS7_Free(p7Ver);
  69433. p7Ver = NULL;
  69434. #ifndef NO_PKCS7_STREAM
  69435. /* verify with wc_PKCS7_VerifySignedData streaming */
  69436. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69437. if (p7Ver != NULL) {
  69438. p7Ver->content = data;
  69439. p7Ver->contentSz = sizeof(data);
  69440. }
  69441. /* test for streaming */
  69442. ret = -1;
  69443. for (z = 0; z < outLen && ret != 0; z++) {
  69444. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69445. if (ret < 0){
  69446. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69447. }
  69448. }
  69449. ExpectIntEQ(ret, 0);
  69450. wc_PKCS7_Free(p7Ver);
  69451. p7Ver = NULL;
  69452. #endif /* !NO_PKCS7_STREAM */
  69453. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  69454. * yet support detached content */
  69455. tmpPtr = out;
  69456. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69457. PKCS7_free(p7Ver);
  69458. p7Ver = NULL;
  69459. ExpectNotNull(out);
  69460. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69461. out = NULL;
  69462. PKCS7_free(p7);
  69463. p7 = NULL;
  69464. }
  69465. /* TEST SUCCESS: Detached, streaming, not MIME */
  69466. {
  69467. /* re-populate input BIO, may have been consumed */
  69468. BIO_free(inBio);
  69469. inBio = NULL;
  69470. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69471. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69472. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  69473. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69474. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69475. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69476. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69477. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69478. if (p7Ver != NULL) {
  69479. p7Ver->content = data;
  69480. p7Ver->contentSz = sizeof(data);
  69481. }
  69482. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69483. wc_PKCS7_Free(p7Ver);
  69484. p7Ver = NULL;
  69485. ExpectNotNull(out);
  69486. #ifndef NO_PKCS7_STREAM
  69487. /* verify with wc_PKCS7_VerifySignedData streaming */
  69488. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69489. if (p7Ver != NULL) {
  69490. p7Ver->content = data;
  69491. p7Ver->contentSz = sizeof(data);
  69492. }
  69493. /* test for streaming */
  69494. ret = -1;
  69495. for (z = 0; z < outLen && ret != 0; z++) {
  69496. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69497. if (ret < 0){
  69498. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69499. }
  69500. }
  69501. ExpectIntEQ(ret, 0);
  69502. ExpectNotNull(out);
  69503. wc_PKCS7_Free(p7Ver);
  69504. p7Ver = NULL;
  69505. #endif /* !NO_PKCS7_STREAM */
  69506. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69507. PKCS7_free(p7);
  69508. p7 = NULL;
  69509. }
  69510. X509_STORE_free(store);
  69511. X509_free(caCert);
  69512. X509_free(signCert);
  69513. EVP_PKEY_free(signKey);
  69514. BIO_free(inBio);
  69515. BIO_free(keyBio);
  69516. BIO_free(certBio);
  69517. BIO_free(caBio);
  69518. #endif
  69519. return EXPECT_RESULT();
  69520. }
  69521. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  69522. {
  69523. EXPECT_DECLS;
  69524. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  69525. PKCS7_SIGNED* pkcs7 = NULL;
  69526. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  69527. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  69528. PKCS7_SIGNED_free(pkcs7);
  69529. #endif
  69530. return EXPECT_RESULT();
  69531. }
  69532. #ifndef NO_BIO
  69533. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  69534. {
  69535. EXPECT_DECLS;
  69536. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  69537. PKCS7* pkcs7 = NULL;
  69538. BIO* bio = NULL;
  69539. const byte* cert_buf = NULL;
  69540. int ret = 0;
  69541. WC_RNG rng;
  69542. const byte data[] = { /* Hello World */
  69543. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  69544. 0x72,0x6c,0x64
  69545. };
  69546. #ifndef NO_RSA
  69547. #if defined(USE_CERT_BUFFERS_2048)
  69548. byte key[sizeof(client_key_der_2048)];
  69549. byte cert[sizeof(client_cert_der_2048)];
  69550. word32 keySz = (word32)sizeof(key);
  69551. word32 certSz = (word32)sizeof(cert);
  69552. XMEMSET(key, 0, keySz);
  69553. XMEMSET(cert, 0, certSz);
  69554. XMEMCPY(key, client_key_der_2048, keySz);
  69555. XMEMCPY(cert, client_cert_der_2048, certSz);
  69556. #elif defined(USE_CERT_BUFFERS_1024)
  69557. byte key[sizeof_client_key_der_1024];
  69558. byte cert[sizeof(sizeof_client_cert_der_1024)];
  69559. word32 keySz = (word32)sizeof(key);
  69560. word32 certSz = (word32)sizeof(cert);
  69561. XMEMSET(key, 0, keySz);
  69562. XMEMSET(cert, 0, certSz);
  69563. XMEMCPY(key, client_key_der_1024, keySz);
  69564. XMEMCPY(cert, client_cert_der_1024, certSz);
  69565. #else
  69566. unsigned char cert[ONEK_BUF];
  69567. unsigned char key[ONEK_BUF];
  69568. XFILE fp = XBADFILE;
  69569. int certSz;
  69570. int keySz;
  69571. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  69572. XBADFILE);
  69573. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  69574. fp), 0);
  69575. if (fp != XBADFILE) {
  69576. XFCLOSE(fp);
  69577. fp = XBADFILE;
  69578. }
  69579. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  69580. XBADFILE);
  69581. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  69582. 0);
  69583. if (fp != XBADFILE) {
  69584. XFCLOSE(fp);
  69585. fp = XBADFILE;
  69586. }
  69587. #endif
  69588. #elif defined(HAVE_ECC)
  69589. #if defined(USE_CERT_BUFFERS_256)
  69590. unsigned char cert[sizeof(cliecc_cert_der_256)];
  69591. unsigned char key[sizeof(ecc_clikey_der_256)];
  69592. int certSz = (int)sizeof(cert);
  69593. int keySz = (int)sizeof(key);
  69594. XMEMSET(cert, 0, certSz);
  69595. XMEMSET(key, 0, keySz);
  69596. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  69597. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  69598. #else
  69599. unsigned char cert[ONEK_BUF];
  69600. unsigned char key[ONEK_BUF];
  69601. XFILE fp = XBADFILE;
  69602. int certSz, keySz;
  69603. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  69604. XBADFILE);
  69605. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  69606. fp), 0);
  69607. if (fp != XBADFILE) {
  69608. XFCLOSE(fp);
  69609. fp = XBADFILE;
  69610. }
  69611. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  69612. XBADFILE);
  69613. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  69614. 0);
  69615. if (fp != XBADFILE) {
  69616. XFCLOSE(fp);
  69617. fp = XBADFILE;
  69618. }
  69619. #endif
  69620. #else
  69621. #error PKCS7 requires ECC or RSA
  69622. #endif
  69623. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  69624. /* initialize with DER encoded cert */
  69625. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  69626. /* init rng */
  69627. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69628. ExpectIntEQ(wc_InitRng(&rng), 0);
  69629. if (pkcs7 != NULL) {
  69630. pkcs7->rng = &rng;
  69631. pkcs7->content = (byte*)data; /* not used for ex */
  69632. pkcs7->contentSz = (word32)sizeof(data);
  69633. pkcs7->contentOID = SIGNED_DATA;
  69634. pkcs7->privateKey = key;
  69635. pkcs7->privateKeySz = (word32)sizeof(key);
  69636. pkcs7->encryptOID = RSAk;
  69637. #ifdef NO_SHA
  69638. pkcs7->hashOID = SHA256h;
  69639. #else
  69640. pkcs7->hashOID = SHAh;
  69641. #endif
  69642. pkcs7->signedAttribs = NULL;
  69643. pkcs7->signedAttribsSz = 0;
  69644. }
  69645. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69646. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  69647. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  69648. /* Read PKCS#7 PEM from BIO */
  69649. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  69650. ExpectIntGE(ret, 0);
  69651. BIO_free(bio);
  69652. wc_PKCS7_Free(pkcs7);
  69653. wc_FreeRng(&rng);
  69654. #endif
  69655. return EXPECT_RESULT();
  69656. }
  69657. #ifdef HAVE_SMIME
  69658. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  69659. static int test_wolfSSL_SMIME_read_PKCS7(void)
  69660. {
  69661. EXPECT_DECLS;
  69662. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  69663. !defined(NO_RSA)
  69664. PKCS7* pkcs7 = NULL;
  69665. BIO* bio = NULL;
  69666. BIO* bcont = NULL;
  69667. BIO* out = NULL;
  69668. const byte* outBuf = NULL;
  69669. int outBufLen = 0;
  69670. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  69671. XFILE smimeTestFile = XBADFILE;
  69672. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  69673. XBADFILE);
  69674. /* smime-test.p7s */
  69675. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  69676. ExpectNotNull(bio);
  69677. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69678. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69679. ExpectNotNull(pkcs7);
  69680. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69681. PKCS7_NOVERIFY), SSL_SUCCESS);
  69682. if (smimeTestFile != XBADFILE) {
  69683. XFCLOSE(smimeTestFile);
  69684. smimeTestFile = XBADFILE;
  69685. }
  69686. if (bcont) BIO_free(bcont);
  69687. bcont = NULL;
  69688. wolfSSL_PKCS7_free(pkcs7);
  69689. pkcs7 = NULL;
  69690. /* smime-test-multipart.p7s */
  69691. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  69692. ExpectFalse(smimeTestFile == XBADFILE);
  69693. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69694. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69695. ExpectNotNull(pkcs7);
  69696. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69697. PKCS7_NOVERIFY), SSL_SUCCESS);
  69698. if (smimeTestFile != XBADFILE) {
  69699. XFCLOSE(smimeTestFile);
  69700. smimeTestFile = XBADFILE;
  69701. }
  69702. if (bcont) BIO_free(bcont);
  69703. bcont = NULL;
  69704. wolfSSL_PKCS7_free(pkcs7);
  69705. pkcs7 = NULL;
  69706. /* smime-test-multipart-badsig.p7s */
  69707. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  69708. ExpectFalse(smimeTestFile == XBADFILE);
  69709. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69710. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69711. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  69712. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69713. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69714. if (smimeTestFile != XBADFILE) {
  69715. XFCLOSE(smimeTestFile);
  69716. smimeTestFile = XBADFILE;
  69717. }
  69718. if (bcont) BIO_free(bcont);
  69719. bcont = NULL;
  69720. wolfSSL_PKCS7_free(pkcs7);
  69721. pkcs7 = NULL;
  69722. /* smime-test-canon.p7s */
  69723. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69724. ExpectFalse(smimeTestFile == XBADFILE);
  69725. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69726. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69727. ExpectNotNull(pkcs7);
  69728. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69729. PKCS7_NOVERIFY), SSL_SUCCESS);
  69730. if (smimeTestFile != XBADFILE) {
  69731. XFCLOSE(smimeTestFile);
  69732. smimeTestFile = XBADFILE;
  69733. }
  69734. if (bcont) BIO_free(bcont);
  69735. bcont = NULL;
  69736. wolfSSL_PKCS7_free(pkcs7);
  69737. pkcs7 = NULL;
  69738. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  69739. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69740. ExpectFalse(smimeTestFile == XBADFILE);
  69741. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69742. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69743. ExpectNotNull(pkcs7);
  69744. out = wolfSSL_BIO_new(BIO_s_mem());
  69745. ExpectNotNull(out);
  69746. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  69747. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  69748. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  69749. /* Content-Type should not show up at beginning of output buffer */
  69750. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  69751. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  69752. BIO_free(out);
  69753. BIO_free(bio);
  69754. if (bcont) BIO_free(bcont);
  69755. wolfSSL_PKCS7_free(pkcs7);
  69756. #endif
  69757. return EXPECT_RESULT();
  69758. }
  69759. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  69760. static int test_wolfSSL_SMIME_write_PKCS7(void)
  69761. {
  69762. EXPECT_DECLS;
  69763. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  69764. PKCS7* p7 = NULL;
  69765. PKCS7* p7Ver = NULL;
  69766. int flags = 0;
  69767. byte data[] = "Test data to encode.";
  69768. const char* cert = "./certs/server-cert.pem";
  69769. const char* key = "./certs/server-key.pem";
  69770. const char* ca = "./certs/ca-cert.pem";
  69771. WOLFSSL_BIO* certBio = NULL;
  69772. WOLFSSL_BIO* keyBio = NULL;
  69773. WOLFSSL_BIO* caBio = NULL;
  69774. WOLFSSL_BIO* inBio = NULL;
  69775. WOLFSSL_BIO* outBio = NULL;
  69776. WOLFSSL_BIO* content = NULL;
  69777. X509* signCert = NULL;
  69778. EVP_PKEY* signKey = NULL;
  69779. X509* caCert = NULL;
  69780. X509_STORE* store = NULL;
  69781. /* read signer cert/key into BIO */
  69782. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69783. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69784. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69785. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69786. /* read CA cert into store (for verify) */
  69787. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69788. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69789. ExpectNotNull(store = X509_STORE_new());
  69790. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69791. /* generate and verify SMIME: not detached */
  69792. {
  69793. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69794. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69795. flags = PKCS7_STREAM;
  69796. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69797. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69798. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69799. /* bad arg: out NULL */
  69800. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  69801. /* bad arg: pkcs7 NULL */
  69802. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  69803. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69804. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69805. BIO_free(content);
  69806. content = NULL;
  69807. BIO_free(inBio);
  69808. inBio = NULL;
  69809. BIO_free(outBio);
  69810. outBio = NULL;
  69811. PKCS7_free(p7Ver);
  69812. p7Ver = NULL;
  69813. PKCS7_free(p7);
  69814. p7 = NULL;
  69815. }
  69816. /* generate and verify SMIME: not detached, add Content-Type */
  69817. {
  69818. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69819. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69820. flags = PKCS7_STREAM | PKCS7_TEXT;
  69821. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69822. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69823. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69824. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69825. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69826. BIO_free(content);
  69827. content = NULL;
  69828. BIO_free(inBio);
  69829. inBio = NULL;
  69830. BIO_free(outBio);
  69831. outBio = NULL;
  69832. PKCS7_free(p7Ver);
  69833. p7Ver = NULL;
  69834. PKCS7_free(p7);
  69835. p7 = NULL;
  69836. }
  69837. /* generate and verify SMIME: detached */
  69838. {
  69839. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69840. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69841. flags = PKCS7_DETACHED | PKCS7_STREAM;
  69842. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69843. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69844. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69845. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69846. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  69847. BIO_free(content);
  69848. content = NULL;
  69849. BIO_free(inBio);
  69850. inBio = NULL;
  69851. BIO_free(outBio);
  69852. outBio = NULL;
  69853. PKCS7_free(p7Ver);
  69854. p7Ver = NULL;
  69855. PKCS7_free(p7);
  69856. p7 = NULL;
  69857. }
  69858. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  69859. {
  69860. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69861. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69862. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  69863. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69864. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  69865. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  69866. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  69867. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  69868. BIO_free(content);
  69869. content = NULL;
  69870. BIO_free(inBio);
  69871. inBio = NULL;
  69872. BIO_free(outBio);
  69873. outBio = NULL;
  69874. PKCS7_free(p7Ver);
  69875. p7Ver = NULL;
  69876. PKCS7_free(p7);
  69877. p7 = NULL;
  69878. }
  69879. X509_STORE_free(store);
  69880. X509_free(caCert);
  69881. X509_free(signCert);
  69882. EVP_PKEY_free(signKey);
  69883. BIO_free(keyBio);
  69884. BIO_free(certBio);
  69885. BIO_free(caBio);
  69886. #endif
  69887. return EXPECT_RESULT();
  69888. }
  69889. #endif /* HAVE_SMIME */
  69890. #endif /* !NO_BIO */
  69891. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  69892. * returns 0) */
  69893. static int test_X509_STORE_No_SSL_CTX(void)
  69894. {
  69895. EXPECT_DECLS;
  69896. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  69897. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  69898. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  69899. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  69900. defined(HAVE_CRL) && !defined(NO_RSA)
  69901. X509_STORE * store = NULL;
  69902. X509_STORE_CTX * storeCtx = NULL;
  69903. X509_CRL * crl = NULL;
  69904. X509 * ca = NULL;
  69905. X509 * cert = NULL;
  69906. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  69907. const char srvCert[] = "./certs/server-cert.pem";
  69908. const char caCert[] = "./certs/ca-cert.pem";
  69909. const char caDir[] = "./certs/crl/hash_pem";
  69910. XFILE fp = XBADFILE;
  69911. X509_LOOKUP * lookup = NULL;
  69912. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  69913. /* Set up store with CA */
  69914. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  69915. SSL_FILETYPE_PEM)));
  69916. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  69917. /* Add CRL lookup directory to store
  69918. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  69919. * of crl.pem */
  69920. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  69921. X509_LOOKUP_hash_dir())));
  69922. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  69923. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  69924. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  69925. SSL_SUCCESS);
  69926. /* Add CRL to store NOT containing the verified certificate, which
  69927. * forces use of the CRL lookup directory */
  69928. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  69929. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69930. NULL, NULL));
  69931. if (fp != XBADFILE)
  69932. XFCLOSE(fp);
  69933. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  69934. /* Create verification context outside of an SSL session */
  69935. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  69936. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  69937. SSL_FILETYPE_PEM)));
  69938. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  69939. /* Perform verification, which should NOT indicate CRL missing due to the
  69940. * store CM's X509 store pointer being NULL */
  69941. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  69942. X509_CRL_free(crl);
  69943. X509_STORE_free(store);
  69944. X509_STORE_CTX_free(storeCtx);
  69945. X509_free(cert);
  69946. X509_free(ca);
  69947. #endif
  69948. return EXPECT_RESULT();
  69949. }
  69950. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  69951. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  69952. static int test_X509_LOOKUP_add_dir(void)
  69953. {
  69954. EXPECT_DECLS;
  69955. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  69956. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  69957. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  69958. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  69959. defined(HAVE_CRL) && !defined(NO_RSA)
  69960. X509_STORE * store = NULL;
  69961. X509_STORE_CTX * storeCtx = NULL;
  69962. X509_CRL * crl = NULL;
  69963. X509 * ca = NULL;
  69964. X509 * cert = NULL;
  69965. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  69966. const char srvCert[] = "./certs/server-cert.pem";
  69967. const char caCert[] = "./certs/ca-cert.pem";
  69968. const char caDir[] = "./certs/crl/hash_der";
  69969. XFILE fp = XBADFILE;
  69970. X509_LOOKUP * lookup = NULL;
  69971. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  69972. /* Set up store with CA */
  69973. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  69974. SSL_FILETYPE_PEM)));
  69975. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  69976. /* Add CRL lookup directory to store.
  69977. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  69978. * of crl.der */
  69979. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  69980. X509_LOOKUP_hash_dir())));
  69981. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  69982. SSL_SUCCESS);
  69983. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  69984. SSL_SUCCESS);
  69985. /* Add CRL to store NOT containing the verified certificate, which
  69986. * forces use of the CRL lookup directory */
  69987. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  69988. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69989. NULL, NULL));
  69990. if (fp != XBADFILE) {
  69991. XFCLOSE(fp);
  69992. fp = XBADFILE;
  69993. }
  69994. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  69995. /* Create verification context outside of an SSL session */
  69996. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  69997. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  69998. SSL_FILETYPE_PEM)));
  69999. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70000. /* Perform verification, which should NOT return CRL missing */
  70001. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  70002. X509_CRL_free(crl);
  70003. crl = NULL;
  70004. X509_STORE_free(store);
  70005. store = NULL;
  70006. X509_STORE_CTX_free(storeCtx);
  70007. storeCtx = NULL;
  70008. X509_free(cert);
  70009. cert = NULL;
  70010. X509_free(ca);
  70011. ca = NULL;
  70012. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  70013. * We should get CRL_MISSING at the end, because the lookup
  70014. * dir has only ASN1 CRLs. */
  70015. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70016. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70017. SSL_FILETYPE_PEM)));
  70018. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70019. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70020. X509_LOOKUP_hash_dir())));
  70021. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  70022. SSL_SUCCESS);
  70023. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70024. SSL_SUCCESS);
  70025. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70026. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70027. NULL, NULL));
  70028. if (fp != XBADFILE) {
  70029. XFCLOSE(fp);
  70030. fp = XBADFILE;
  70031. }
  70032. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70033. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70034. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70035. SSL_FILETYPE_PEM)));
  70036. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70037. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  70038. * in dir containing only ASN1/DER. */
  70039. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70040. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  70041. X509_V_ERR_UNABLE_TO_GET_CRL);
  70042. X509_CRL_free(crl);
  70043. X509_STORE_free(store);
  70044. X509_STORE_CTX_free(storeCtx);
  70045. X509_free(cert);
  70046. X509_free(ca);
  70047. #endif
  70048. return EXPECT_RESULT();
  70049. }
  70050. /*----------------------------------------------------------------------------*
  70051. | Certificate Failure Checks
  70052. *----------------------------------------------------------------------------*/
  70053. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  70054. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  70055. #if !defined(NO_RSA) || defined(HAVE_ECC)
  70056. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  70057. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  70058. int type)
  70059. {
  70060. int ret;
  70061. WOLFSSL_CERT_MANAGER* cm = NULL;
  70062. switch (type) {
  70063. case TESTING_RSA:
  70064. #ifdef NO_RSA
  70065. fprintf(stderr, "RSA disabled, skipping test\n");
  70066. return ASN_SIG_CONFIRM_E;
  70067. #else
  70068. break;
  70069. #endif
  70070. case TESTING_ECC:
  70071. #ifndef HAVE_ECC
  70072. fprintf(stderr, "ECC disabled, skipping test\n");
  70073. return ASN_SIG_CONFIRM_E;
  70074. #else
  70075. break;
  70076. #endif
  70077. default:
  70078. fprintf(stderr, "Bad function argument\n");
  70079. return BAD_FUNC_ARG;
  70080. }
  70081. cm = wolfSSL_CertManagerNew();
  70082. if (cm == NULL) {
  70083. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  70084. return -1;
  70085. }
  70086. #ifndef NO_FILESYSTEM
  70087. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  70088. if (ret != WOLFSSL_SUCCESS) {
  70089. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  70090. wolfSSL_CertManagerFree(cm);
  70091. return ret;
  70092. }
  70093. #else
  70094. (void)ca;
  70095. #endif
  70096. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  70097. WOLFSSL_FILETYPE_ASN1);
  70098. /* Let ExpectIntEQ handle return code */
  70099. wolfSSL_CertManagerFree(cm);
  70100. return ret;
  70101. }
  70102. #endif
  70103. #if !defined(NO_FILESYSTEM)
  70104. static int test_RsaSigFailure_cm(void)
  70105. {
  70106. EXPECT_DECLS;
  70107. #ifndef NO_RSA
  70108. const char* ca_cert = "./certs/ca-cert.pem";
  70109. const char* server_cert = "./certs/server-cert.der";
  70110. byte* cert_buf = NULL;
  70111. size_t cert_sz = 0;
  70112. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70113. if ((cert_buf != NULL) && (cert_sz > 0)) {
  70114. /* corrupt DER - invert last byte, which is signature */
  70115. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70116. /* test bad cert */
  70117. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70118. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70119. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70120. #elif defined(NO_ASN_CRYPT)
  70121. /* RSA verify is not called when ASN crypt support is disabled */
  70122. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70123. WOLFSSL_SUCCESS);
  70124. #else
  70125. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70126. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70127. #endif
  70128. }
  70129. /* load_file() uses malloc. */
  70130. if (cert_buf != NULL) {
  70131. free(cert_buf);
  70132. }
  70133. #endif /* !NO_RSA */
  70134. return EXPECT_RESULT();
  70135. }
  70136. static int test_EccSigFailure_cm(void)
  70137. {
  70138. EXPECT_DECLS;
  70139. #ifdef HAVE_ECC
  70140. /* self-signed ECC cert, so use server cert as CA */
  70141. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  70142. const char* server_cert = "./certs/server-ecc.der";
  70143. byte* cert_buf = NULL;
  70144. size_t cert_sz = 0;
  70145. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70146. if (cert_buf != NULL && cert_sz > 0) {
  70147. /* corrupt DER - invert last byte, which is signature */
  70148. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70149. /* test bad cert */
  70150. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70151. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70152. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70153. #elif defined(NO_ASN_CRYPT)
  70154. /* ECC verify is not called when ASN crypt support is disabled */
  70155. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70156. WOLFSSL_SUCCESS);
  70157. #else
  70158. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70159. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70160. #endif
  70161. }
  70162. /* load_file() uses malloc. */
  70163. if (cert_buf != NULL) {
  70164. free(cert_buf);
  70165. }
  70166. #ifdef FP_ECC
  70167. wc_ecc_fp_free();
  70168. #endif
  70169. #endif /* HAVE_ECC */
  70170. return EXPECT_RESULT();
  70171. }
  70172. #endif /* !NO_FILESYSTEM */
  70173. #endif /* NO_CERTS */
  70174. #ifdef WOLFSSL_TLS13
  70175. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  70176. #ifdef WC_SHA384_DIGEST_SIZE
  70177. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  70178. #else
  70179. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  70180. #endif
  70181. #endif
  70182. #ifdef WOLFSSL_EARLY_DATA
  70183. static const char earlyData[] = "Early Data";
  70184. static char earlyDataBuffer[1];
  70185. #endif
  70186. static int test_tls13_apis(void)
  70187. {
  70188. EXPECT_DECLS;
  70189. int ret;
  70190. #ifndef WOLFSSL_NO_TLS12
  70191. #ifndef NO_WOLFSSL_CLIENT
  70192. WOLFSSL_CTX* clientTls12Ctx = NULL;
  70193. WOLFSSL* clientTls12Ssl = NULL;
  70194. #endif
  70195. #ifndef NO_WOLFSSL_SERVER
  70196. WOLFSSL_CTX* serverTls12Ctx = NULL;
  70197. WOLFSSL* serverTls12Ssl = NULL;
  70198. #endif
  70199. #endif
  70200. #ifndef NO_WOLFSSL_CLIENT
  70201. WOLFSSL_CTX* clientCtx = NULL;
  70202. WOLFSSL* clientSsl = NULL;
  70203. #endif
  70204. #ifndef NO_WOLFSSL_SERVER
  70205. WOLFSSL_CTX* serverCtx = NULL;
  70206. WOLFSSL* serverSsl = NULL;
  70207. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70208. const char* ourCert = svrCertFile;
  70209. const char* ourKey = svrKeyFile;
  70210. #endif
  70211. #endif
  70212. int required;
  70213. #ifdef WOLFSSL_EARLY_DATA
  70214. int outSz;
  70215. #endif
  70216. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  70217. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  70218. #ifdef WOLFSSL_HAVE_KYBER
  70219. #ifndef WOLFSSL_NO_KYBER512
  70220. WOLFSSL_KYBER_LEVEL1
  70221. #elif !defined(WOLFSSL_NO_KYBER768)
  70222. WOLFSSL_KYBER_LEVEL3
  70223. #else
  70224. WOLFSSL_KYBER_LEVEL5
  70225. #endif
  70226. #else
  70227. WOLFSSL_ECC_SECP256R1
  70228. #endif
  70229. };
  70230. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  70231. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  70232. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  70233. int numGroups = 2;
  70234. #endif
  70235. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70236. char groupList[] =
  70237. #ifdef HAVE_CURVE25519
  70238. "X25519:"
  70239. #endif
  70240. #ifdef HAVE_CURVE448
  70241. "X448:"
  70242. #endif
  70243. #ifndef NO_ECC_SECP
  70244. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  70245. "P-521:secp521r1:"
  70246. #endif
  70247. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  70248. "P-384:secp384r1:"
  70249. #endif
  70250. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  70251. "P-256:secp256r1"
  70252. #if defined(WOLFSSL_HAVE_KYBER)
  70253. #ifndef WOLFSSL_NO_KYBER512
  70254. ":P256_KYBER_LEVEL1"
  70255. #elif !defined(WOLFSSL_NO_KYBER768)
  70256. ":P256_KYBER_LEVEL3"
  70257. #else
  70258. ":P256_KYBER_LEVEL5"
  70259. #endif
  70260. #endif
  70261. #endif
  70262. #endif /* !defined(NO_ECC_SECP) */
  70263. #if defined(WOLFSSL_HAVE_KYBER)
  70264. #ifndef WOLFSSL_NO_KYBER512
  70265. ":KYBER_LEVEL1"
  70266. #elif !defined(WOLFSSL_NO_KYBER768)
  70267. ":KYBER_LEVEL3"
  70268. #else
  70269. ":KYBER_LEVEL5"
  70270. #endif
  70271. #endif
  70272. "";
  70273. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  70274. #if defined(WOLFSSL_HAVE_KYBER)
  70275. int kyberLevel;
  70276. #endif
  70277. (void)ret;
  70278. #ifndef WOLFSSL_NO_TLS12
  70279. #ifndef NO_WOLFSSL_CLIENT
  70280. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  70281. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  70282. #endif
  70283. #ifndef NO_WOLFSSL_SERVER
  70284. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  70285. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70286. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  70287. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  70288. WOLFSSL_FILETYPE_PEM);
  70289. #endif
  70290. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  70291. #endif
  70292. #endif
  70293. #ifndef NO_WOLFSSL_CLIENT
  70294. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  70295. clientSsl = wolfSSL_new(clientCtx);
  70296. #endif
  70297. #ifndef NO_WOLFSSL_SERVER
  70298. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  70299. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70300. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  70301. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  70302. #endif
  70303. serverSsl = wolfSSL_new(serverCtx);
  70304. ExpectNotNull(serverSsl);
  70305. #endif
  70306. #ifdef WOLFSSL_SEND_HRR_COOKIE
  70307. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70308. #ifndef NO_WOLFSSL_CLIENT
  70309. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70310. #endif
  70311. #ifndef NO_WOLFSSL_SERVER
  70312. #ifndef WOLFSSL_NO_TLS12
  70313. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  70314. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70315. #endif
  70316. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  70317. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  70318. WOLFSSL_SUCCESS);
  70319. #endif
  70320. #endif
  70321. #ifdef HAVE_SUPPORTED_CURVES
  70322. #ifdef HAVE_ECC
  70323. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70324. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70325. #ifndef NO_WOLFSSL_SERVER
  70326. do {
  70327. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  70328. #ifdef WOLFSSL_ASYNC_CRYPT
  70329. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70330. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  70331. #endif
  70332. }
  70333. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70334. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70335. #endif
  70336. #ifndef NO_WOLFSSL_CLIENT
  70337. #ifndef WOLFSSL_NO_TLS12
  70338. do {
  70339. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  70340. #ifdef WOLFSSL_ASYNC_CRYPT
  70341. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70342. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  70343. #endif
  70344. }
  70345. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70346. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70347. #endif
  70348. do {
  70349. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  70350. #ifdef WOLFSSL_ASYNC_CRYPT
  70351. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70352. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  70353. #endif
  70354. }
  70355. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70356. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70357. #endif
  70358. #elif defined(HAVE_CURVE25519)
  70359. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70360. #ifndef NO_WOLFSSL_SERVER
  70361. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  70362. WOLFSSL_SUCCESS);
  70363. #endif
  70364. #ifndef NO_WOLFSSL_CLIENT
  70365. #ifndef WOLFSSL_NO_TLS12
  70366. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  70367. WOLFSSL_SUCCESS);
  70368. #endif
  70369. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  70370. WOLFSSL_SUCCESS);
  70371. #endif
  70372. #elif defined(HAVE_CURVE448)
  70373. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70374. #ifndef NO_WOLFSSL_SERVER
  70375. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  70376. WOLFSSL_SUCCESS);
  70377. #endif
  70378. #ifndef NO_WOLFSSL_CLIENT
  70379. #ifndef WOLFSSL_NO_TLS12
  70380. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  70381. WOLFSSL_SUCCESS);
  70382. #endif
  70383. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  70384. WOLFSSL_SUCCESS);
  70385. #endif
  70386. #else
  70387. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70388. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70389. #ifndef NO_WOLFSSL_CLIENT
  70390. #ifndef WOLFSSL_NO_TLS12
  70391. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  70392. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70393. #endif
  70394. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  70395. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70396. #endif
  70397. #endif
  70398. #if defined(WOLFSSL_HAVE_KYBER)
  70399. #ifndef WOLFSSL_NO_KYBER768
  70400. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  70401. #elif !defined(WOLFSSL_NO_KYBER1024)
  70402. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  70403. #else
  70404. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  70405. #endif
  70406. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70407. #ifndef NO_WOLFSSL_SERVER
  70408. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  70409. WOLFSSL_SUCCESS);
  70410. #endif
  70411. #ifndef NO_WOLFSSL_CLIENT
  70412. #ifndef WOLFSSL_NO_TLS12
  70413. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  70414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70415. #endif
  70416. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  70417. WOLFSSL_SUCCESS);
  70418. #endif
  70419. #endif
  70420. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70421. #ifndef NO_WOLFSSL_SERVER
  70422. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70423. #endif
  70424. #ifndef NO_WOLFSSL_CLIENT
  70425. #ifndef WOLFSSL_NO_TLS12
  70426. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  70427. #endif
  70428. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  70429. #endif
  70430. #endif /* HAVE_SUPPORTED_CURVES */
  70431. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70432. #ifndef NO_WOLFSSL_CLIENT
  70433. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70434. #endif
  70435. #ifndef NO_WOLFSSL_SERVER
  70436. #ifndef WOLFSSL_NO_TLS12
  70437. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70438. #endif
  70439. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  70440. #endif
  70441. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70442. #ifndef NO_WOLFSSL_CLIENT
  70443. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70444. #endif
  70445. #ifndef NO_WOLFSSL_SERVER
  70446. #ifndef WOLFSSL_NO_TLS12
  70447. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70448. #endif
  70449. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  70450. #endif
  70451. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70452. #ifndef NO_WOLFSSL_CLIENT
  70453. #ifndef WOLFSSL_NO_TLS12
  70454. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70455. #endif
  70456. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  70457. #endif
  70458. #ifndef NO_WOLFSSL_SERVER
  70459. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  70460. #endif
  70461. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70462. #ifndef NO_WOLFSSL_CLIENT
  70463. #ifndef WOLFSSL_NO_TLS12
  70464. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70465. #endif
  70466. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  70467. #endif
  70468. #ifndef NO_WOLFSSL_SERVER
  70469. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  70470. #endif
  70471. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70472. #ifndef NO_WOLFSSL_CLIENT
  70473. #ifndef WOLFSSL_NO_TLS12
  70474. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70475. #endif
  70476. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70477. #endif
  70478. #ifndef NO_WOLFSSL_SERVER
  70479. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70480. #endif
  70481. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70482. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70483. #ifndef NO_WOLFSSL_CLIENT
  70484. #ifndef WOLFSSL_NO_TLS12
  70485. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  70486. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70487. #endif
  70488. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70489. #endif
  70490. #ifndef NO_WOLFSSL_SERVER
  70491. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70492. #endif
  70493. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  70494. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70495. #ifndef NO_WOLFSSL_SERVER
  70496. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70497. #endif
  70498. #ifndef NO_WOLFSSL_CLIENT
  70499. #ifndef WOLFSSL_NO_TLS12
  70500. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  70501. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70502. #endif
  70503. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  70504. #endif
  70505. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70506. #ifndef NO_WOLFSSL_SERVER
  70507. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70508. #endif
  70509. #ifndef NO_WOLFSSL_CLIENT
  70510. #ifndef WOLFSSL_NO_TLS12
  70511. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  70512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70513. #endif
  70514. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  70515. #endif
  70516. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70517. #ifndef NO_WOLFSSL_CLIENT
  70518. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70519. #endif
  70520. #ifndef NO_WOLFSSL_SERVER
  70521. #ifndef WOLFSSL_NO_TLS12
  70522. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  70523. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70524. #endif
  70525. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70526. #endif
  70527. #endif
  70528. #ifdef HAVE_ECC
  70529. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  70530. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70531. #ifndef NO_WOLFSSL_SERVER
  70532. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70533. #endif
  70534. #ifndef NO_WOLFSSL_CLIENT
  70535. #ifndef WOLFSSL_NO_TLS12
  70536. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70537. #endif
  70538. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70539. #endif
  70540. #endif
  70541. #ifdef HAVE_SUPPORTED_CURVES
  70542. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70543. #ifndef NO_WOLFSSL_CLIENT
  70544. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70545. #endif
  70546. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70547. #ifndef NO_WOLFSSL_CLIENT
  70548. #ifndef WOLFSSL_NO_TLS12
  70549. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  70550. WOLFSSL_SUCCESS);
  70551. #endif
  70552. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  70553. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70554. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  70555. WOLFSSL_SUCCESS);
  70556. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  70557. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70558. #endif
  70559. #ifndef NO_WOLFSSL_SERVER
  70560. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  70561. WOLFSSL_SUCCESS);
  70562. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  70563. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70564. #endif
  70565. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70566. #ifndef NO_WOLFSSL_CLIENT
  70567. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70568. #endif
  70569. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70570. #ifndef NO_WOLFSSL_CLIENT
  70571. #ifndef WOLFSSL_NO_TLS12
  70572. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  70573. WOLFSSL_SUCCESS);
  70574. #endif
  70575. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  70576. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70577. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  70578. WOLFSSL_SUCCESS);
  70579. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  70580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70581. #endif
  70582. #ifndef NO_WOLFSSL_SERVER
  70583. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  70584. WOLFSSL_SUCCESS);
  70585. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  70586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70587. #endif
  70588. #ifdef OPENSSL_EXTRA
  70589. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70590. #ifndef NO_WOLFSSL_CLIENT
  70591. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  70592. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70593. #endif
  70594. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  70595. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70596. #ifndef NO_WOLFSSL_CLIENT
  70597. #ifndef WOLFSSL_NO_TLS12
  70598. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  70599. WOLFSSL_SUCCESS);
  70600. #endif
  70601. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  70602. WOLFSSL_SUCCESS);
  70603. #endif
  70604. #ifndef NO_WOLFSSL_SERVER
  70605. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  70606. WOLFSSL_SUCCESS);
  70607. #endif
  70608. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70609. #ifndef NO_WOLFSSL_CLIENT
  70610. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70611. #endif
  70612. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70613. #ifndef NO_WOLFSSL_CLIENT
  70614. #ifndef WOLFSSL_NO_TLS12
  70615. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  70616. WOLFSSL_SUCCESS);
  70617. #endif
  70618. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  70619. WOLFSSL_SUCCESS);
  70620. #endif
  70621. #ifndef NO_WOLFSSL_SERVER
  70622. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  70623. WOLFSSL_SUCCESS);
  70624. #endif
  70625. #endif /* OPENSSL_EXTRA */
  70626. #endif /* HAVE_SUPPORTED_CURVES */
  70627. #endif /* HAVE_ECC */
  70628. #ifdef WOLFSSL_EARLY_DATA
  70629. #ifndef OPENSSL_EXTRA
  70630. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70631. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70632. #else
  70633. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70634. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70635. #endif
  70636. #ifndef NO_WOLFSSL_CLIENT
  70637. #ifndef OPENSSL_EXTRA
  70638. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70639. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70640. #else
  70641. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70642. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70643. #endif
  70644. #endif
  70645. #ifndef NO_WOLFSSL_SERVER
  70646. #ifndef WOLFSSL_NO_TLS12
  70647. #ifndef OPENSSL_EXTRA
  70648. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70650. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70651. #else
  70652. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70653. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70654. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70655. #endif
  70656. #endif
  70657. #ifndef OPENSSL_EXTRA
  70658. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70659. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  70660. WOLFSSL_SUCCESS);
  70661. #else
  70662. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  70663. #endif
  70664. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  70665. #else
  70666. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  70667. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  70668. #endif
  70669. #endif
  70670. #ifndef OPENSSL_EXTRA
  70671. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70672. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70673. #else
  70674. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70675. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70676. #endif
  70677. #ifndef NO_WOLFSSL_CLIENT
  70678. #ifndef OPENSSL_EXTRA
  70679. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70680. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70681. #else
  70682. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  70683. #endif
  70684. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  70685. #else
  70686. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70687. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  70688. #endif
  70689. #endif
  70690. #ifndef NO_WOLFSSL_SERVER
  70691. #ifndef WOLFSSL_NO_TLS12
  70692. #ifndef OPENSSL_EXTRA
  70693. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70694. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70695. #else
  70696. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70697. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70698. #endif
  70699. #endif
  70700. #ifndef OPENSSL_EXTRA
  70701. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70702. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  70703. #else
  70704. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  70705. #endif
  70706. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  70707. #else
  70708. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  70709. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  70710. #endif
  70711. #endif
  70712. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  70713. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70714. #ifndef NO_WOLFSSL_CLIENT
  70715. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  70716. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70717. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  70718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70719. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70720. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70721. #endif
  70722. #ifndef NO_WOLFSSL_SERVER
  70723. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  70724. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70725. #endif
  70726. #ifndef NO_WOLFSSL_CLIENT
  70727. #ifndef WOLFSSL_NO_TLS12
  70728. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  70729. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70730. #endif
  70731. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70732. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70733. #endif
  70734. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  70735. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70736. #ifndef NO_WOLFSSL_SERVER
  70737. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  70738. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70739. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  70740. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70741. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  70742. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70743. #endif
  70744. #ifndef NO_WOLFSSL_CLIENT
  70745. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  70746. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70747. #endif
  70748. #ifndef NO_WOLFSSL_SERVER
  70749. #ifndef WOLFSSL_NO_TLS12
  70750. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  70751. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70752. #endif
  70753. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  70754. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70755. #endif
  70756. #endif
  70757. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  70758. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  70759. #endif
  70760. #ifndef NO_WOLFSSL_SERVER
  70761. wolfSSL_free(serverSsl);
  70762. wolfSSL_CTX_free(serverCtx);
  70763. #endif
  70764. #ifndef NO_WOLFSSL_CLIENT
  70765. wolfSSL_free(clientSsl);
  70766. wolfSSL_CTX_free(clientCtx);
  70767. #endif
  70768. #ifndef WOLFSSL_NO_TLS12
  70769. #ifndef NO_WOLFSSL_SERVER
  70770. wolfSSL_free(serverTls12Ssl);
  70771. wolfSSL_CTX_free(serverTls12Ctx);
  70772. #endif
  70773. #ifndef NO_WOLFSSL_CLIENT
  70774. wolfSSL_free(clientTls12Ssl);
  70775. wolfSSL_CTX_free(clientTls12Ctx);
  70776. #endif
  70777. #endif
  70778. return EXPECT_RESULT();
  70779. }
  70780. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  70781. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  70782. defined(BUILD_TLS_AES_256_GCM_SHA384)
  70783. /* Called when writing. */
  70784. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  70785. {
  70786. (void)ssl;
  70787. (void)buf;
  70788. (void)sz;
  70789. (void)ctx;
  70790. /* Force error return from wolfSSL_accept_TLSv13(). */
  70791. return WANT_WRITE;
  70792. }
  70793. /* Called when reading. */
  70794. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  70795. {
  70796. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  70797. int len = (int)msg->length;
  70798. (void)ssl;
  70799. (void)sz;
  70800. /* Pass back as much of message as will fit in buffer. */
  70801. if (len > sz)
  70802. len = sz;
  70803. XMEMCPY(buf, msg->buffer, len);
  70804. /* Move over returned data. */
  70805. msg->buffer += len;
  70806. msg->length -= len;
  70807. /* Amount actually copied. */
  70808. return len;
  70809. }
  70810. #endif
  70811. static int test_tls13_cipher_suites(void)
  70812. {
  70813. EXPECT_DECLS;
  70814. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  70815. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  70816. defined(BUILD_TLS_AES_256_GCM_SHA384)
  70817. WOLFSSL_CTX* ctx = NULL;
  70818. WOLFSSL *ssl = NULL;
  70819. int i;
  70820. byte clientHello[] = {
  70821. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  70822. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  70823. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  70824. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  70825. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  70826. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  70827. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  70828. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  70829. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70830. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  70831. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  70832. 0x13, 0x01,
  70833. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  70834. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  70835. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  70836. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  70837. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  70838. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  70839. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  70840. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  70841. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  70842. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  70843. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  70844. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  70845. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  70846. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  70847. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  70848. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  70849. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  70850. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  70851. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  70852. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  70853. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  70854. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  70855. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  70856. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  70857. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  70858. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  70859. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  70860. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  70861. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  70862. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  70863. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  70864. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  70865. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  70866. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  70867. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  70868. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70869. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70870. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  70871. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  70872. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  70873. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  70874. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  70875. };
  70876. WOLFSSL_BUFFER_INFO msg;
  70877. /* Offset into ClientHello message data of first cipher suite. */
  70878. const int csOff = 78;
  70879. /* Server cipher list. */
  70880. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  70881. /* Suite list with duplicates. */
  70882. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  70883. "TLS13-AES128-GCM-SHA256:"
  70884. "TLS13-AES256-GCM-SHA384:"
  70885. "TLS13-AES256-GCM-SHA384:"
  70886. "TLS13-AES128-GCM-SHA256";
  70887. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  70888. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  70889. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  70890. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  70891. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  70892. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  70893. #endif
  70894. /* Set up wolfSSL context. */
  70895. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  70896. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  70897. WOLFSSL_FILETYPE_PEM));
  70898. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  70899. WOLFSSL_FILETYPE_PEM));
  70900. /* Read from 'msg'. */
  70901. wolfSSL_SetIORecv(ctx, CsRecv);
  70902. /* No where to send to - dummy sender. */
  70903. wolfSSL_SetIOSend(ctx, CsSend);
  70904. /* Test cipher suite list with many copies of a cipher suite. */
  70905. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70906. msg.buffer = clientHello;
  70907. msg.length = (unsigned int)sizeof(clientHello);
  70908. wolfSSL_SetIOReadCtx(ssl, &msg);
  70909. /* Force server to have as many occurrences of same cipher suite as
  70910. * possible. */
  70911. if (ssl != NULL) {
  70912. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  70913. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  70914. for (i = 0; i < suites->suiteSz; i += 2) {
  70915. suites->suites[i + 0] = TLS13_BYTE;
  70916. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  70917. }
  70918. }
  70919. /* Test multiple occurrences of same cipher suite. */
  70920. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70921. wolfSSL_free(ssl);
  70922. ssl = NULL;
  70923. /* Set client order opposite to server order:
  70924. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  70925. clientHello[csOff + 0] = TLS13_BYTE;
  70926. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  70927. clientHello[csOff + 2] = TLS13_BYTE;
  70928. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  70929. /* Test server order negotiation. */
  70930. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70931. msg.buffer = clientHello;
  70932. msg.length = (unsigned int)sizeof(clientHello);
  70933. wolfSSL_SetIOReadCtx(ssl, &msg);
  70934. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  70935. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  70936. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  70937. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70938. /* Check refined order - server order. */
  70939. ExpectIntEQ(ssl->suites->suiteSz, 4);
  70940. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  70941. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  70942. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  70943. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  70944. wolfSSL_free(ssl);
  70945. ssl = NULL;
  70946. /* Test client order negotiation. */
  70947. ExpectNotNull(ssl = wolfSSL_new(ctx));
  70948. msg.buffer = clientHello;
  70949. msg.length = (unsigned int)sizeof(clientHello);
  70950. wolfSSL_SetIOReadCtx(ssl, &msg);
  70951. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  70952. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  70953. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  70954. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  70955. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70956. /* Check refined order - client order. */
  70957. ExpectIntEQ(ssl->suites->suiteSz, 4);
  70958. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  70959. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  70960. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  70961. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  70962. wolfSSL_free(ssl);
  70963. ssl = NULL;
  70964. /* Check duplicate detection is working. */
  70965. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  70966. ExpectIntEQ(ctx->suites->suiteSz, 4);
  70967. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  70968. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  70969. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  70970. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  70971. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  70972. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  70973. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  70974. ExpectIntEQ(ctx->suites->suiteSz, 4);
  70975. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  70976. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  70977. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  70978. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  70979. #endif
  70980. wolfSSL_CTX_free(ctx);
  70981. #endif
  70982. return EXPECT_RESULT();
  70983. }
  70984. #endif
  70985. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  70986. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  70987. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  70988. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  70989. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  70990. const unsigned char* priv, unsigned int privSz,
  70991. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  70992. unsigned char* out, unsigned int* outlen,
  70993. void* ctx)
  70994. {
  70995. int result;
  70996. /* Test fail when context associated with WOLFSSL is NULL */
  70997. if (ctx == NULL) {
  70998. return -1;
  70999. }
  71000. (void)ssl;
  71001. /* return 0 on success */
  71002. PRIVATE_KEY_UNLOCK();
  71003. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  71004. PRIVATE_KEY_LOCK();
  71005. return result;
  71006. }
  71007. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  71008. EXPECT_DECLS;
  71009. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  71010. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  71011. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  71012. WOLFSSL_SUCCESS);
  71013. #endif
  71014. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  71015. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  71016. WOLFSSL_SUCCESS);
  71017. #endif
  71018. return EXPECT_RESULT();
  71019. }
  71020. static int test_dh_ssl_setup(WOLFSSL* ssl)
  71021. {
  71022. EXPECT_DECLS;
  71023. static int dh_test_ctx = 1;
  71024. int ret;
  71025. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  71026. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  71027. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71028. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71029. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71030. }
  71031. return EXPECT_RESULT();
  71032. }
  71033. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  71034. {
  71035. EXPECT_DECLS;
  71036. int ret;
  71037. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  71038. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  71039. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71040. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71041. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71042. }
  71043. return EXPECT_RESULT();
  71044. }
  71045. #endif
  71046. static int test_DhCallbacks(void)
  71047. {
  71048. EXPECT_DECLS;
  71049. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  71050. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  71051. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  71052. WOLFSSL_CTX *ctx = NULL;
  71053. WOLFSSL *ssl = NULL;
  71054. int test;
  71055. test_ssl_cbf func_cb_client;
  71056. test_ssl_cbf func_cb_server;
  71057. /* Test that DH callback APIs work. */
  71058. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  71059. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71060. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  71061. /* load client ca cert */
  71062. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  71063. WOLFSSL_SUCCESS);
  71064. /* test with NULL arguments */
  71065. wolfSSL_SetDhAgreeCtx(NULL, &test);
  71066. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  71067. /* test success case */
  71068. test = 1;
  71069. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71070. wolfSSL_SetDhAgreeCtx(ssl, &test);
  71071. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  71072. wolfSSL_free(ssl);
  71073. wolfSSL_CTX_free(ctx);
  71074. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71075. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71076. /* set callbacks to use DH functions */
  71077. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71078. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  71079. func_cb_client.method = wolfTLSv1_2_client_method;
  71080. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71081. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  71082. func_cb_server.method = wolfTLSv1_2_server_method;
  71083. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71084. &func_cb_server, NULL), TEST_SUCCESS);
  71085. /* Test fail */
  71086. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71087. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71088. /* set callbacks to use DH functions */
  71089. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71090. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  71091. func_cb_client.method = wolfTLSv1_2_client_method;
  71092. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71093. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  71094. func_cb_server.method = wolfTLSv1_2_server_method;
  71095. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71096. &func_cb_server, NULL), TEST_FAIL);
  71097. #endif
  71098. return EXPECT_RESULT();
  71099. }
  71100. #endif /* HAVE_PK_CALLBACKS */
  71101. #ifdef HAVE_HASHDRBG
  71102. #ifdef TEST_RESEED_INTERVAL
  71103. static int test_wc_RNG_GenerateBlock_Reseed(void)
  71104. {
  71105. EXPECT_DECLS;
  71106. int i;
  71107. WC_RNG rng;
  71108. byte key[32];
  71109. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71110. ExpectIntEQ(wc_InitRng(&rng), 0);
  71111. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  71112. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71113. }
  71114. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71115. return EXPECT_RESULT();
  71116. }
  71117. #endif /* TEST_RESEED_INTERVAL */
  71118. static int test_wc_RNG_GenerateBlock(void)
  71119. {
  71120. EXPECT_DECLS;
  71121. int i;
  71122. WC_RNG rng;
  71123. byte key[32];
  71124. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71125. ExpectIntEQ(wc_InitRng(&rng), 0);
  71126. for (i = 0; i < 10; i++) {
  71127. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71128. }
  71129. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71130. return EXPECT_RESULT();
  71131. }
  71132. #endif /* HAVE_HASHDRBG */
  71133. /*
  71134. * Testing get_rand_digit
  71135. */
  71136. static int test_get_rand_digit(void)
  71137. {
  71138. EXPECT_DECLS;
  71139. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  71140. WC_RNG rng;
  71141. mp_digit d;
  71142. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71143. ExpectIntEQ(wc_InitRng(&rng), 0);
  71144. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  71145. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71146. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71147. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71148. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71149. #endif
  71150. return EXPECT_RESULT();
  71151. } /* End test_get_rand_digit*/
  71152. /*
  71153. * Testing get_digit_count
  71154. */
  71155. static int test_get_digit_count(void)
  71156. {
  71157. EXPECT_DECLS;
  71158. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  71159. mp_int a;
  71160. XMEMSET(&a, 0, sizeof(mp_int));
  71161. ExpectIntEQ(mp_init(&a), 0);
  71162. ExpectIntEQ(get_digit_count(NULL), 0);
  71163. ExpectIntEQ(get_digit_count(&a), 0);
  71164. mp_clear(&a);
  71165. #endif
  71166. return EXPECT_RESULT();
  71167. } /* End test_get_digit_count*/
  71168. /*
  71169. * Testing mp_cond_copy
  71170. */
  71171. static int test_mp_cond_copy(void)
  71172. {
  71173. EXPECT_DECLS;
  71174. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  71175. defined(WOLFSSL_PUBLIC_MP)
  71176. mp_int a;
  71177. mp_int b;
  71178. int copy = 0;
  71179. XMEMSET(&a, 0, sizeof(mp_int));
  71180. XMEMSET(&b, 0, sizeof(mp_int));
  71181. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71182. ExpectIntEQ(mp_init(&b), MP_OKAY);
  71183. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71184. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71185. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71186. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  71187. mp_clear(&a);
  71188. mp_clear(&b);
  71189. #endif
  71190. return EXPECT_RESULT();
  71191. } /* End test_mp_cond_copy*/
  71192. /*
  71193. * Testing mp_rand
  71194. */
  71195. static int test_mp_rand(void)
  71196. {
  71197. EXPECT_DECLS;
  71198. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  71199. mp_int a;
  71200. WC_RNG rng;
  71201. int digits = 1;
  71202. XMEMSET(&a, 0, sizeof(mp_int));
  71203. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71204. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71205. ExpectIntEQ(wc_InitRng(&rng), 0);
  71206. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  71207. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71208. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71209. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  71210. mp_clear(&a);
  71211. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71212. #endif
  71213. return EXPECT_RESULT();
  71214. } /* End test_mp_rand*/
  71215. /*
  71216. * Testing get_digit
  71217. */
  71218. static int test_get_digit(void)
  71219. {
  71220. EXPECT_DECLS;
  71221. #if defined(WOLFSSL_PUBLIC_MP)
  71222. mp_int a;
  71223. int n = 0;
  71224. XMEMSET(&a, 0, sizeof(mp_int));
  71225. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71226. ExpectIntEQ(get_digit(NULL, n), 0);
  71227. ExpectIntEQ(get_digit(&a, n), 0);
  71228. mp_clear(&a);
  71229. #endif
  71230. return EXPECT_RESULT();
  71231. } /* End test_get_digit*/
  71232. /*
  71233. * Testing wc_export_int
  71234. */
  71235. static int test_wc_export_int(void)
  71236. {
  71237. EXPECT_DECLS;
  71238. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  71239. defined(WOLFSSL_PUBLIC_MP)
  71240. mp_int mp;
  71241. byte buf[32];
  71242. word32 keySz = (word32)sizeof(buf);
  71243. word32 len = (word32)sizeof(buf);
  71244. XMEMSET(&mp, 0, sizeof(mp_int));
  71245. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  71246. ExpectIntEQ(mp_set(&mp, 1234), 0);
  71247. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71249. len = sizeof(buf)-1;
  71250. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71251. WC_NO_ERR_TRACE(BUFFER_E));
  71252. len = sizeof(buf);
  71253. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  71254. len = 4; /* test input too small */
  71255. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  71256. len = sizeof(buf);
  71257. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  71258. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  71259. ExpectIntEQ(len, 5);
  71260. mp_clear(&mp);
  71261. #endif
  71262. return EXPECT_RESULT();
  71263. } /* End test_wc_export_int*/
  71264. static int test_wc_InitRngNonce(void)
  71265. {
  71266. EXPECT_DECLS;
  71267. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71268. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71269. HAVE_FIPS_VERSION >= 2))
  71270. WC_RNG rng;
  71271. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71272. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71273. word32 nonceSz = sizeof(nonce);
  71274. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  71275. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71276. #endif
  71277. return EXPECT_RESULT();
  71278. } /* End test_wc_InitRngNonce*/
  71279. /*
  71280. * Testing wc_InitRngNonce_ex
  71281. */
  71282. static int test_wc_InitRngNonce_ex(void)
  71283. {
  71284. EXPECT_DECLS;
  71285. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71286. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71287. HAVE_FIPS_VERSION >= 2))
  71288. WC_RNG rng;
  71289. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71290. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71291. word32 nonceSz = sizeof(nonce);
  71292. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  71293. 0);
  71294. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71295. #endif
  71296. return EXPECT_RESULT();
  71297. } /* End test_wc_InitRngNonce_ex */
  71298. static int test_wolfSSL_X509_CRL(void)
  71299. {
  71300. EXPECT_DECLS;
  71301. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  71302. X509_CRL *crl = NULL;
  71303. char pem[][100] = {
  71304. "./certs/crl/crl.pem",
  71305. "./certs/crl/crl2.pem",
  71306. "./certs/crl/caEccCrl.pem",
  71307. "./certs/crl/eccCliCRL.pem",
  71308. "./certs/crl/eccSrvCRL.pem",
  71309. ""
  71310. };
  71311. #ifndef NO_BIO
  71312. BIO *bio = NULL;
  71313. #endif
  71314. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71315. char der[][100] = {
  71316. "./certs/crl/crl.der",
  71317. "./certs/crl/crl2.der",
  71318. ""};
  71319. #endif
  71320. XFILE fp = XBADFILE;
  71321. int i;
  71322. for (i = 0; pem[i][0] != '\0'; i++)
  71323. {
  71324. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71325. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71326. NULL, NULL));
  71327. ExpectNotNull(crl);
  71328. X509_CRL_free(crl);
  71329. if (fp != XBADFILE) {
  71330. XFCLOSE(fp);
  71331. fp = XBADFILE;
  71332. }
  71333. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71334. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  71335. NULL));
  71336. if (EXPECT_FAIL()) {
  71337. crl = NULL;
  71338. }
  71339. ExpectNotNull(crl);
  71340. X509_CRL_free(crl);
  71341. crl = NULL;
  71342. if (fp != XBADFILE) {
  71343. XFCLOSE(fp);
  71344. fp = XBADFILE;
  71345. }
  71346. }
  71347. #ifndef NO_BIO
  71348. for (i = 0; pem[i][0] != '\0'; i++)
  71349. {
  71350. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  71351. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  71352. X509_CRL_free(crl);
  71353. crl = NULL;
  71354. BIO_free(bio);
  71355. bio = NULL;
  71356. }
  71357. #endif
  71358. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71359. for (i = 0; der[i][0] != '\0'; i++) {
  71360. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  71361. ExpectTrue((fp != XBADFILE));
  71362. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  71363. ExpectNotNull(crl);
  71364. X509_CRL_free(crl);
  71365. if (fp != XBADFILE) {
  71366. XFCLOSE(fp);
  71367. fp = XBADFILE;
  71368. }
  71369. fp = XFOPEN(der[i], "rb");
  71370. ExpectTrue((fp != XBADFILE));
  71371. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  71372. if (EXPECT_FAIL()) {
  71373. crl = NULL;
  71374. }
  71375. ExpectNotNull(crl);
  71376. X509_CRL_free(crl);
  71377. crl = NULL;
  71378. if (fp != XBADFILE) {
  71379. XFCLOSE(fp);
  71380. fp = XBADFILE;
  71381. }
  71382. }
  71383. #endif
  71384. #endif
  71385. return EXPECT_RESULT();
  71386. }
  71387. static int test_wolfSSL_X509_load_crl_file(void)
  71388. {
  71389. EXPECT_DECLS;
  71390. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71391. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71392. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  71393. int i;
  71394. char pem[][100] = {
  71395. "./certs/crl/crl.pem",
  71396. "./certs/crl/crl2.pem",
  71397. "./certs/crl/caEccCrl.pem",
  71398. "./certs/crl/eccCliCRL.pem",
  71399. "./certs/crl/eccSrvCRL.pem",
  71400. #ifdef WC_RSA_PSS
  71401. "./certs/crl/crl_rsapss.pem",
  71402. #endif
  71403. ""
  71404. };
  71405. char der[][100] = {
  71406. "./certs/crl/crl.der",
  71407. "./certs/crl/crl2.der",
  71408. ""
  71409. };
  71410. WOLFSSL_X509_STORE* store = NULL;
  71411. WOLFSSL_X509_LOOKUP* lookup = NULL;
  71412. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71413. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71414. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71415. X509_FILETYPE_PEM), 1);
  71416. #ifdef WC_RSA_PSS
  71417. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  71418. X509_FILETYPE_PEM), 1);
  71419. #endif
  71420. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71421. X509_FILETYPE_PEM), 1);
  71422. if (store) {
  71423. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71424. WOLFSSL_FILETYPE_PEM), 1);
  71425. /* since store hasn't yet known the revoked cert*/
  71426. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71427. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71428. }
  71429. for (i = 0; pem[i][0] != '\0'; i++) {
  71430. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  71431. 1);
  71432. }
  71433. if (store) {
  71434. /* since store knows crl list */
  71435. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71436. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71437. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71438. #ifdef WC_RSA_PSS
  71439. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71440. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  71441. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71442. #endif
  71443. }
  71444. /* once feeing store */
  71445. X509_STORE_free(store);
  71446. store = NULL;
  71447. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71448. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71449. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71450. X509_FILETYPE_PEM), 1);
  71451. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71452. X509_FILETYPE_PEM), 1);
  71453. if (store) {
  71454. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71455. WOLFSSL_FILETYPE_PEM), 1);
  71456. /* since store hasn't yet known the revoked cert*/
  71457. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71458. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71459. }
  71460. for (i = 0; der[i][0] != '\0'; i++) {
  71461. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  71462. 1);
  71463. }
  71464. if (store) {
  71465. /* since store knows crl list */
  71466. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71467. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71468. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71469. }
  71470. /* test for incorrect parameter */
  71471. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  71472. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  71473. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  71474. X509_STORE_free(store);
  71475. store = NULL;
  71476. #endif
  71477. return EXPECT_RESULT();
  71478. }
  71479. static int test_wolfSSL_i2d_X509(void)
  71480. {
  71481. EXPECT_DECLS;
  71482. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  71483. const unsigned char* cert_buf = server_cert_der_2048;
  71484. unsigned char* out = NULL;
  71485. unsigned char* tmp = NULL;
  71486. X509* cert = NULL;
  71487. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  71488. /* Pointer should be advanced */
  71489. ExpectPtrGT(cert_buf, server_cert_der_2048);
  71490. ExpectIntGT(i2d_X509(cert, &out), 0);
  71491. ExpectNotNull(out);
  71492. tmp = out;
  71493. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  71494. ExpectPtrGT(tmp, out);
  71495. if (out != NULL)
  71496. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  71497. X509_free(cert);
  71498. #endif
  71499. return EXPECT_RESULT();
  71500. }
  71501. static int test_wolfSSL_d2i_X509_REQ(void)
  71502. {
  71503. EXPECT_DECLS;
  71504. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71505. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  71506. !defined(WOLFSSL_SP_MATH)
  71507. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  71508. * were generated by libest
  71509. * ./certs/csr.attr.der contains sample attributes
  71510. * ./certs/csr.ext.der contains sample extensions */
  71511. const char* csrFile = "./certs/csr.signed.der";
  71512. const char* csrPopFile = "./certs/csr.attr.der";
  71513. const char* csrExtFile = "./certs/csr.ext.der";
  71514. /* ./certs/csr.dsa.pem is generated using
  71515. * openssl req -newkey dsa:certs/dsaparams.pem \
  71516. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  71517. * -outform PEM
  71518. * with the passphrase "wolfSSL"
  71519. */
  71520. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71521. const char* csrDsaFile = "./certs/csr.dsa.pem";
  71522. XFILE f = XBADFILE;
  71523. #endif
  71524. BIO* bio = NULL;
  71525. X509* req = NULL;
  71526. EVP_PKEY *pub_key = NULL;
  71527. {
  71528. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  71529. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71530. /*
  71531. * Extract the public key from the CSR
  71532. */
  71533. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71534. /*
  71535. * Verify the signature in the CSR
  71536. */
  71537. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71538. X509_free(req);
  71539. req = NULL;
  71540. BIO_free(bio);
  71541. bio = NULL;
  71542. EVP_PKEY_free(pub_key);
  71543. pub_key = NULL;
  71544. }
  71545. {
  71546. #ifdef OPENSSL_ALL
  71547. X509_ATTRIBUTE* attr = NULL;
  71548. ASN1_TYPE *at = NULL;
  71549. #endif
  71550. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  71551. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71552. /*
  71553. * Extract the public key from the CSR
  71554. */
  71555. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71556. /*
  71557. * Verify the signature in the CSR
  71558. */
  71559. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71560. #ifdef OPENSSL_ALL
  71561. /*
  71562. * Obtain the challenge password from the CSR
  71563. */
  71564. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71565. -1), 1);
  71566. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  71567. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71568. ExpectNotNull(at->value.asn1_string);
  71569. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  71570. "2xIE+qqp/rhyTXP+");
  71571. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  71572. #endif
  71573. X509_free(req);
  71574. req = NULL;
  71575. BIO_free(bio);
  71576. bio = NULL;
  71577. EVP_PKEY_free(pub_key);
  71578. pub_key = NULL;
  71579. }
  71580. {
  71581. #ifdef OPENSSL_ALL
  71582. X509_ATTRIBUTE* attr = NULL;
  71583. ASN1_TYPE *at = NULL;
  71584. STACK_OF(X509_EXTENSION) *exts = NULL;
  71585. #endif
  71586. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  71587. /* This CSR contains an Extension Request attribute so
  71588. * we test extension parsing in a CSR attribute here. */
  71589. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71590. /*
  71591. * Extract the public key from the CSR
  71592. */
  71593. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71594. /*
  71595. * Verify the signature in the CSR
  71596. */
  71597. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71598. #ifdef OPENSSL_ALL
  71599. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  71600. req));
  71601. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  71602. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  71603. /*
  71604. * Obtain the challenge password from the CSR
  71605. */
  71606. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71607. -1), 0);
  71608. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  71609. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71610. ExpectNotNull(at->value.asn1_string);
  71611. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  71612. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  71613. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  71614. #endif
  71615. X509_free(req);
  71616. req = NULL;
  71617. BIO_free(bio);
  71618. bio = NULL;
  71619. EVP_PKEY_free(pub_key);
  71620. pub_key = NULL;
  71621. }
  71622. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71623. {
  71624. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  71625. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  71626. /*
  71627. * Extract the public key from the CSR
  71628. */
  71629. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71630. /*
  71631. * Verify the signature in the CSR
  71632. */
  71633. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71634. X509_free(req);
  71635. req = NULL;
  71636. BIO_free(bio);
  71637. /* Run the same test, but with a file pointer instead of a BIO.
  71638. * (PEM_read_X509_REQ)*/
  71639. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  71640. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  71641. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71642. X509_free(req);
  71643. EVP_PKEY_free(pub_key);
  71644. }
  71645. #endif /* !NO_DSA && !HAVE_SELFTEST */
  71646. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  71647. return EXPECT_RESULT();
  71648. }
  71649. static int test_wolfSSL_PEM_read_X509(void)
  71650. {
  71651. EXPECT_DECLS;
  71652. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71653. !defined(NO_RSA)
  71654. X509 *x509 = NULL;
  71655. XFILE fp = XBADFILE;
  71656. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  71657. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  71658. X509_free(x509);
  71659. if (fp != XBADFILE)
  71660. XFCLOSE(fp);
  71661. #endif
  71662. return EXPECT_RESULT();
  71663. }
  71664. static int test_wolfSSL_PEM_read(void)
  71665. {
  71666. EXPECT_DECLS;
  71667. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  71668. const char* filename = "./certs/server-keyEnc.pem";
  71669. XFILE fp = XBADFILE;
  71670. char* name = NULL;
  71671. char* header = NULL;
  71672. byte* data = NULL;
  71673. long len;
  71674. EVP_CIPHER_INFO cipher;
  71675. WOLFSSL_BIO* bio = NULL;
  71676. byte* fileData = NULL;
  71677. size_t fileDataSz = 0;
  71678. byte* out;
  71679. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  71680. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  71681. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  71682. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  71683. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  71684. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71685. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71686. ExpectIntGT(XSTRLEN(header), 0);
  71687. ExpectIntGT(len, 0);
  71688. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71689. name = NULL;
  71690. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71691. header = NULL;
  71692. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71693. data = NULL;
  71694. BIO_free(bio);
  71695. bio = NULL;
  71696. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  71697. /* Fail cases. */
  71698. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71699. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71700. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71701. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71702. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71703. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71704. ExpectIntGT(XSTRLEN(header), 0);
  71705. ExpectIntGT(len, 0);
  71706. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71707. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71708. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71709. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71710. DYNAMIC_TYPE_TMP_BUFFER));
  71711. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71712. if (fp != XBADFILE) {
  71713. XFCLOSE(fp);
  71714. fp = XBADFILE;
  71715. }
  71716. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71717. /* Fail cases. */
  71718. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  71719. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  71720. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  71721. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  71722. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71723. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71724. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71725. /* Fail cases. */
  71726. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  71727. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  71728. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  71729. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  71730. /* Pass case */
  71731. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  71732. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71733. name = NULL;
  71734. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71735. header = NULL;
  71736. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71737. data = NULL;
  71738. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  71739. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71740. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71741. ExpectIntGT(XSTRLEN(header), 0);
  71742. ExpectIntGT(len, 0);
  71743. /* Fail cases. */
  71744. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71745. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71746. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71747. #ifndef NO_DES3
  71748. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  71749. #endif
  71750. /* Fail cases. */
  71751. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  71752. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71753. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  71754. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71755. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  71756. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71757. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  71758. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71759. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  71760. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71761. #if !defined(NO_DES3) && !defined(NO_MD5)
  71762. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  71763. (void*)"yassl123"), WOLFSSL_SUCCESS);
  71764. #else
  71765. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  71766. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71767. #endif
  71768. BIO_free(bio);
  71769. bio = NULL;
  71770. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71771. fileData = NULL;
  71772. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71773. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71774. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71775. name = NULL;
  71776. header = NULL;
  71777. data = NULL;
  71778. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  71779. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71780. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71781. ExpectIntEQ(XSTRLEN(header), 0);
  71782. ExpectIntGT(len, 0);
  71783. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71784. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71785. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71786. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71787. DYNAMIC_TYPE_TMP_BUFFER));
  71788. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71789. if (fp != XBADFILE)
  71790. XFCLOSE(fp);
  71791. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71792. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71793. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71794. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71795. BIO_free(bio);
  71796. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71797. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71798. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71799. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71800. #endif
  71801. return EXPECT_RESULT();
  71802. }
  71803. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  71804. {
  71805. EXPECT_DECLS;
  71806. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71807. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71808. const byte iv[12] = { 0 };
  71809. const byte key[16] = { 0 };
  71810. const byte cleartext[16] = { 0 };
  71811. const byte aad[] = {
  71812. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  71813. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  71814. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  71815. 0x4f
  71816. };
  71817. byte out1Part[16];
  71818. byte outTag1Part[16];
  71819. byte out2Part[16];
  71820. byte outTag2Part[16];
  71821. byte decryptBuf[16];
  71822. int len = 0;
  71823. int tlen;
  71824. EVP_CIPHER_CTX* ctx = NULL;
  71825. /* ENCRYPT */
  71826. /* Send AAD and data in 1 part */
  71827. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71828. tlen = 0;
  71829. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71830. 1);
  71831. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71832. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  71833. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  71834. sizeof(cleartext)), 1);
  71835. tlen += len;
  71836. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  71837. tlen += len;
  71838. ExpectIntEQ(tlen, sizeof(cleartext));
  71839. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  71840. outTag1Part), 1);
  71841. EVP_CIPHER_CTX_free(ctx);
  71842. ctx = NULL;
  71843. /* DECRYPT */
  71844. /* Send AAD and data in 1 part */
  71845. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71846. tlen = 0;
  71847. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71848. 1);
  71849. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71850. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  71851. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  71852. sizeof(cleartext)), 1);
  71853. tlen += len;
  71854. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  71855. outTag1Part), 1);
  71856. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  71857. tlen += len;
  71858. ExpectIntEQ(tlen, sizeof(cleartext));
  71859. EVP_CIPHER_CTX_free(ctx);
  71860. ctx = NULL;
  71861. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  71862. /* ENCRYPT */
  71863. /* Send AAD and data in 2 parts */
  71864. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71865. tlen = 0;
  71866. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71867. 1);
  71868. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71869. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  71870. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  71871. 1);
  71872. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  71873. tlen += len;
  71874. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  71875. sizeof(cleartext) - 1), 1);
  71876. tlen += len;
  71877. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  71878. tlen += len;
  71879. ExpectIntEQ(tlen, sizeof(cleartext));
  71880. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  71881. outTag2Part), 1);
  71882. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  71883. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  71884. EVP_CIPHER_CTX_free(ctx);
  71885. ctx = NULL;
  71886. /* DECRYPT */
  71887. /* Send AAD and data in 2 parts */
  71888. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  71889. tlen = 0;
  71890. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  71891. 1);
  71892. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  71893. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  71894. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  71895. 1);
  71896. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  71897. tlen += len;
  71898. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  71899. sizeof(cleartext) - 1), 1);
  71900. tlen += len;
  71901. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  71902. outTag1Part), 1);
  71903. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  71904. tlen += len;
  71905. ExpectIntEQ(tlen, sizeof(cleartext));
  71906. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  71907. /* Test AAD reuse */
  71908. EVP_CIPHER_CTX_free(ctx);
  71909. #endif
  71910. return EXPECT_RESULT();
  71911. }
  71912. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  71913. {
  71914. EXPECT_DECLS;
  71915. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71916. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71917. /* Zero length plain text */
  71918. byte key[] = {
  71919. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71920. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71921. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71922. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  71923. }; /* align */
  71924. byte iv[] = {
  71925. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  71926. }; /* align */
  71927. byte plaintxt[1];
  71928. int ivSz = 12;
  71929. int plaintxtSz = 0;
  71930. unsigned char tag[16];
  71931. unsigned char tag_kat[] = {
  71932. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  71933. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  71934. };
  71935. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  71936. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  71937. int ciphertxtSz = 0;
  71938. int decryptedtxtSz = 0;
  71939. int len = 0;
  71940. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  71941. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  71942. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  71943. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71944. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  71945. plaintxtSz));
  71946. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  71947. ciphertxtSz += len;
  71948. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  71949. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  71950. ExpectIntEQ(0, ciphertxtSz);
  71951. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  71952. EVP_CIPHER_CTX_init(de);
  71953. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  71954. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  71955. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  71956. decryptedtxtSz = len;
  71957. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  71958. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  71959. decryptedtxtSz += len;
  71960. ExpectIntEQ(0, decryptedtxtSz);
  71961. EVP_CIPHER_CTX_free(en);
  71962. EVP_CIPHER_CTX_free(de);
  71963. #endif
  71964. return EXPECT_RESULT();
  71965. }
  71966. static int test_wolfssl_EVP_aes_gcm(void)
  71967. {
  71968. EXPECT_DECLS;
  71969. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  71970. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  71971. /* A 256 bit key, AES_128 will use the first 128 bit*/
  71972. byte *key = (byte*)"01234567890123456789012345678901";
  71973. /* A 128 bit IV */
  71974. byte *iv = (byte*)"0123456789012345";
  71975. int ivSz = AES_BLOCK_SIZE;
  71976. /* Message to be encrypted */
  71977. byte *plaintxt = (byte*)"for things to change you have to change";
  71978. /* Additional non-confidential data */
  71979. byte *aad = (byte*)"Don't spend major time on minor things.";
  71980. unsigned char tag[AES_BLOCK_SIZE] = {0};
  71981. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  71982. int aadSz = (int)XSTRLEN((char*)aad);
  71983. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  71984. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  71985. int ciphertxtSz = 0;
  71986. int decryptedtxtSz = 0;
  71987. int len = 0;
  71988. int i = 0;
  71989. EVP_CIPHER_CTX en[2];
  71990. EVP_CIPHER_CTX de[2];
  71991. for (i = 0; i < 2; i++) {
  71992. EVP_CIPHER_CTX_init(&en[i]);
  71993. if (i == 0) {
  71994. /* Default uses 96-bits IV length */
  71995. #ifdef WOLFSSL_AES_128
  71996. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  71997. key, iv));
  71998. #elif defined(WOLFSSL_AES_192)
  71999. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72000. key, iv));
  72001. #elif defined(WOLFSSL_AES_256)
  72002. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72003. key, iv));
  72004. #endif
  72005. }
  72006. else {
  72007. #ifdef WOLFSSL_AES_128
  72008. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  72009. NULL, NULL));
  72010. #elif defined(WOLFSSL_AES_192)
  72011. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72012. NULL, NULL));
  72013. #elif defined(WOLFSSL_AES_256)
  72014. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72015. NULL, NULL));
  72016. #endif
  72017. /* non-default must to set the IV length first */
  72018. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  72019. ivSz, NULL));
  72020. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72021. }
  72022. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72023. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72024. plaintxtSz));
  72025. ciphertxtSz = len;
  72026. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72027. ciphertxtSz += len;
  72028. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  72029. AES_BLOCK_SIZE, tag));
  72030. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72031. EVP_CIPHER_CTX_init(&de[i]);
  72032. if (i == 0) {
  72033. /* Default uses 96-bits IV length */
  72034. #ifdef WOLFSSL_AES_128
  72035. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72036. key, iv));
  72037. #elif defined(WOLFSSL_AES_192)
  72038. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72039. key, iv));
  72040. #elif defined(WOLFSSL_AES_256)
  72041. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72042. key, iv));
  72043. #endif
  72044. }
  72045. else {
  72046. #ifdef WOLFSSL_AES_128
  72047. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72048. NULL, NULL));
  72049. #elif defined(WOLFSSL_AES_192)
  72050. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72051. NULL, NULL));
  72052. #elif defined(WOLFSSL_AES_256)
  72053. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72054. NULL, NULL));
  72055. #endif
  72056. /* non-default must to set the IV length first */
  72057. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72058. ivSz, NULL));
  72059. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72060. }
  72061. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72062. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72063. ciphertxtSz));
  72064. decryptedtxtSz = len;
  72065. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72066. AES_BLOCK_SIZE, tag));
  72067. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72068. decryptedtxtSz += len;
  72069. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72070. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72071. /* modify tag*/
  72072. if (i == 0) {
  72073. /* Default uses 96-bits IV length */
  72074. #ifdef WOLFSSL_AES_128
  72075. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72076. key, iv));
  72077. #elif defined(WOLFSSL_AES_192)
  72078. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72079. key, iv));
  72080. #elif defined(WOLFSSL_AES_256)
  72081. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72082. key, iv));
  72083. #endif
  72084. }
  72085. else {
  72086. #ifdef WOLFSSL_AES_128
  72087. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72088. NULL, NULL));
  72089. #elif defined(WOLFSSL_AES_192)
  72090. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72091. NULL, NULL));
  72092. #elif defined(WOLFSSL_AES_256)
  72093. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72094. NULL, NULL));
  72095. #endif
  72096. /* non-default must to set the IV length first */
  72097. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72098. ivSz, NULL));
  72099. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72100. }
  72101. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72102. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72103. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72104. AES_BLOCK_SIZE, tag));
  72105. /* fail due to wrong tag */
  72106. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72107. ciphertxtSz));
  72108. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72109. ExpectIntEQ(0, len);
  72110. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72111. }
  72112. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72113. return EXPECT_RESULT();
  72114. }
  72115. static int test_wolfssl_EVP_aria_gcm(void)
  72116. {
  72117. int res = TEST_SKIPPED;
  72118. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  72119. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72120. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72121. byte *key = (byte*)"01234567890123456789012345678901";
  72122. /* A 128 bit IV */
  72123. byte *iv = (byte*)"0123456789012345";
  72124. int ivSz = ARIA_BLOCK_SIZE;
  72125. /* Message to be encrypted */
  72126. const int plaintxtSz = 40;
  72127. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72128. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  72129. /* Additional non-confidential data */
  72130. byte *aad = (byte*)"Don't spend major time on minor things.";
  72131. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  72132. int aadSz = (int)XSTRLEN((char*)aad);
  72133. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72134. byte decryptedtxt[plaintxtSz];
  72135. int ciphertxtSz = 0;
  72136. int decryptedtxtSz = 0;
  72137. int len = 0;
  72138. int i = 0;
  72139. #define TEST_ARIA_GCM_COUNT 6
  72140. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  72141. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  72142. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  72143. EVP_CIPHER_CTX_init(&en[i]);
  72144. switch (i) {
  72145. case 0:
  72146. /* Default uses 96-bits IV length */
  72147. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  72148. break;
  72149. case 1:
  72150. /* Default uses 96-bits IV length */
  72151. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  72152. break;
  72153. case 2:
  72154. /* Default uses 96-bits IV length */
  72155. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  72156. break;
  72157. case 3:
  72158. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72159. /* non-default must to set the IV length first */
  72160. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72161. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72162. break;
  72163. case 4:
  72164. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72165. /* non-default must to set the IV length first */
  72166. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72167. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72168. break;
  72169. case 5:
  72170. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72171. /* non-default must to set the IV length first */
  72172. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72173. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72174. break;
  72175. }
  72176. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  72177. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72178. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  72179. ciphertxtSz = len;
  72180. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72181. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  72182. ciphertxtSz += len;
  72183. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  72184. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72185. EVP_CIPHER_CTX_init(&de[i]);
  72186. switch (i) {
  72187. case 0:
  72188. /* Default uses 96-bits IV length */
  72189. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  72190. break;
  72191. case 1:
  72192. /* Default uses 96-bits IV length */
  72193. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  72194. break;
  72195. case 2:
  72196. /* Default uses 96-bits IV length */
  72197. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  72198. break;
  72199. case 3:
  72200. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72201. /* non-default must to set the IV length first */
  72202. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72203. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72204. break;
  72205. case 4:
  72206. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72207. /* non-default must to set the IV length first */
  72208. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72209. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72210. break;
  72211. case 5:
  72212. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72213. /* non-default must to set the IV length first */
  72214. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72215. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72216. break;
  72217. }
  72218. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72219. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72220. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72221. decryptedtxtSz = len;
  72222. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72223. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72224. decryptedtxtSz += len;
  72225. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  72226. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72227. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72228. /* modify tag*/
  72229. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72230. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72231. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72232. /* fail due to wrong tag */
  72233. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72234. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72235. AssertIntEQ(0, len);
  72236. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72237. }
  72238. res = TEST_RES_CHECK(1);
  72239. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72240. return res;
  72241. }
  72242. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  72243. {
  72244. EXPECT_DECLS;
  72245. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72246. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72247. /* Zero length plain text */
  72248. byte key[] = {
  72249. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72250. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72251. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72253. }; /* align */
  72254. byte iv[] = {
  72255. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72256. }; /* align */
  72257. byte plaintxt[1];
  72258. int ivSz = 12;
  72259. int plaintxtSz = 0;
  72260. unsigned char tag[16];
  72261. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72262. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72263. int ciphertxtSz = 0;
  72264. int decryptedtxtSz = 0;
  72265. int len = 0;
  72266. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72267. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72268. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  72269. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72270. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72271. plaintxtSz));
  72272. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72273. ciphertxtSz += len;
  72274. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72275. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72276. ExpectIntEQ(0, ciphertxtSz);
  72277. EVP_CIPHER_CTX_init(de);
  72278. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  72279. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72280. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72281. decryptedtxtSz = len;
  72282. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72283. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72284. decryptedtxtSz += len;
  72285. ExpectIntEQ(0, decryptedtxtSz);
  72286. EVP_CIPHER_CTX_free(en);
  72287. EVP_CIPHER_CTX_free(de);
  72288. #endif
  72289. return EXPECT_RESULT();
  72290. }
  72291. static int test_wolfssl_EVP_aes_ccm(void)
  72292. {
  72293. EXPECT_DECLS;
  72294. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72295. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72296. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72297. byte *key = (byte*)"01234567890123456789012345678901";
  72298. /* A 128 bit IV */
  72299. byte *iv = (byte*)"0123456789012";
  72300. int ivSz = (int)XSTRLEN((char*)iv);
  72301. /* Message to be encrypted */
  72302. byte *plaintxt = (byte*)"for things to change you have to change";
  72303. /* Additional non-confidential data */
  72304. byte *aad = (byte*)"Don't spend major time on minor things.";
  72305. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72306. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72307. int aadSz = (int)XSTRLEN((char*)aad);
  72308. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72309. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72310. int ciphertxtSz = 0;
  72311. int decryptedtxtSz = 0;
  72312. int len = 0;
  72313. int i = 0;
  72314. int ret;
  72315. EVP_CIPHER_CTX en[2];
  72316. EVP_CIPHER_CTX de[2];
  72317. for (i = 0; i < 2; i++) {
  72318. EVP_CIPHER_CTX_init(&en[i]);
  72319. if (i == 0) {
  72320. /* Default uses 96-bits IV length */
  72321. #ifdef WOLFSSL_AES_128
  72322. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72323. key, iv));
  72324. #elif defined(WOLFSSL_AES_192)
  72325. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72326. key, iv));
  72327. #elif defined(WOLFSSL_AES_256)
  72328. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72329. key, iv));
  72330. #endif
  72331. }
  72332. else {
  72333. #ifdef WOLFSSL_AES_128
  72334. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72335. NULL, NULL));
  72336. #elif defined(WOLFSSL_AES_192)
  72337. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72338. NULL, NULL));
  72339. #elif defined(WOLFSSL_AES_256)
  72340. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72341. NULL, NULL));
  72342. #endif
  72343. /* non-default must to set the IV length first */
  72344. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72345. ivSz, NULL));
  72346. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72347. }
  72348. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72349. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72350. plaintxtSz));
  72351. ciphertxtSz = len;
  72352. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72353. ciphertxtSz += len;
  72354. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72355. AES_BLOCK_SIZE, tag));
  72356. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  72357. ExpectIntEQ(ret, 1);
  72358. EVP_CIPHER_CTX_init(&de[i]);
  72359. if (i == 0) {
  72360. /* Default uses 96-bits IV length */
  72361. #ifdef WOLFSSL_AES_128
  72362. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72363. key, iv));
  72364. #elif defined(WOLFSSL_AES_192)
  72365. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72366. key, iv));
  72367. #elif defined(WOLFSSL_AES_256)
  72368. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72369. key, iv));
  72370. #endif
  72371. }
  72372. else {
  72373. #ifdef WOLFSSL_AES_128
  72374. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72375. NULL, NULL));
  72376. #elif defined(WOLFSSL_AES_192)
  72377. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72378. NULL, NULL));
  72379. #elif defined(WOLFSSL_AES_256)
  72380. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72381. NULL, NULL));
  72382. #endif
  72383. /* non-default must to set the IV length first */
  72384. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72385. ivSz, NULL));
  72386. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72387. }
  72388. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72389. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72390. ciphertxtSz));
  72391. decryptedtxtSz = len;
  72392. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72393. AES_BLOCK_SIZE, tag));
  72394. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72395. decryptedtxtSz += len;
  72396. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72397. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72398. /* modify tag*/
  72399. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72400. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72401. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72402. AES_BLOCK_SIZE, tag));
  72403. /* fail due to wrong tag */
  72404. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72405. ciphertxtSz));
  72406. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72407. ExpectIntEQ(0, len);
  72408. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  72409. ExpectIntEQ(ret, 1);
  72410. }
  72411. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  72412. return EXPECT_RESULT();
  72413. }
  72414. static int test_wolfssl_EVP_chacha20_poly1305(void)
  72415. {
  72416. EXPECT_DECLS;
  72417. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  72418. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  72419. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  72420. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72421. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  72422. byte cipherText[sizeof(plainText)];
  72423. byte decryptedText[sizeof(plainText)];
  72424. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  72425. EVP_CIPHER_CTX* ctx = NULL;
  72426. int outSz;
  72427. XMEMSET(key, 0, sizeof(key));
  72428. XMEMSET(iv, 0, sizeof(iv));
  72429. /* Encrypt. */
  72430. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72431. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72432. NULL), WOLFSSL_SUCCESS);
  72433. /* Invalid IV length. */
  72434. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72435. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72436. /* Valid IV length. */
  72437. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72438. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72439. /* Invalid tag length. */
  72440. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72441. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72442. /* Valid tag length. */
  72443. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72444. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  72445. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72446. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72447. WOLFSSL_SUCCESS);
  72448. ExpectIntEQ(outSz, sizeof(aad));
  72449. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72450. sizeof(plainText)), WOLFSSL_SUCCESS);
  72451. ExpectIntEQ(outSz, sizeof(plainText));
  72452. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72453. ExpectIntEQ(outSz, 0);
  72454. /* Invalid tag length. */
  72455. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72456. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72457. /* Valid tag length. */
  72458. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72459. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72460. EVP_CIPHER_CTX_free(ctx);
  72461. ctx = NULL;
  72462. /* Decrypt. */
  72463. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72464. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72465. NULL), WOLFSSL_SUCCESS);
  72466. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72467. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72468. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72469. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72470. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72471. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72472. WOLFSSL_SUCCESS);
  72473. ExpectIntEQ(outSz, sizeof(aad));
  72474. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72475. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72476. ExpectIntEQ(outSz, sizeof(cipherText));
  72477. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72478. WOLFSSL_SUCCESS);
  72479. ExpectIntEQ(outSz, 0);
  72480. EVP_CIPHER_CTX_free(ctx);
  72481. ctx = NULL;
  72482. /* Test partial Inits. CipherInit() allow setting of key and iv
  72483. * in separate calls. */
  72484. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72485. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  72486. key, NULL, 1), WOLFSSL_SUCCESS);
  72487. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72488. WOLFSSL_SUCCESS);
  72489. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  72490. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  72491. ExpectIntEQ(outSz, sizeof(aad));
  72492. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72493. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72494. ExpectIntEQ(outSz, sizeof(cipherText));
  72495. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72496. WOLFSSL_SUCCESS);
  72497. ExpectIntEQ(outSz, 0);
  72498. EVP_CIPHER_CTX_free(ctx);
  72499. #endif
  72500. return EXPECT_RESULT();
  72501. }
  72502. static int test_wolfssl_EVP_chacha20(void)
  72503. {
  72504. EXPECT_DECLS;
  72505. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  72506. byte key[CHACHA_MAX_KEY_SZ];
  72507. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  72508. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72509. byte cipherText[sizeof(plainText)];
  72510. byte decryptedText[sizeof(plainText)];
  72511. EVP_CIPHER_CTX* ctx = NULL;
  72512. int outSz;
  72513. XMEMSET(key, 0, sizeof(key));
  72514. XMEMSET(iv, 0, sizeof(iv));
  72515. /* Encrypt. */
  72516. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72517. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72518. NULL), WOLFSSL_SUCCESS);
  72519. /* Any tag length must fail - not an AEAD cipher. */
  72520. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72521. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72522. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72523. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72524. sizeof(plainText)), WOLFSSL_SUCCESS);
  72525. ExpectIntEQ(outSz, sizeof(plainText));
  72526. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72527. ExpectIntEQ(outSz, 0);
  72528. EVP_CIPHER_CTX_free(ctx);
  72529. ctx = NULL;
  72530. /* Decrypt. */
  72531. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72532. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72533. NULL), WOLFSSL_SUCCESS);
  72534. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72535. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72536. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72537. ExpectIntEQ(outSz, sizeof(cipherText));
  72538. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72539. WOLFSSL_SUCCESS);
  72540. ExpectIntEQ(outSz, 0);
  72541. EVP_CIPHER_CTX_free(ctx);
  72542. ctx = NULL;
  72543. /* Test partial Inits. CipherInit() allow setting of key and iv
  72544. * in separate calls. */
  72545. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72546. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  72547. key, NULL, 1), WOLFSSL_SUCCESS);
  72548. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72549. WOLFSSL_SUCCESS);
  72550. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72551. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72552. ExpectIntEQ(outSz, sizeof(cipherText));
  72553. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72554. WOLFSSL_SUCCESS);
  72555. ExpectIntEQ(outSz, 0);
  72556. EVP_CIPHER_CTX_free(ctx);
  72557. #endif
  72558. return EXPECT_RESULT();
  72559. }
  72560. static int test_wolfssl_EVP_sm4_ecb(void)
  72561. {
  72562. int res = TEST_SKIPPED;
  72563. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  72564. EXPECT_DECLS;
  72565. byte key[SM4_KEY_SIZE];
  72566. byte plainText[SM4_BLOCK_SIZE] = {
  72567. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72568. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72569. };
  72570. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72571. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72572. EVP_CIPHER_CTX* ctx;
  72573. int outSz;
  72574. XMEMSET(key, 0, sizeof(key));
  72575. /* Encrypt. */
  72576. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72577. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72578. WOLFSSL_SUCCESS);
  72579. /* Any tag length must fail - not an AEAD cipher. */
  72580. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72581. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72582. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  72583. WOLFSSL_SUCCESS);
  72584. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72585. sizeof(plainText)), WOLFSSL_SUCCESS);
  72586. ExpectIntEQ(outSz, sizeof(plainText));
  72587. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72588. WOLFSSL_SUCCESS);
  72589. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72590. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72591. EVP_CIPHER_CTX_free(ctx);
  72592. /* Decrypt. */
  72593. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72594. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72595. WOLFSSL_SUCCESS);
  72596. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  72597. WOLFSSL_SUCCESS);
  72598. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72599. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72600. ExpectIntEQ(outSz, sizeof(plainText));
  72601. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72602. WOLFSSL_SUCCESS);
  72603. ExpectIntEQ(outSz, 0);
  72604. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72605. EVP_CIPHER_CTX_free(ctx);
  72606. res = EXPECT_RESULT();
  72607. #endif
  72608. return res;
  72609. }
  72610. static int test_wolfssl_EVP_sm4_cbc(void)
  72611. {
  72612. int res = TEST_SKIPPED;
  72613. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  72614. EXPECT_DECLS;
  72615. byte key[SM4_KEY_SIZE];
  72616. byte iv[SM4_BLOCK_SIZE];
  72617. byte plainText[SM4_BLOCK_SIZE] = {
  72618. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72619. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72620. };
  72621. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72622. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72623. EVP_CIPHER_CTX* ctx;
  72624. int outSz;
  72625. XMEMSET(key, 0, sizeof(key));
  72626. XMEMSET(iv, 0, sizeof(iv));
  72627. /* Encrypt. */
  72628. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72629. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72630. WOLFSSL_SUCCESS);
  72631. /* Any tag length must fail - not an AEAD cipher. */
  72632. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72633. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72634. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72635. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72636. sizeof(plainText)), WOLFSSL_SUCCESS);
  72637. ExpectIntEQ(outSz, sizeof(plainText));
  72638. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72639. WOLFSSL_SUCCESS);
  72640. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72641. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72642. EVP_CIPHER_CTX_free(ctx);
  72643. /* Decrypt. */
  72644. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72645. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72646. WOLFSSL_SUCCESS);
  72647. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72648. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72649. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72650. ExpectIntEQ(outSz, sizeof(plainText));
  72651. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72652. WOLFSSL_SUCCESS);
  72653. ExpectIntEQ(outSz, 0);
  72654. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72655. EVP_CIPHER_CTX_free(ctx);
  72656. /* Test partial Inits. CipherInit() allow setting of key and iv
  72657. * in separate calls. */
  72658. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72659. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  72660. WOLFSSL_SUCCESS);
  72661. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  72662. WOLFSSL_SUCCESS);
  72663. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72664. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72665. ExpectIntEQ(outSz, sizeof(plainText));
  72666. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72667. WOLFSSL_SUCCESS);
  72668. ExpectIntEQ(outSz, 0);
  72669. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72670. EVP_CIPHER_CTX_free(ctx);
  72671. res = EXPECT_RESULT();
  72672. #endif
  72673. return res;
  72674. }
  72675. static int test_wolfssl_EVP_sm4_ctr(void)
  72676. {
  72677. int res = TEST_SKIPPED;
  72678. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  72679. EXPECT_DECLS;
  72680. byte key[SM4_KEY_SIZE];
  72681. byte iv[SM4_BLOCK_SIZE];
  72682. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72683. byte cipherText[sizeof(plainText)];
  72684. byte decryptedText[sizeof(plainText)];
  72685. EVP_CIPHER_CTX* ctx;
  72686. int outSz;
  72687. XMEMSET(key, 0, sizeof(key));
  72688. XMEMSET(iv, 0, sizeof(iv));
  72689. /* Encrypt. */
  72690. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72691. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72692. WOLFSSL_SUCCESS);
  72693. /* Any tag length must fail - not an AEAD cipher. */
  72694. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72695. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72696. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72697. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72698. sizeof(plainText)), WOLFSSL_SUCCESS);
  72699. ExpectIntEQ(outSz, sizeof(plainText));
  72700. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72701. ExpectIntEQ(outSz, 0);
  72702. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72703. EVP_CIPHER_CTX_free(ctx);
  72704. /* Decrypt. */
  72705. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72706. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72707. WOLFSSL_SUCCESS);
  72708. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72709. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72710. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72711. ExpectIntEQ(outSz, sizeof(cipherText));
  72712. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72713. WOLFSSL_SUCCESS);
  72714. ExpectIntEQ(outSz, 0);
  72715. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72716. EVP_CIPHER_CTX_free(ctx);
  72717. /* Test partial Inits. CipherInit() allow setting of key and iv
  72718. * in separate calls. */
  72719. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72720. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  72721. WOLFSSL_SUCCESS);
  72722. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72723. WOLFSSL_SUCCESS);
  72724. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72725. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72726. ExpectIntEQ(outSz, sizeof(cipherText));
  72727. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72728. WOLFSSL_SUCCESS);
  72729. ExpectIntEQ(outSz, 0);
  72730. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72731. EVP_CIPHER_CTX_free(ctx);
  72732. res = EXPECT_RESULT();
  72733. #endif
  72734. return res;
  72735. }
  72736. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  72737. {
  72738. int res = TEST_SKIPPED;
  72739. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  72740. /* Zero length plain text */
  72741. EXPECT_DECLS;
  72742. byte key[] = {
  72743. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72744. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72745. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72746. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72747. }; /* align */
  72748. byte iv[] = {
  72749. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72750. }; /* align */
  72751. byte plaintxt[1];
  72752. int ivSz = 12;
  72753. int plaintxtSz = 0;
  72754. unsigned char tag[16];
  72755. unsigned char tag_kat[16] = {
  72756. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  72757. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  72758. };
  72759. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72760. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72761. int ciphertxtSz = 0;
  72762. int decryptedtxtSz = 0;
  72763. int len = 0;
  72764. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72765. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72766. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  72767. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72768. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72769. plaintxtSz));
  72770. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72771. ciphertxtSz += len;
  72772. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  72773. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72774. ExpectIntEQ(0, ciphertxtSz);
  72775. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  72776. EVP_CIPHER_CTX_init(de);
  72777. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  72778. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72779. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72780. decryptedtxtSz = len;
  72781. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  72782. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72783. decryptedtxtSz += len;
  72784. ExpectIntEQ(0, decryptedtxtSz);
  72785. EVP_CIPHER_CTX_free(en);
  72786. EVP_CIPHER_CTX_free(de);
  72787. res = EXPECT_RESULT();
  72788. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  72789. return res;
  72790. }
  72791. static int test_wolfssl_EVP_sm4_gcm(void)
  72792. {
  72793. int res = TEST_SKIPPED;
  72794. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  72795. EXPECT_DECLS;
  72796. byte *key = (byte*)"0123456789012345";
  72797. /* A 128 bit IV */
  72798. byte *iv = (byte*)"0123456789012345";
  72799. int ivSz = SM4_BLOCK_SIZE;
  72800. /* Message to be encrypted */
  72801. byte *plaintxt = (byte*)"for things to change you have to change";
  72802. /* Additional non-confidential data */
  72803. byte *aad = (byte*)"Don't spend major time on minor things.";
  72804. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  72805. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72806. int aadSz = (int)XSTRLEN((char*)aad);
  72807. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72808. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72809. int ciphertxtSz = 0;
  72810. int decryptedtxtSz = 0;
  72811. int len = 0;
  72812. int i = 0;
  72813. EVP_CIPHER_CTX en[2];
  72814. EVP_CIPHER_CTX de[2];
  72815. for (i = 0; i < 2; i++) {
  72816. EVP_CIPHER_CTX_init(&en[i]);
  72817. if (i == 0) {
  72818. /* Default uses 96-bits IV length */
  72819. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  72820. iv));
  72821. }
  72822. else {
  72823. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  72824. NULL));
  72825. /* non-default must to set the IV length first */
  72826. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  72827. ivSz, NULL));
  72828. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72829. }
  72830. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72831. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72832. plaintxtSz));
  72833. ciphertxtSz = len;
  72834. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72835. ciphertxtSz += len;
  72836. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  72837. SM4_BLOCK_SIZE, tag));
  72838. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72839. EVP_CIPHER_CTX_init(&de[i]);
  72840. if (i == 0) {
  72841. /* Default uses 96-bits IV length */
  72842. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  72843. iv));
  72844. }
  72845. else {
  72846. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  72847. NULL));
  72848. /* non-default must to set the IV length first */
  72849. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72850. ivSz, NULL));
  72851. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72852. }
  72853. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72854. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72855. ciphertxtSz));
  72856. decryptedtxtSz = len;
  72857. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72858. SM4_BLOCK_SIZE, tag));
  72859. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72860. decryptedtxtSz += len;
  72861. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72862. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72863. /* modify tag*/
  72864. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  72865. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72866. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72867. SM4_BLOCK_SIZE, tag));
  72868. /* fail due to wrong tag */
  72869. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72870. ciphertxtSz));
  72871. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72872. ExpectIntEQ(0, len);
  72873. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72874. }
  72875. res = EXPECT_RESULT();
  72876. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  72877. return res;
  72878. }
  72879. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  72880. {
  72881. int res = TEST_SKIPPED;
  72882. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  72883. /* Zero length plain text */
  72884. EXPECT_DECLS;
  72885. byte key[] = {
  72886. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72887. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72888. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72889. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72890. }; /* align */
  72891. byte iv[] = {
  72892. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72893. }; /* align */
  72894. byte plaintxt[1];
  72895. int ivSz = 12;
  72896. int plaintxtSz = 0;
  72897. unsigned char tag[16];
  72898. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72899. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72900. int ciphertxtSz = 0;
  72901. int decryptedtxtSz = 0;
  72902. int len = 0;
  72903. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72904. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72905. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  72906. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72907. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72908. plaintxtSz));
  72909. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72910. ciphertxtSz += len;
  72911. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72912. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72913. ExpectIntEQ(0, ciphertxtSz);
  72914. EVP_CIPHER_CTX_init(de);
  72915. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  72916. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72917. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72918. decryptedtxtSz = len;
  72919. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72920. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72921. decryptedtxtSz += len;
  72922. ExpectIntEQ(0, decryptedtxtSz);
  72923. EVP_CIPHER_CTX_free(en);
  72924. EVP_CIPHER_CTX_free(de);
  72925. res = EXPECT_RESULT();
  72926. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  72927. return res;
  72928. }
  72929. static int test_wolfssl_EVP_sm4_ccm(void)
  72930. {
  72931. int res = TEST_SKIPPED;
  72932. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  72933. EXPECT_DECLS;
  72934. byte *key = (byte*)"0123456789012345";
  72935. byte *iv = (byte*)"0123456789012";
  72936. int ivSz = (int)XSTRLEN((char*)iv);
  72937. /* Message to be encrypted */
  72938. byte *plaintxt = (byte*)"for things to change you have to change";
  72939. /* Additional non-confidential data */
  72940. byte *aad = (byte*)"Don't spend major time on minor things.";
  72941. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  72942. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72943. int aadSz = (int)XSTRLEN((char*)aad);
  72944. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  72945. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  72946. int ciphertxtSz = 0;
  72947. int decryptedtxtSz = 0;
  72948. int len = 0;
  72949. int i = 0;
  72950. EVP_CIPHER_CTX en[2];
  72951. EVP_CIPHER_CTX de[2];
  72952. for (i = 0; i < 2; i++) {
  72953. EVP_CIPHER_CTX_init(&en[i]);
  72954. if (i == 0) {
  72955. /* Default uses 96-bits IV length */
  72956. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  72957. iv));
  72958. }
  72959. else {
  72960. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  72961. NULL));
  72962. /* non-default must to set the IV length first */
  72963. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72964. ivSz, NULL));
  72965. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72966. }
  72967. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72968. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72969. plaintxtSz));
  72970. ciphertxtSz = len;
  72971. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72972. ciphertxtSz += len;
  72973. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72974. SM4_BLOCK_SIZE, tag));
  72975. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72976. EVP_CIPHER_CTX_init(&de[i]);
  72977. if (i == 0) {
  72978. /* Default uses 96-bits IV length */
  72979. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  72980. iv));
  72981. }
  72982. else {
  72983. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  72984. NULL));
  72985. /* non-default must to set the IV length first */
  72986. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72987. ivSz, NULL));
  72988. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72989. }
  72990. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72991. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72992. ciphertxtSz));
  72993. decryptedtxtSz = len;
  72994. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72995. SM4_BLOCK_SIZE, tag));
  72996. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72997. decryptedtxtSz += len;
  72998. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72999. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73000. /* modify tag*/
  73001. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73002. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73003. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73004. SM4_BLOCK_SIZE, tag));
  73005. /* fail due to wrong tag */
  73006. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73007. ciphertxtSz));
  73008. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73009. ExpectIntEQ(0, len);
  73010. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73011. }
  73012. res = EXPECT_RESULT();
  73013. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  73014. return res;
  73015. }
  73016. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  73017. {
  73018. EXPECT_DECLS;
  73019. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  73020. EVP_PKEY_CTX* ctx = NULL;
  73021. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  73022. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  73023. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  73024. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  73025. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  73026. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  73027. byte outKey[34];
  73028. size_t outKeySz = sizeof(outKey);
  73029. /* These expected outputs were gathered by running the same test below using
  73030. * OpenSSL. */
  73031. const byte extractAndExpand[] = {
  73032. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  73033. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  73034. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  73035. };
  73036. const byte extractOnly[] = {
  73037. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  73038. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  73039. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  73040. };
  73041. const byte expandOnly[] = {
  73042. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  73043. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  73044. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  73045. };
  73046. const byte extractAndExpandAddInfo[] = {
  73047. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  73048. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  73049. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  73050. };
  73051. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  73052. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  73053. /* NULL ctx. */
  73054. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73055. /* NULL md. */
  73056. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73057. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  73058. /* NULL ctx. */
  73059. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  73060. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73061. /* NULL salt is ok. */
  73062. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  73063. WOLFSSL_SUCCESS);
  73064. /* Salt length <= 0. */
  73065. /* Length 0 salt is ok. */
  73066. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  73067. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73068. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  73069. WOLFSSL_SUCCESS);
  73070. /* NULL ctx. */
  73071. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  73072. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73073. /* NULL key. */
  73074. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  73075. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73076. /* Key length <= 0 */
  73077. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73078. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73079. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  73080. WOLFSSL_SUCCESS);
  73081. /* NULL ctx. */
  73082. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  73083. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73084. /* NULL info is ok. */
  73085. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  73086. WOLFSSL_SUCCESS);
  73087. /* Info length <= 0 */
  73088. /* Length 0 info is ok. */
  73089. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  73090. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73091. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  73092. WOLFSSL_SUCCESS);
  73093. /* NULL ctx. */
  73094. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73095. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73096. /* Extract and expand (default). */
  73097. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73098. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  73099. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  73100. /* Extract only. */
  73101. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73102. WOLFSSL_SUCCESS);
  73103. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73104. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  73105. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  73106. outKeySz = sizeof(outKey);
  73107. /* Expand only. */
  73108. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  73109. WOLFSSL_SUCCESS);
  73110. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73111. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  73112. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  73113. outKeySz = sizeof(outKey);
  73114. /* Extract and expand with appended additional info. */
  73115. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  73116. WOLFSSL_SUCCESS);
  73117. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  73118. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  73119. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73120. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  73121. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  73122. EVP_PKEY_CTX_free(ctx);
  73123. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  73124. return EXPECT_RESULT();
  73125. }
  73126. #ifndef NO_BIO
  73127. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  73128. {
  73129. EXPECT_DECLS;
  73130. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73131. BIO* bio = NULL;
  73132. X509_INFO* info = NULL;
  73133. STACK_OF(X509_INFO)* sk = NULL;
  73134. char* subject = NULL;
  73135. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  73136. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73137. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  73138. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73139. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  73140. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  73141. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  73142. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  73143. /* using dereference to maintain testing for Apache port*/
  73144. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73145. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73146. 0, 0));
  73147. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  73148. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73149. X509_INFO_free(info);
  73150. info = NULL;
  73151. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73152. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73153. 0, 0));
  73154. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  73155. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73156. X509_INFO_free(info);
  73157. ExpectNull(info = sk_X509_INFO_pop(sk));
  73158. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  73159. BIO_free(bio);
  73160. #endif
  73161. return EXPECT_RESULT();
  73162. }
  73163. #endif /* !NO_BIO */
  73164. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  73165. {
  73166. EXPECT_DECLS;
  73167. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73168. X509 *x509 = NULL;
  73169. X509_NAME* name = NULL;
  73170. int idx = 0;
  73171. X509_NAME_ENTRY *ne = NULL;
  73172. ASN1_OBJECT *object = NULL;
  73173. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  73174. WOLFSSL_FILETYPE_PEM));
  73175. ExpectNotNull(name = X509_get_subject_name(x509));
  73176. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  73177. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  73178. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  73179. X509_free(x509);
  73180. #endif
  73181. return EXPECT_RESULT();
  73182. }
  73183. static int test_wolfSSL_X509_STORE_get1_certs(void)
  73184. {
  73185. EXPECT_DECLS;
  73186. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  73187. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73188. X509_STORE_CTX *storeCtx = NULL;
  73189. X509_STORE *store = NULL;
  73190. X509 *caX509 = NULL;
  73191. X509 *svrX509 = NULL;
  73192. X509_NAME *subject = NULL;
  73193. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  73194. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  73195. SSL_FILETYPE_PEM));
  73196. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  73197. SSL_FILETYPE_PEM)));
  73198. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  73199. ExpectNotNull(store = X509_STORE_new());
  73200. ExpectNotNull(subject = X509_get_subject_name(caX509));
  73201. /* Errors */
  73202. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  73203. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  73204. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  73205. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  73206. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  73207. SSL_SUCCESS);
  73208. /* Should find the cert */
  73209. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73210. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  73211. sk_X509_pop_free(certs, NULL);
  73212. certs = NULL;
  73213. /* Should not find the cert */
  73214. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  73215. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73216. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  73217. sk_X509_pop_free(certs, NULL);
  73218. certs = NULL;
  73219. X509_STORE_free(store);
  73220. X509_STORE_CTX_free(storeCtx);
  73221. X509_free(svrX509);
  73222. X509_free(caX509);
  73223. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  73224. return EXPECT_RESULT();
  73225. }
  73226. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73227. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73228. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73229. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  73230. X509_CRL** crl_out, X509* cert) {
  73231. X509_CRL *crl = NULL;
  73232. XFILE fp = XBADFILE;
  73233. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  73234. int ret = 0;
  73235. (void)ctx;
  73236. if (cert_issuer == NULL)
  73237. return 0;
  73238. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  73239. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  73240. XFCLOSE(fp);
  73241. if (crl != NULL) {
  73242. char* crl_issuer = X509_NAME_oneline(
  73243. X509_CRL_get_issuer(crl), NULL, 0);
  73244. if ((crl_issuer != NULL) &&
  73245. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  73246. *crl_out = X509_CRL_dup(crl);
  73247. if (*crl_out != NULL)
  73248. ret = 1;
  73249. }
  73250. OPENSSL_free(crl_issuer);
  73251. }
  73252. }
  73253. X509_CRL_free(crl);
  73254. OPENSSL_free(cert_issuer);
  73255. return ret;
  73256. }
  73257. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  73258. X509_CRL** crl_out, X509* cert) {
  73259. (void)ctx;
  73260. (void)cert;
  73261. *crl_out = NULL;
  73262. return 1;
  73263. }
  73264. #ifndef NO_WOLFSSL_STUB
  73265. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  73266. X509_CRL* crl) {
  73267. (void)ctx;
  73268. (void)crl;
  73269. return 1;
  73270. }
  73271. #endif
  73272. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  73273. X509_STORE_CTX* ctx) {
  73274. int cert_error = X509_STORE_CTX_get_error(ctx);
  73275. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  73276. int flags = X509_VERIFY_PARAM_get_flags(param);
  73277. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  73278. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  73279. /* Make sure the flags are set */
  73280. return 0;
  73281. }
  73282. /* Ignore CRL missing error */
  73283. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  73284. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  73285. #else
  73286. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  73287. #endif
  73288. return 1;
  73289. return ok;
  73290. }
  73291. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  73292. {
  73293. EXPECT_DECLS;
  73294. X509_STORE* cert_store = NULL;
  73295. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73296. WOLFSSL_SUCCESS);
  73297. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73298. X509_STORE_set_get_crl(cert_store,
  73299. test_wolfSSL_X509_STORE_set_get_crl_provider);
  73300. #ifndef NO_WOLFSSL_STUB
  73301. X509_STORE_set_check_crl(cert_store,
  73302. test_wolfSSL_X509_STORE_set_get_crl_check);
  73303. #endif
  73304. return EXPECT_RESULT();
  73305. }
  73306. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  73307. {
  73308. EXPECT_DECLS;
  73309. X509_STORE* cert_store = NULL;
  73310. X509_VERIFY_PARAM* param = NULL;
  73311. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  73312. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73313. WOLFSSL_SUCCESS);
  73314. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73315. X509_STORE_set_get_crl(cert_store,
  73316. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  73317. #ifndef NO_WOLFSSL_STUB
  73318. X509_STORE_set_check_crl(cert_store,
  73319. test_wolfSSL_X509_STORE_set_get_crl_check);
  73320. #endif
  73321. X509_STORE_set_verify_cb(cert_store,
  73322. test_wolfSSL_X509_STORE_set_get_crl_verify);
  73323. ExpectNotNull(X509_STORE_get0_param(cert_store));
  73324. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  73325. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  73326. X509_STORE_get0_param(cert_store)), 1);
  73327. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  73328. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73329. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  73330. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  73331. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73332. X509_VERIFY_PARAM_free(param);
  73333. return EXPECT_RESULT();
  73334. }
  73335. #endif
  73336. /* This test mimics the usage of the CRL provider in gRPC */
  73337. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  73338. {
  73339. EXPECT_DECLS;
  73340. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73341. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73342. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73343. test_ssl_cbf func_cb_client;
  73344. test_ssl_cbf func_cb_server;
  73345. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73346. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73347. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  73348. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73349. &func_cb_server, NULL), TEST_SUCCESS);
  73350. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73351. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73352. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  73353. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73354. &func_cb_server, NULL), TEST_SUCCESS);
  73355. #endif
  73356. return EXPECT_RESULT();
  73357. }
  73358. static int test_wolfSSL_dup_CA_list(void)
  73359. {
  73360. int res = TEST_SKIPPED;
  73361. #if defined(OPENSSL_ALL)
  73362. EXPECT_DECLS;
  73363. STACK_OF(X509_NAME) *originalStack = NULL;
  73364. STACK_OF(X509_NAME) *copyStack = NULL;
  73365. int originalCount = 0;
  73366. int copyCount = 0;
  73367. X509_NAME *name = NULL;
  73368. int i;
  73369. originalStack = sk_X509_NAME_new_null();
  73370. ExpectNotNull(originalStack);
  73371. for (i = 0; i < 3; i++) {
  73372. name = X509_NAME_new();
  73373. ExpectNotNull(name);
  73374. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  73375. if (EXPECT_FAIL()) {
  73376. X509_NAME_free(name);
  73377. }
  73378. }
  73379. copyStack = SSL_dup_CA_list(originalStack);
  73380. ExpectNotNull(copyStack);
  73381. originalCount = sk_X509_NAME_num(originalStack);
  73382. copyCount = sk_X509_NAME_num(copyStack);
  73383. ExpectIntEQ(originalCount, copyCount);
  73384. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  73385. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  73386. originalStack = NULL;
  73387. copyStack = NULL;
  73388. res = EXPECT_RESULT();
  73389. #endif /* OPENSSL_ALL */
  73390. return res;
  73391. }
  73392. static int test_ForceZero(void)
  73393. {
  73394. EXPECT_DECLS;
  73395. unsigned char data[32];
  73396. unsigned int i, j, len;
  73397. /* Test case with 0 length */
  73398. ForceZero(data, 0);
  73399. /* Test ForceZero */
  73400. for (i = 0; i < sizeof(data); i++) {
  73401. for (len = 1; len < sizeof(data) - i; len++) {
  73402. for (j = 0; j < sizeof(data); j++)
  73403. data[j] = j + 1;
  73404. ForceZero(data + i, len);
  73405. for (j = 0; j < sizeof(data); j++) {
  73406. if (j < i || j >= i + len) {
  73407. ExpectIntNE(data[j], 0x00);
  73408. }
  73409. else {
  73410. ExpectIntEQ(data[j], 0x00);
  73411. }
  73412. }
  73413. }
  73414. }
  73415. return EXPECT_RESULT();
  73416. }
  73417. #ifndef NO_BIO
  73418. static int test_wolfSSL_X509_print(void)
  73419. {
  73420. EXPECT_DECLS;
  73421. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73422. !defined(NO_RSA) && defined(XSNPRINTF)
  73423. X509 *x509 = NULL;
  73424. BIO *bio = NULL;
  73425. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73426. const X509_ALGOR *cert_sig_alg = NULL;
  73427. #endif
  73428. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  73429. WOLFSSL_FILETYPE_PEM));
  73430. /* print to memory */
  73431. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73432. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73433. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  73434. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  73435. /* Will print IP address subject alt name. */
  73436. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  73437. #elif defined(NO_ASN_TIME)
  73438. /* Will print IP address subject alt name but not Validity. */
  73439. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  73440. #else
  73441. /* Will print IP address subject alt name. */
  73442. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  73443. #endif
  73444. #elif defined(NO_ASN_TIME)
  73445. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  73446. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  73447. #else
  73448. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  73449. #endif
  73450. BIO_free(bio);
  73451. bio = NULL;
  73452. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73453. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73454. /* Print signature */
  73455. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  73456. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  73457. #endif
  73458. /* print to stderr */
  73459. #if !defined(NO_WOLFSSL_DIR)
  73460. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73461. #endif
  73462. /* print again */
  73463. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  73464. X509_free(x509);
  73465. BIO_free(bio);
  73466. #endif
  73467. return EXPECT_RESULT();
  73468. }
  73469. static int test_wolfSSL_X509_CRL_print(void)
  73470. {
  73471. EXPECT_DECLS;
  73472. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  73473. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  73474. X509_CRL* crl = NULL;
  73475. BIO *bio = NULL;
  73476. XFILE fp = XBADFILE;
  73477. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  73478. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  73479. NULL, NULL));
  73480. if (fp != XBADFILE)
  73481. XFCLOSE(fp);
  73482. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73483. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  73484. X509_CRL_free(crl);
  73485. BIO_free(bio);
  73486. #endif
  73487. return EXPECT_RESULT();
  73488. }
  73489. static int test_wolfSSL_BIO_get_len(void)
  73490. {
  73491. EXPECT_DECLS;
  73492. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  73493. BIO *bio = NULL;
  73494. const char txt[] = "Some example text to push to the BIO.";
  73495. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73496. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  73497. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  73498. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  73499. BIO_free(bio);
  73500. bio = NULL;
  73501. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73502. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  73503. BIO_free(bio);
  73504. #endif
  73505. return EXPECT_RESULT();
  73506. }
  73507. #endif /* !NO_BIO */
  73508. static int test_wolfSSL_RSA(void)
  73509. {
  73510. EXPECT_DECLS;
  73511. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  73512. RSA* rsa = NULL;
  73513. const BIGNUM *n = NULL;
  73514. const BIGNUM *e = NULL;
  73515. const BIGNUM *d = NULL;
  73516. const BIGNUM *p = NULL;
  73517. const BIGNUM *q = NULL;
  73518. const BIGNUM *dmp1 = NULL;
  73519. const BIGNUM *dmq1 = NULL;
  73520. const BIGNUM *iqmp = NULL;
  73521. ExpectNotNull(rsa = RSA_new());
  73522. ExpectIntEQ(RSA_size(NULL), 0);
  73523. ExpectIntEQ(RSA_size(rsa), 0);
  73524. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  73525. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  73526. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  73527. #ifdef WOLFSSL_RSA_KEY_CHECK
  73528. ExpectIntEQ(RSA_check_key(rsa), 0);
  73529. #endif
  73530. RSA_free(rsa);
  73531. rsa = NULL;
  73532. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73533. ExpectIntEQ(RSA_size(rsa), 256);
  73534. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  73535. {
  73536. /* Test setting only subset of parameters */
  73537. RSA *rsa2 = NULL;
  73538. unsigned char hash[SHA256_DIGEST_LENGTH];
  73539. unsigned char signature[2048/8];
  73540. unsigned int signatureLen = 0;
  73541. XMEMSET(hash, 0, sizeof(hash));
  73542. RSA_get0_key(rsa, &n, &e, &d);
  73543. RSA_get0_factors(rsa, &p, &q);
  73544. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73545. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73546. &signatureLen, rsa), 1);
  73547. /* Quick sanity check */
  73548. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73549. signatureLen, rsa), 1);
  73550. /* Verifying */
  73551. ExpectNotNull(rsa2 = RSA_new());
  73552. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  73553. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73554. signatureLen, rsa2), 1);
  73555. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73556. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73557. signatureLen, rsa2), 1);
  73558. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73559. BN_dup(iqmp)), 1);
  73560. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73561. signatureLen, rsa2), 1);
  73562. RSA_free(rsa2);
  73563. rsa2 = NULL;
  73564. /* Signing */
  73565. XMEMSET(signature, 0, sizeof(signature));
  73566. ExpectNotNull(rsa2 = RSA_new());
  73567. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  73568. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73569. &signatureLen, rsa2), 1);
  73570. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73571. signatureLen, rsa), 1);
  73572. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73573. XMEMSET(signature, 0, sizeof(signature));
  73574. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73575. &signatureLen, rsa2), 1);
  73576. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73577. signatureLen, rsa), 1);
  73578. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73579. BN_dup(iqmp)), 1);
  73580. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73581. &signatureLen, rsa2), 1);
  73582. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73583. signatureLen, rsa), 1);
  73584. RSA_free(rsa2);
  73585. rsa2 = NULL;
  73586. }
  73587. #endif
  73588. #ifdef WOLFSSL_RSA_KEY_CHECK
  73589. ExpectIntEQ(RSA_check_key(NULL), 0);
  73590. ExpectIntEQ(RSA_check_key(rsa), 1);
  73591. #endif
  73592. /* sanity check */
  73593. ExpectIntEQ(RSA_bits(NULL), 0);
  73594. /* key */
  73595. ExpectIntEQ(RSA_bits(rsa), 2048);
  73596. RSA_get0_key(rsa, &n, &e, &d);
  73597. ExpectPtrEq(rsa->n, n);
  73598. ExpectPtrEq(rsa->e, e);
  73599. ExpectPtrEq(rsa->d, d);
  73600. n = NULL;
  73601. e = NULL;
  73602. d = NULL;
  73603. ExpectNotNull(n = BN_new());
  73604. ExpectNotNull(e = BN_new());
  73605. ExpectNotNull(d = BN_new());
  73606. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  73607. if (EXPECT_FAIL()) {
  73608. BN_free((BIGNUM*)n);
  73609. BN_free((BIGNUM*)e);
  73610. BN_free((BIGNUM*)d);
  73611. }
  73612. ExpectPtrEq(rsa->n, n);
  73613. ExpectPtrEq(rsa->e, e);
  73614. ExpectPtrEq(rsa->d, d);
  73615. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  73616. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  73617. /* crt_params */
  73618. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73619. ExpectPtrEq(rsa->dmp1, dmp1);
  73620. ExpectPtrEq(rsa->dmq1, dmq1);
  73621. ExpectPtrEq(rsa->iqmp, iqmp);
  73622. dmp1 = NULL;
  73623. dmq1 = NULL;
  73624. iqmp = NULL;
  73625. ExpectNotNull(dmp1 = BN_new());
  73626. ExpectNotNull(dmq1 = BN_new());
  73627. ExpectNotNull(iqmp = BN_new());
  73628. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73629. (BIGNUM*)iqmp), 1);
  73630. if (EXPECT_FAIL()) {
  73631. BN_free((BIGNUM*)dmp1);
  73632. BN_free((BIGNUM*)dmq1);
  73633. BN_free((BIGNUM*)iqmp);
  73634. }
  73635. ExpectPtrEq(rsa->dmp1, dmp1);
  73636. ExpectPtrEq(rsa->dmq1, dmq1);
  73637. ExpectPtrEq(rsa->iqmp, iqmp);
  73638. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  73639. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73640. (BIGNUM*)iqmp), 0);
  73641. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  73642. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  73643. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  73644. ExpectNull(dmp1);
  73645. ExpectNull(dmq1);
  73646. ExpectNull(iqmp);
  73647. /* factors */
  73648. RSA_get0_factors(rsa, NULL, NULL);
  73649. RSA_get0_factors(rsa, &p, &q);
  73650. ExpectPtrEq(rsa->p, p);
  73651. ExpectPtrEq(rsa->q, q);
  73652. p = NULL;
  73653. q = NULL;
  73654. ExpectNotNull(p = BN_new());
  73655. ExpectNotNull(q = BN_new());
  73656. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  73657. if (EXPECT_FAIL()) {
  73658. BN_free((BIGNUM*)p);
  73659. BN_free((BIGNUM*)q);
  73660. }
  73661. ExpectPtrEq(rsa->p, p);
  73662. ExpectPtrEq(rsa->q, q);
  73663. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  73664. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  73665. RSA_get0_factors(NULL, NULL, NULL);
  73666. RSA_get0_factors(NULL, &p, &q);
  73667. ExpectNull(p);
  73668. ExpectNull(q);
  73669. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  73670. ExpectIntEQ(RSA_bits(rsa), 21);
  73671. RSA_free(rsa);
  73672. rsa = NULL;
  73673. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  73674. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  73675. ExpectIntEQ(RSA_size(rsa), 384);
  73676. ExpectIntEQ(RSA_bits(rsa), 3072);
  73677. RSA_free(rsa);
  73678. rsa = NULL;
  73679. #endif
  73680. /* remove for now with odd key size until adjusting rsa key size check with
  73681. wc_MakeRsaKey()
  73682. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  73683. RSA_free(rsa);
  73684. rsa = NULL;
  73685. */
  73686. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  73687. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  73688. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  73689. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  73690. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  73691. {
  73692. byte buff[FOURK_BUF];
  73693. byte der[FOURK_BUF];
  73694. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  73695. XFILE f = XBADFILE;
  73696. int bytes = 0;
  73697. /* test loading encrypted RSA private pem w/o password */
  73698. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  73699. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  73700. if (f != XBADFILE)
  73701. XFCLOSE(f);
  73702. XMEMSET(der, 0, sizeof(der));
  73703. /* test that error value is returned with no password */
  73704. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  73705. 0);
  73706. }
  73707. #endif
  73708. #endif
  73709. return EXPECT_RESULT();
  73710. }
  73711. static int test_wolfSSL_RSA_DER(void)
  73712. {
  73713. EXPECT_DECLS;
  73714. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  73715. RSA *rsa = NULL;
  73716. int i;
  73717. const unsigned char *buff = NULL;
  73718. unsigned char *newBuff = NULL;
  73719. struct tbl_s
  73720. {
  73721. const unsigned char *der;
  73722. int sz;
  73723. } tbl[] = {
  73724. #ifdef USE_CERT_BUFFERS_1024
  73725. {client_key_der_1024, sizeof_client_key_der_1024},
  73726. {server_key_der_1024, sizeof_server_key_der_1024},
  73727. #endif
  73728. #ifdef USE_CERT_BUFFERS_2048
  73729. {client_key_der_2048, sizeof_client_key_der_2048},
  73730. {server_key_der_2048, sizeof_server_key_der_2048},
  73731. #endif
  73732. {NULL, 0}
  73733. };
  73734. /* Public Key DER */
  73735. struct tbl_s pub[] = {
  73736. #ifdef USE_CERT_BUFFERS_1024
  73737. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  73738. #endif
  73739. #ifdef USE_CERT_BUFFERS_2048
  73740. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  73741. #endif
  73742. {NULL, 0}
  73743. };
  73744. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  73745. buff = pub[0].der;
  73746. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  73747. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  73748. buff = tbl[0].der;
  73749. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  73750. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73751. rsa = RSA_new();
  73752. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  73753. RSA_free(rsa);
  73754. rsa = NULL;
  73755. for (i = 0; tbl[i].der != NULL; i++)
  73756. {
  73757. /* Passing in pointer results in pointer moving. */
  73758. buff = tbl[i].der;
  73759. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  73760. ExpectNotNull(rsa);
  73761. RSA_free(rsa);
  73762. rsa = NULL;
  73763. }
  73764. for (i = 0; tbl[i].der != NULL; i++)
  73765. {
  73766. /* Passing in pointer results in pointer moving. */
  73767. buff = tbl[i].der;
  73768. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  73769. ExpectNotNull(rsa);
  73770. RSA_free(rsa);
  73771. rsa = NULL;
  73772. }
  73773. for (i = 0; pub[i].der != NULL; i++)
  73774. {
  73775. buff = pub[i].der;
  73776. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  73777. ExpectNotNull(rsa);
  73778. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  73779. newBuff = NULL;
  73780. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  73781. ExpectNotNull(newBuff);
  73782. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  73783. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73784. RSA_free(rsa);
  73785. rsa = NULL;
  73786. }
  73787. #endif
  73788. return EXPECT_RESULT();
  73789. }
  73790. static int test_wolfSSL_RSA_print(void)
  73791. {
  73792. EXPECT_DECLS;
  73793. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73794. !defined(NO_STDIO_FILESYSTEM) && \
  73795. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  73796. !defined(NO_BIO) && defined(XFPRINTF)
  73797. BIO *bio = NULL;
  73798. WOLFSSL_RSA* rsa = NULL;
  73799. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73800. ExpectNotNull(rsa = RSA_new());
  73801. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  73802. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  73803. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  73804. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  73805. /* Some very large number of indent spaces. */
  73806. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  73807. /* RSA is empty. */
  73808. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  73809. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  73810. RSA_free(rsa);
  73811. rsa = NULL;
  73812. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73813. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  73814. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  73815. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  73816. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  73817. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  73818. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  73819. BIO_free(bio);
  73820. RSA_free(rsa);
  73821. #endif
  73822. return EXPECT_RESULT();
  73823. }
  73824. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  73825. {
  73826. EXPECT_DECLS;
  73827. #ifndef NO_RSA
  73828. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  73829. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  73830. RSA *rsa = NULL;
  73831. const unsigned char *derBuf = client_key_der_2048;
  73832. unsigned char em[256] = {0}; /* len = 2048/8 */
  73833. /* Random data simulating a hash */
  73834. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  73835. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  73836. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  73837. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  73838. };
  73839. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  73840. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  73841. RSA_PSS_SALTLEN_DIGEST), 0);
  73842. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  73843. RSA_PSS_SALTLEN_DIGEST), 0);
  73844. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  73845. RSA_PSS_SALTLEN_DIGEST), 0);
  73846. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  73847. RSA_PSS_SALTLEN_DIGEST), 0);
  73848. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  73849. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  73850. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73851. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  73852. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73853. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  73854. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73855. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  73856. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73857. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73858. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  73859. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  73860. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73861. RSA_PSS_SALTLEN_DIGEST), 1);
  73862. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73863. RSA_PSS_SALTLEN_DIGEST), 1);
  73864. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73865. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  73866. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73867. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  73868. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  73869. RSA_PSS_SALTLEN_MAX), 1);
  73870. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  73871. RSA_PSS_SALTLEN_MAX), 1);
  73872. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  73873. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  73874. RSA_free(rsa);
  73875. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  73876. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  73877. #endif
  73878. return EXPECT_RESULT();
  73879. }
  73880. static int test_wolfSSL_RSA_sign_sha3(void)
  73881. {
  73882. EXPECT_DECLS;
  73883. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  73884. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  73885. RSA* rsa = NULL;
  73886. const unsigned char *derBuf = client_key_der_2048;
  73887. unsigned char sigRet[256] = {0};
  73888. unsigned int sigLen = sizeof(sigRet);
  73889. /* Random data simulating a hash */
  73890. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  73891. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  73892. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  73893. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  73894. };
  73895. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  73896. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  73897. rsa), 1);
  73898. RSA_free(rsa);
  73899. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  73900. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  73901. return EXPECT_RESULT();
  73902. }
  73903. static int test_wolfSSL_RSA_get0_key(void)
  73904. {
  73905. EXPECT_DECLS;
  73906. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73907. RSA *rsa = NULL;
  73908. const BIGNUM* n = NULL;
  73909. const BIGNUM* e = NULL;
  73910. const BIGNUM* d = NULL;
  73911. const unsigned char* der;
  73912. int derSz;
  73913. #ifdef USE_CERT_BUFFERS_1024
  73914. der = client_key_der_1024;
  73915. derSz = sizeof_client_key_der_1024;
  73916. #elif defined(USE_CERT_BUFFERS_2048)
  73917. der = client_key_der_2048;
  73918. derSz = sizeof_client_key_der_2048;
  73919. #else
  73920. der = NULL;
  73921. derSz = 0;
  73922. #endif
  73923. if (der != NULL) {
  73924. RSA_get0_key(NULL, NULL, NULL, NULL);
  73925. RSA_get0_key(rsa, NULL, NULL, NULL);
  73926. RSA_get0_key(NULL, &n, &e, &d);
  73927. ExpectNull(n);
  73928. ExpectNull(e);
  73929. ExpectNull(d);
  73930. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  73931. ExpectNotNull(rsa);
  73932. RSA_get0_key(rsa, NULL, NULL, NULL);
  73933. RSA_get0_key(rsa, &n, NULL, NULL);
  73934. ExpectNotNull(n);
  73935. RSA_get0_key(rsa, NULL, &e, NULL);
  73936. ExpectNotNull(e);
  73937. RSA_get0_key(rsa, NULL, NULL, &d);
  73938. ExpectNotNull(d);
  73939. RSA_get0_key(rsa, &n, &e, &d);
  73940. ExpectNotNull(n);
  73941. ExpectNotNull(e);
  73942. ExpectNotNull(d);
  73943. RSA_free(rsa);
  73944. }
  73945. #endif
  73946. return EXPECT_RESULT();
  73947. }
  73948. static int test_wolfSSL_RSA_meth(void)
  73949. {
  73950. EXPECT_DECLS;
  73951. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  73952. RSA *rsa = NULL;
  73953. RSA_METHOD *rsa_meth = NULL;
  73954. #ifdef WOLFSSL_KEY_GEN
  73955. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73956. RSA_free(rsa);
  73957. rsa = NULL;
  73958. #else
  73959. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73960. #endif
  73961. ExpectNotNull(RSA_get_default_method());
  73962. wolfSSL_RSA_meth_free(NULL);
  73963. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  73964. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  73965. RSA_METHOD_FLAG_NO_CHECK));
  73966. #ifndef NO_WOLFSSL_STUB
  73967. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  73968. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  73969. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  73970. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  73971. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  73972. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  73973. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  73974. #endif
  73975. ExpectIntEQ(RSA_flags(NULL), 0);
  73976. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  73977. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  73978. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  73979. ExpectNotNull(rsa = RSA_new());
  73980. /* No method set. */
  73981. ExpectIntEQ(RSA_flags(rsa), 0);
  73982. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73983. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73984. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73985. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  73986. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  73987. if (EXPECT_FAIL()) {
  73988. wolfSSL_RSA_meth_free(rsa_meth);
  73989. }
  73990. ExpectNull(RSA_get_method(NULL));
  73991. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  73992. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  73993. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73994. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73995. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  73996. RSA_METHOD_FLAG_NO_CHECK);
  73997. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  73998. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  73999. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  74000. /* rsa_meth is freed here */
  74001. RSA_free(rsa);
  74002. #endif
  74003. return EXPECT_RESULT();
  74004. }
  74005. static int test_wolfSSL_RSA_verify(void)
  74006. {
  74007. EXPECT_DECLS;
  74008. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  74009. #ifndef NO_BIO
  74010. XFILE fp = XBADFILE;
  74011. RSA *pKey = NULL;
  74012. RSA *pubKey = NULL;
  74013. X509 *cert = NULL;
  74014. const char *text = "Hello wolfSSL !";
  74015. unsigned char hash[SHA256_DIGEST_LENGTH];
  74016. unsigned char signature[2048/8];
  74017. unsigned int signatureLength;
  74018. byte *buf = NULL;
  74019. BIO *bio = NULL;
  74020. SHA256_CTX c;
  74021. EVP_PKEY *evpPkey = NULL;
  74022. EVP_PKEY *evpPubkey = NULL;
  74023. size_t sz;
  74024. /* generate hash */
  74025. SHA256_Init(&c);
  74026. SHA256_Update(&c, text, strlen(text));
  74027. SHA256_Final(hash, &c);
  74028. #ifdef WOLFSSL_SMALL_STACK_CACHE
  74029. /* workaround for small stack cache case */
  74030. wc_Sha256Free((wc_Sha256*)&c);
  74031. #endif
  74032. /* read privete key file */
  74033. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  74034. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  74035. ExpectTrue((sz = XFTELL(fp)) > 0);
  74036. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  74037. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  74038. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  74039. if (fp != XBADFILE) {
  74040. XFCLOSE(fp);
  74041. fp = XBADFILE;
  74042. }
  74043. /* read private key and sign hash data */
  74044. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  74045. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  74046. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  74047. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  74048. signature, &signatureLength, pKey), SSL_SUCCESS);
  74049. /* read public key and verify signed data */
  74050. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  74051. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  74052. if (fp != XBADFILE)
  74053. XFCLOSE(fp);
  74054. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  74055. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  74056. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74057. signatureLength, pubKey), SSL_SUCCESS);
  74058. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  74059. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74060. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  74061. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74062. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  74063. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74064. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74065. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74066. RSA_free(pKey);
  74067. EVP_PKEY_free(evpPkey);
  74068. RSA_free(pubKey);
  74069. EVP_PKEY_free(evpPubkey);
  74070. X509_free(cert);
  74071. BIO_free(bio);
  74072. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  74073. #endif
  74074. #endif
  74075. return EXPECT_RESULT();
  74076. }
  74077. static int test_wolfSSL_RSA_sign(void)
  74078. {
  74079. EXPECT_DECLS;
  74080. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74081. RSA *rsa;
  74082. unsigned char hash[SHA256_DIGEST_LENGTH];
  74083. #ifdef USE_CERT_BUFFERS_1024
  74084. const unsigned char* privDer = client_key_der_1024;
  74085. size_t privDerSz = sizeof_client_key_der_1024;
  74086. const unsigned char* pubDer = client_keypub_der_1024;
  74087. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74088. unsigned char signature[1024/8];
  74089. #else
  74090. const unsigned char* privDer = client_key_der_2048;
  74091. size_t privDerSz = sizeof_client_key_der_2048;
  74092. const unsigned char* pubDer = client_keypub_der_2048;
  74093. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74094. unsigned char signature[2048/8];
  74095. #endif
  74096. unsigned int signatureLen;
  74097. const unsigned char* der;
  74098. XMEMSET(hash, 0, sizeof(hash));
  74099. der = privDer;
  74100. rsa = NULL;
  74101. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74102. /* Invalid parameters. */
  74103. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  74104. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  74105. &signatureLen, rsa), 0);
  74106. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  74107. &signatureLen, rsa), 0);
  74108. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  74109. &signatureLen, rsa), 0);
  74110. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74111. NULL, rsa), 0);
  74112. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74113. &signatureLen, NULL), 0);
  74114. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74115. &signatureLen, rsa), 1);
  74116. RSA_free(rsa);
  74117. der = pubDer;
  74118. rsa = NULL;
  74119. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74120. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74121. signatureLen, rsa), 1);
  74122. RSA_free(rsa);
  74123. #endif
  74124. return EXPECT_RESULT();
  74125. }
  74126. static int test_wolfSSL_RSA_sign_ex(void)
  74127. {
  74128. EXPECT_DECLS;
  74129. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74130. RSA *rsa = NULL;
  74131. unsigned char hash[SHA256_DIGEST_LENGTH];
  74132. #ifdef USE_CERT_BUFFERS_1024
  74133. const unsigned char* privDer = client_key_der_1024;
  74134. size_t privDerSz = sizeof_client_key_der_1024;
  74135. const unsigned char* pubDer = client_keypub_der_1024;
  74136. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74137. unsigned char signature[1024/8];
  74138. #else
  74139. const unsigned char* privDer = client_key_der_2048;
  74140. size_t privDerSz = sizeof_client_key_der_2048;
  74141. const unsigned char* pubDer = client_keypub_der_2048;
  74142. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74143. unsigned char signature[2048/8];
  74144. #endif
  74145. unsigned int signatureLen;
  74146. const unsigned char* der;
  74147. unsigned char encodedHash[51];
  74148. unsigned int encodedHashLen;
  74149. const unsigned char expEncHash[] = {
  74150. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  74151. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  74152. 0x00, 0x04, 0x20,
  74153. /* Hash data */
  74154. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74155. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74158. };
  74159. XMEMSET(hash, 0, sizeof(hash));
  74160. ExpectNotNull(rsa = wolfSSL_RSA_new());
  74161. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74162. &signatureLen, rsa, 1), 0);
  74163. wolfSSL_RSA_free(rsa);
  74164. der = privDer;
  74165. rsa = NULL;
  74166. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74167. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  74168. -1), 0);
  74169. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  74170. signature, &signatureLen, rsa, 1), 0);
  74171. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74172. &signatureLen, rsa, 1), 0);
  74173. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74174. &signatureLen, rsa, 1), 0);
  74175. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74176. NULL, rsa, 1), 0);
  74177. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74178. &signatureLen, NULL, 1), 0);
  74179. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74180. &signatureLen, rsa, -1), 0);
  74181. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74182. &signatureLen, rsa, 0), 0);
  74183. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74184. &signatureLen, rsa, 0), 0);
  74185. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74186. NULL, rsa, 0), 0);
  74187. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74188. &signatureLen, rsa, 1), 1);
  74189. /* Test returning encoded hash. */
  74190. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  74191. &encodedHashLen, rsa, 0), 1);
  74192. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  74193. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  74194. RSA_free(rsa);
  74195. der = pubDer;
  74196. rsa = NULL;
  74197. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74198. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74199. signatureLen, rsa), 1);
  74200. RSA_free(rsa);
  74201. #endif
  74202. return EXPECT_RESULT();
  74203. }
  74204. static int test_wolfSSL_RSA_public_decrypt(void)
  74205. {
  74206. EXPECT_DECLS;
  74207. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74208. RSA *rsa;
  74209. unsigned char msg[SHA256_DIGEST_LENGTH];
  74210. #ifdef USE_CERT_BUFFERS_1024
  74211. const unsigned char* pubDer = client_keypub_der_1024;
  74212. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74213. unsigned char decMsg[1024/8];
  74214. const unsigned char encMsg[] = {
  74215. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74216. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74217. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74218. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74219. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74220. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74221. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74222. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74223. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74224. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74225. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74226. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74227. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74228. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74229. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74230. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74231. };
  74232. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74233. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74234. defined(WC_RSA_NO_PADDING)
  74235. const unsigned char encMsgNoPad[] = {
  74236. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74237. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74238. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74239. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74240. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74241. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74242. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74243. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74244. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74245. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74246. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74247. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74248. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74249. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74250. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74251. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74252. };
  74253. #endif
  74254. #else
  74255. const unsigned char* pubDer = client_keypub_der_2048;
  74256. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74257. unsigned char decMsg[2048/8];
  74258. const unsigned char encMsg[] = {
  74259. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74260. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74261. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74262. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74263. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74264. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74265. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74266. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74267. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74268. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74269. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74270. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74271. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74272. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74273. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74274. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74275. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74276. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74277. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74278. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74279. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74280. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74281. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74282. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74283. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74284. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74285. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74286. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74287. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74288. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74289. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74290. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74291. };
  74292. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74293. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74294. defined(WC_RSA_NO_PADDING)
  74295. const unsigned char encMsgNoPad[] = {
  74296. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74297. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74298. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74299. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74300. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74301. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74302. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74303. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74304. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74305. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74306. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74307. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74308. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74309. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74310. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74311. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74312. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74313. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74314. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74315. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74316. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74317. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74318. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74319. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74320. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74321. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74322. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74323. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74324. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74325. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74326. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74327. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74328. };
  74329. #endif
  74330. #endif
  74331. const unsigned char* der;
  74332. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74333. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74334. defined(WC_RSA_NO_PADDING)
  74335. int i;
  74336. #endif
  74337. XMEMSET(msg, 0, sizeof(msg));
  74338. der = pubDer;
  74339. rsa = NULL;
  74340. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74341. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  74342. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  74343. RSA_PKCS1_PADDING), -1);
  74344. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  74345. RSA_PKCS1_PADDING), -1);
  74346. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74347. RSA_PKCS1_PADDING), -1);
  74348. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  74349. RSA_PKCS1_PADDING), -1);
  74350. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74351. RSA_PKCS1_PSS_PADDING), -1);
  74352. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74353. RSA_PKCS1_PADDING), 32);
  74354. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  74355. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74356. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74357. defined(WC_RSA_NO_PADDING)
  74358. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  74359. rsa, RSA_NO_PADDING), sizeof(decMsg));
  74360. /* Zeros before actual data. */
  74361. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  74362. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74363. }
  74364. /* Check actual data. */
  74365. XMEMSET(msg, 0x01, sizeof(msg));
  74366. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74367. #endif
  74368. RSA_free(rsa);
  74369. #endif
  74370. return EXPECT_RESULT();
  74371. }
  74372. static int test_wolfSSL_RSA_private_encrypt(void)
  74373. {
  74374. EXPECT_DECLS;
  74375. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74376. RSA *rsa;
  74377. unsigned char msg[SHA256_DIGEST_LENGTH];
  74378. #ifdef USE_CERT_BUFFERS_1024
  74379. const unsigned char* privDer = client_key_der_1024;
  74380. size_t privDerSz = sizeof_client_key_der_1024;
  74381. unsigned char encMsg[1024/8];
  74382. const unsigned char expEncMsg[] = {
  74383. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74384. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74385. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74386. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74387. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74388. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74389. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74390. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74391. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74392. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74393. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74394. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74395. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74396. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74397. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74398. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74399. };
  74400. #ifdef WC_RSA_NO_PADDING
  74401. const unsigned char expEncMsgNoPad[] = {
  74402. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74403. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74404. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74405. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74406. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74407. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74408. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74409. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74410. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74411. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74412. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74413. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74414. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74415. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74416. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74417. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74418. };
  74419. #endif
  74420. #else
  74421. const unsigned char* privDer = client_key_der_2048;
  74422. size_t privDerSz = sizeof_client_key_der_2048;
  74423. unsigned char encMsg[2048/8];
  74424. const unsigned char expEncMsg[] = {
  74425. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74426. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74427. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74428. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74429. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74430. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74431. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74432. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74433. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74434. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74435. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74436. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74437. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74438. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74439. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74440. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74441. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74442. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74443. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74444. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74445. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74446. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74447. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74448. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74449. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74450. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74451. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74452. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74453. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74454. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74455. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74456. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74457. };
  74458. #ifdef WC_RSA_NO_PADDING
  74459. const unsigned char expEncMsgNoPad[] = {
  74460. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74461. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74462. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74463. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74464. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74465. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74466. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74467. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74468. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74469. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74470. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74471. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74472. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74473. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74474. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74475. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74476. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74477. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74478. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74479. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74480. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74481. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74482. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74483. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74484. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74485. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74486. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74487. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74488. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74489. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74490. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74491. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74492. };
  74493. #endif
  74494. #endif
  74495. const unsigned char* der;
  74496. XMEMSET(msg, 0x00, sizeof(msg));
  74497. der = privDer;
  74498. rsa = NULL;
  74499. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74500. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  74501. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  74502. -1);
  74503. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74504. RSA_PKCS1_PADDING), -1);
  74505. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  74506. RSA_PKCS1_PADDING), -1);
  74507. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  74508. RSA_PKCS1_PADDING), -1);
  74509. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74510. RSA_PKCS1_PSS_PADDING), -1);
  74511. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74512. RSA_PKCS1_PADDING), sizeof(encMsg));
  74513. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  74514. #ifdef WC_RSA_NO_PADDING
  74515. /* Non-zero message. */
  74516. XMEMSET(msg, 0x01, sizeof(msg));
  74517. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74518. RSA_NO_PADDING), sizeof(encMsg));
  74519. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  74520. #endif
  74521. RSA_free(rsa);
  74522. #endif
  74523. return EXPECT_RESULT();
  74524. }
  74525. static int test_wolfSSL_RSA_public_encrypt(void)
  74526. {
  74527. EXPECT_DECLS;
  74528. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74529. RSA* rsa = NULL;
  74530. const unsigned char msg[2048/8] = { 0 };
  74531. unsigned char encMsg[2048/8];
  74532. ExpectNotNull(rsa = RSA_new());
  74533. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  74534. RSA_PKCS1_PADDING), -1);
  74535. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74536. RSA_PKCS1_PADDING), -1);
  74537. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  74538. RSA_PKCS1_PADDING), -1);
  74539. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  74540. RSA_PKCS1_PADDING), -1);
  74541. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74542. RSA_PKCS1_PSS_PADDING), -1);
  74543. /* Empty RSA key. */
  74544. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74545. RSA_PKCS1_PADDING), -1);
  74546. RSA_free(rsa);
  74547. #endif
  74548. return EXPECT_RESULT();
  74549. }
  74550. static int test_wolfSSL_RSA_private_decrypt(void)
  74551. {
  74552. EXPECT_DECLS;
  74553. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74554. RSA* rsa = NULL;
  74555. unsigned char msg[2048/8];
  74556. const unsigned char encMsg[2048/8] = { 0 };
  74557. ExpectNotNull(rsa = RSA_new());
  74558. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  74559. RSA_PKCS1_PADDING), -1);
  74560. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  74561. RSA_PKCS1_PADDING), -1);
  74562. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74563. RSA_PKCS1_PADDING), -1);
  74564. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  74565. RSA_PKCS1_PADDING), -1);
  74566. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74567. RSA_PKCS1_PSS_PADDING), -1);
  74568. /* Empty RSA key. */
  74569. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74570. RSA_PKCS1_PADDING), -1);
  74571. RSA_free(rsa);
  74572. #endif
  74573. return EXPECT_RESULT();
  74574. }
  74575. static int test_wolfSSL_RSA_GenAdd(void)
  74576. {
  74577. EXPECT_DECLS;
  74578. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74579. RSA *rsa;
  74580. #ifdef USE_CERT_BUFFERS_1024
  74581. const unsigned char* privDer = client_key_der_1024;
  74582. size_t privDerSz = sizeof_client_key_der_1024;
  74583. const unsigned char* pubDer = client_keypub_der_1024;
  74584. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74585. #else
  74586. const unsigned char* privDer = client_key_der_2048;
  74587. size_t privDerSz = sizeof_client_key_der_2048;
  74588. const unsigned char* pubDer = client_keypub_der_2048;
  74589. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74590. #endif
  74591. const unsigned char* der;
  74592. der = privDer;
  74593. rsa = NULL;
  74594. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74595. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  74596. #ifndef RSA_LOW_MEM
  74597. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  74598. #else
  74599. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  74600. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74601. #endif
  74602. RSA_free(rsa);
  74603. der = pubDer;
  74604. rsa = NULL;
  74605. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74606. /* Need private values. */
  74607. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74608. RSA_free(rsa);
  74609. #endif
  74610. return EXPECT_RESULT();
  74611. }
  74612. static int test_wolfSSL_RSA_blinding_on(void)
  74613. {
  74614. EXPECT_DECLS;
  74615. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  74616. RSA *rsa;
  74617. WOLFSSL_BN_CTX *bnCtx = NULL;
  74618. #ifdef USE_CERT_BUFFERS_1024
  74619. const unsigned char* privDer = client_key_der_1024;
  74620. size_t privDerSz = sizeof_client_key_der_1024;
  74621. #else
  74622. const unsigned char* privDer = client_key_der_2048;
  74623. size_t privDerSz = sizeof_client_key_der_2048;
  74624. #endif
  74625. const unsigned char* der;
  74626. der = privDer;
  74627. rsa = NULL;
  74628. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74629. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  74630. /* Does nothing so all parameters are valid. */
  74631. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  74632. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  74633. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  74634. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  74635. wolfSSL_BN_CTX_free(bnCtx);
  74636. RSA_free(rsa);
  74637. #endif
  74638. return EXPECT_RESULT();
  74639. }
  74640. static int test_wolfSSL_RSA_ex_data(void)
  74641. {
  74642. EXPECT_DECLS;
  74643. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74644. RSA* rsa = NULL;
  74645. unsigned char data[1];
  74646. ExpectNotNull(rsa = RSA_new());
  74647. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  74648. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74649. #ifdef MAX_EX_DATA
  74650. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  74651. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  74652. #endif
  74653. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  74654. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  74655. #ifdef HAVE_EX_DATA
  74656. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  74657. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  74658. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  74659. #else
  74660. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  74661. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  74662. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74663. #endif
  74664. RSA_free(rsa);
  74665. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74666. return EXPECT_RESULT();
  74667. }
  74668. static int test_wolfSSL_RSA_LoadDer(void)
  74669. {
  74670. EXPECT_DECLS;
  74671. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  74672. defined(OPENSSL_EXTRA_X509_SMALL))
  74673. RSA *rsa = NULL;
  74674. #ifdef USE_CERT_BUFFERS_1024
  74675. const unsigned char* privDer = client_key_der_1024;
  74676. size_t privDerSz = sizeof_client_key_der_1024;
  74677. #else
  74678. const unsigned char* privDer = client_key_der_2048;
  74679. size_t privDerSz = sizeof_client_key_der_2048;
  74680. #endif
  74681. ExpectNotNull(rsa = RSA_new());
  74682. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  74683. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  74684. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  74685. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  74686. RSA_free(rsa);
  74687. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74688. return EXPECT_RESULT();
  74689. }
  74690. /* Local API. */
  74691. static int test_wolfSSL_RSA_To_Der(void)
  74692. {
  74693. EXPECT_DECLS;
  74694. #ifdef WOLFSSL_TEST_STATIC_BUILD
  74695. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74696. RSA* rsa;
  74697. #ifdef USE_CERT_BUFFERS_1024
  74698. const unsigned char* privDer = client_key_der_1024;
  74699. size_t privDerSz = sizeof_client_key_der_1024;
  74700. const unsigned char* pubDer = client_keypub_der_1024;
  74701. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74702. unsigned char out[sizeof(client_key_der_1024)];
  74703. #else
  74704. const unsigned char* privDer = client_key_der_2048;
  74705. size_t privDerSz = sizeof_client_key_der_2048;
  74706. const unsigned char* pubDer = client_keypub_der_2048;
  74707. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74708. unsigned char out[sizeof(client_key_der_2048)];
  74709. #endif
  74710. const unsigned char* der;
  74711. unsigned char* outDer = NULL;
  74712. der = privDer;
  74713. rsa = NULL;
  74714. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74715. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74716. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74717. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  74718. outDer = out;
  74719. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74720. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  74721. outDer = NULL;
  74722. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74723. ExpectNotNull(outDer);
  74724. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  74725. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  74726. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  74727. outDer = out;
  74728. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  74729. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  74730. RSA_free(rsa);
  74731. ExpectNotNull(rsa = RSA_new());
  74732. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74733. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74734. RSA_free(rsa);
  74735. der = pubDer;
  74736. rsa = NULL;
  74737. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74738. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74739. RSA_free(rsa);
  74740. #endif
  74741. #endif
  74742. return EXPECT_RESULT();
  74743. }
  74744. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  74745. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  74746. {
  74747. EXPECT_DECLS;
  74748. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  74749. XFILE file = XBADFILE;
  74750. const char* fname = "./certs/server-keyPub.pem";
  74751. RSA *rsa = NULL;
  74752. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  74753. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  74754. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  74755. ExpectIntEQ(RSA_size(rsa), 256);
  74756. RSA_free(rsa);
  74757. if (file != XBADFILE)
  74758. XFCLOSE(file);
  74759. #endif
  74760. return EXPECT_RESULT();
  74761. }
  74762. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  74763. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  74764. {
  74765. EXPECT_DECLS;
  74766. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74767. defined(WOLFSSL_KEY_GEN)
  74768. RSA* rsa = NULL;
  74769. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  74770. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  74771. /* Valid but stub so returns 0. */
  74772. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  74773. #endif
  74774. return EXPECT_RESULT();
  74775. }
  74776. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  74777. {
  74778. EXPECT_DECLS;
  74779. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  74780. (defined(WOLFSSL_PEM_TO_DER) || \
  74781. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  74782. RSA* rsa = NULL;
  74783. #ifdef USE_CERT_BUFFERS_1024
  74784. const unsigned char* privDer = client_key_der_1024;
  74785. size_t privDerSz = sizeof_client_key_der_1024;
  74786. #else
  74787. const unsigned char* privDer = client_key_der_2048;
  74788. size_t privDerSz = sizeof_client_key_der_2048;
  74789. #endif
  74790. const unsigned char* der;
  74791. #ifndef NO_AES
  74792. unsigned char passwd[] = "password";
  74793. #endif
  74794. ExpectNotNull(rsa = RSA_new());
  74795. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  74796. NULL, NULL), 0);
  74797. RSA_free(rsa);
  74798. der = privDer;
  74799. rsa = NULL;
  74800. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74801. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  74802. NULL, NULL), 0);
  74803. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  74804. NULL, NULL), 0);
  74805. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  74806. NULL, NULL), 1);
  74807. #ifndef NO_AES
  74808. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  74809. NULL, 0, NULL, NULL), 1);
  74810. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  74811. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  74812. #endif
  74813. RSA_free(rsa);
  74814. #endif
  74815. return EXPECT_RESULT();
  74816. }
  74817. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  74818. {
  74819. EXPECT_DECLS;
  74820. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  74821. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  74822. RSA* rsa = NULL;
  74823. #ifdef USE_CERT_BUFFERS_1024
  74824. const unsigned char* privDer = client_key_der_1024;
  74825. size_t privDerSz = sizeof_client_key_der_1024;
  74826. #else
  74827. const unsigned char* privDer = client_key_der_2048;
  74828. size_t privDerSz = sizeof_client_key_der_2048;
  74829. #endif
  74830. const unsigned char* der;
  74831. #ifndef NO_AES
  74832. unsigned char passwd[] = "password";
  74833. #endif
  74834. unsigned char* pem = NULL;
  74835. int plen;
  74836. ExpectNotNull(rsa = RSA_new());
  74837. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74838. &plen), 0);
  74839. RSA_free(rsa);
  74840. der = privDer;
  74841. rsa = NULL;
  74842. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74843. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  74844. &plen), 0);
  74845. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  74846. &plen), 0);
  74847. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74848. NULL), 0);
  74849. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  74850. &plen), 1);
  74851. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74852. pem = NULL;
  74853. #ifndef NO_AES
  74854. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  74855. NULL, 0, &pem, &plen), 1);
  74856. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74857. pem = NULL;
  74858. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  74859. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  74860. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  74861. #endif
  74862. RSA_free(rsa);
  74863. #endif
  74864. return EXPECT_RESULT();
  74865. }
  74866. static int test_wolfSSL_DH(void)
  74867. {
  74868. EXPECT_DECLS;
  74869. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  74870. DH *dh = NULL;
  74871. BIGNUM* p;
  74872. BIGNUM* q;
  74873. BIGNUM* g;
  74874. BIGNUM* pub = NULL;
  74875. BIGNUM* priv = NULL;
  74876. #if defined(OPENSSL_ALL)
  74877. #if !defined(HAVE_FIPS) || \
  74878. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  74879. FILE* f = NULL;
  74880. unsigned char buf[268];
  74881. const unsigned char* pt = buf;
  74882. long len = 0;
  74883. dh = NULL;
  74884. XMEMSET(buf, 0, sizeof(buf));
  74885. /* Test 2048 bit parameters */
  74886. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  74887. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  74888. if (f != XBADFILE)
  74889. XFCLOSE(f);
  74890. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  74891. ExpectNotNull(dh->p);
  74892. ExpectNotNull(dh->g);
  74893. ExpectTrue(pt == buf);
  74894. ExpectIntEQ(DH_generate_key(dh), 1);
  74895. /* first, test for expected successful key agreement. */
  74896. if (EXPECT_SUCCESS()) {
  74897. DH *dh2 = NULL;
  74898. unsigned char buf2[268];
  74899. int sz1 = 0, sz2 = 0;
  74900. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  74901. ExpectIntEQ(DH_generate_key(dh2), 1);
  74902. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  74903. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  74904. ExpectIntEQ(sz1, sz2);
  74905. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  74906. ExpectIntNE(sz1 = DH_size(dh), 0);
  74907. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  74908. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  74909. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  74910. if (dh2 != NULL)
  74911. DH_free(dh2);
  74912. }
  74913. ExpectIntEQ(DH_generate_key(dh), 1);
  74914. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  74915. ExpectNotNull(pub = BN_new());
  74916. ExpectIntEQ(BN_set_word(pub, 1), 1);
  74917. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  74918. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  74919. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  74920. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  74921. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  74922. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  74923. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  74924. BN_free(pub);
  74925. pub = NULL;
  74926. DH_get0_pqg(dh, (const BIGNUM**)&p,
  74927. (const BIGNUM**)&q,
  74928. (const BIGNUM**)&g);
  74929. ExpectPtrEq(p, dh->p);
  74930. ExpectPtrEq(q, dh->q);
  74931. ExpectPtrEq(g, dh->g);
  74932. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  74933. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  74934. ExpectPtrEq(pub, dh->pub_key);
  74935. ExpectPtrEq(priv, dh->priv_key);
  74936. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  74937. ExpectPtrEq(pub, dh->pub_key);
  74938. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  74939. ExpectPtrEq(priv, dh->priv_key);
  74940. pub = NULL;
  74941. priv = NULL;
  74942. ExpectNotNull(pub = BN_new());
  74943. ExpectNotNull(priv = BN_new());
  74944. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  74945. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  74946. if (EXPECT_FAIL()) {
  74947. BN_free(pub);
  74948. BN_free(priv);
  74949. }
  74950. pub = NULL;
  74951. priv = NULL;
  74952. ExpectNotNull(pub = BN_new());
  74953. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  74954. if (EXPECT_FAIL()) {
  74955. BN_free(pub);
  74956. }
  74957. ExpectNotNull(priv = BN_new());
  74958. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  74959. if (EXPECT_FAIL()) {
  74960. BN_free(priv);
  74961. }
  74962. ExpectPtrEq(pub, dh->pub_key);
  74963. ExpectPtrEq(priv, dh->priv_key);
  74964. pub = NULL;
  74965. priv = NULL;
  74966. DH_free(dh);
  74967. dh = NULL;
  74968. ExpectNotNull(dh = DH_new());
  74969. p = NULL;
  74970. ExpectNotNull(p = BN_new());
  74971. ExpectIntEQ(BN_set_word(p, 1), 1);
  74972. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  74973. ExpectNotNull(pub = BN_new());
  74974. ExpectNotNull(priv = BN_new());
  74975. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  74976. if (EXPECT_FAIL()) {
  74977. BN_free(pub);
  74978. BN_free(priv);
  74979. }
  74980. pub = NULL;
  74981. priv = NULL;
  74982. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  74983. BN_free(p);
  74984. p = NULL;
  74985. DH_free(dh);
  74986. dh = NULL;
  74987. #ifdef WOLFSSL_KEY_GEN
  74988. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  74989. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  74990. DH_free(dh);
  74991. dh = NULL;
  74992. #endif
  74993. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  74994. #endif /* OPENSSL_ALL */
  74995. (void)dh;
  74996. (void)p;
  74997. (void)q;
  74998. (void)g;
  74999. (void)pub;
  75000. (void)priv;
  75001. ExpectNotNull(dh = wolfSSL_DH_new());
  75002. /* invalid parameters test */
  75003. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  75004. (const BIGNUM**)&q,
  75005. (const BIGNUM**)&g);
  75006. DH_get0_pqg(dh, NULL,
  75007. (const BIGNUM**)&q,
  75008. (const BIGNUM**)&g);
  75009. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  75010. DH_get0_pqg(dh, NULL, NULL, NULL);
  75011. DH_get0_pqg(dh, (const BIGNUM**)&p,
  75012. (const BIGNUM**)&q,
  75013. (const BIGNUM**)&g);
  75014. ExpectPtrEq(p, NULL);
  75015. ExpectPtrEq(q, NULL);
  75016. ExpectPtrEq(g, NULL);
  75017. DH_free(dh);
  75018. dh = NULL;
  75019. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  75020. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  75021. #if defined(OPENSSL_ALL) || \
  75022. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75023. dh = wolfSSL_DH_new();
  75024. ExpectNotNull(dh);
  75025. p = wolfSSL_BN_new();
  75026. ExpectNotNull(p);
  75027. ExpectIntEQ(BN_set_word(p, 11), 1);
  75028. g = wolfSSL_BN_new();
  75029. ExpectNotNull(g);
  75030. ExpectIntEQ(BN_set_word(g, 2), 1);
  75031. q = wolfSSL_BN_new();
  75032. ExpectNotNull(q);
  75033. ExpectIntEQ(BN_set_word(q, 5), 1);
  75034. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  75035. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  75036. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  75037. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  75038. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  75039. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  75040. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  75041. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  75042. /* Don't need q. */
  75043. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75044. if (EXPECT_FAIL()) {
  75045. BN_free(p);
  75046. BN_free(g);
  75047. }
  75048. p = NULL;
  75049. g = NULL;
  75050. /* Setting again will free the p and g. */
  75051. wolfSSL_BN_free(q);
  75052. q = NULL;
  75053. DH_free(dh);
  75054. dh = NULL;
  75055. dh = wolfSSL_DH_new();
  75056. ExpectNotNull(dh);
  75057. p = wolfSSL_BN_new();
  75058. ExpectNotNull(p);
  75059. ExpectIntEQ(BN_set_word(p, 11), 1);
  75060. g = wolfSSL_BN_new();
  75061. ExpectNotNull(g);
  75062. ExpectIntEQ(BN_set_word(g, 2), 1);
  75063. q = wolfSSL_BN_new();
  75064. ExpectNotNull(q);
  75065. ExpectIntEQ(BN_set_word(q, 5), 1);
  75066. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  75067. /* p, q and g are now owned by dh - don't free. */
  75068. if (EXPECT_FAIL()) {
  75069. BN_free(p);
  75070. BN_free(q);
  75071. BN_free(g);
  75072. }
  75073. p = NULL;
  75074. q = NULL;
  75075. g = NULL;
  75076. p = wolfSSL_BN_new();
  75077. ExpectNotNull(p);
  75078. ExpectIntEQ(BN_set_word(p, 11), 1);
  75079. g = wolfSSL_BN_new();
  75080. ExpectNotNull(g);
  75081. ExpectIntEQ(BN_set_word(g, 2), 1);
  75082. q = wolfSSL_BN_new();
  75083. ExpectNotNull(q);
  75084. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  75085. if (EXPECT_FAIL()) {
  75086. BN_free(p);
  75087. }
  75088. p = NULL;
  75089. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  75090. if (EXPECT_FAIL()) {
  75091. BN_free(q);
  75092. }
  75093. q = NULL;
  75094. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  75095. if (EXPECT_FAIL()) {
  75096. BN_free(g);
  75097. }
  75098. g = NULL;
  75099. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  75100. /* p, q and g are now owned by dh - don't free. */
  75101. DH_free(dh);
  75102. dh = NULL;
  75103. ExpectIntEQ(DH_generate_key(NULL), 0);
  75104. ExpectNotNull(dh = DH_new());
  75105. ExpectIntEQ(DH_generate_key(dh), 0);
  75106. p = wolfSSL_BN_new();
  75107. ExpectNotNull(p);
  75108. ExpectIntEQ(BN_set_word(p, 0), 1);
  75109. g = wolfSSL_BN_new();
  75110. ExpectNotNull(g);
  75111. ExpectIntEQ(BN_set_word(g, 2), 1);
  75112. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75113. if (EXPECT_FAIL()) {
  75114. BN_free(p);
  75115. BN_free(g);
  75116. }
  75117. p = NULL;
  75118. g = NULL;
  75119. ExpectIntEQ(DH_generate_key(dh), 0);
  75120. DH_free(dh);
  75121. dh = NULL;
  75122. #endif
  75123. #endif
  75124. /* Test DH_up_ref() */
  75125. dh = wolfSSL_DH_new();
  75126. ExpectNotNull(dh);
  75127. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75128. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  75129. DH_free(dh); /* decrease ref count */
  75130. DH_free(dh); /* free WOLFSSL_DH */
  75131. dh = NULL;
  75132. q = NULL;
  75133. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  75134. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  75135. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  75136. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  75137. #ifdef HAVE_FFDHE_2048
  75138. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75139. DH_free(dh);
  75140. dh = NULL;
  75141. q = NULL;
  75142. #endif
  75143. #ifdef HAVE_FFDHE_3072
  75144. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  75145. DH_free(dh);
  75146. dh = NULL;
  75147. q = NULL;
  75148. #endif
  75149. #ifdef HAVE_FFDHE_4096
  75150. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  75151. DH_free(dh);
  75152. dh = NULL;
  75153. q = NULL;
  75154. #endif
  75155. #else
  75156. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75157. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  75158. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  75159. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  75160. #endif /* OPENSSL_EXTRA && !NO_DH */
  75161. return EXPECT_RESULT();
  75162. }
  75163. static int test_wolfSSL_DH_dup(void)
  75164. {
  75165. EXPECT_DECLS;
  75166. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  75167. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  75168. defined(OPENSSL_EXTRA)
  75169. DH *dh = NULL;
  75170. DH *dhDup = NULL;
  75171. ExpectNotNull(dh = wolfSSL_DH_new());
  75172. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  75173. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  75174. #if defined(OPENSSL_ALL) || \
  75175. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75176. {
  75177. WOLFSSL_BIGNUM* p = NULL;
  75178. WOLFSSL_BIGNUM* g = NULL;
  75179. ExpectNotNull(p = wolfSSL_BN_new());
  75180. ExpectNotNull(g = wolfSSL_BN_new());
  75181. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  75182. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  75183. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75184. if (EXPECT_FAIL()) {
  75185. wolfSSL_BN_free(p);
  75186. wolfSSL_BN_free(g);
  75187. }
  75188. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  75189. wolfSSL_DH_free(dhDup);
  75190. }
  75191. #endif
  75192. wolfSSL_DH_free(dh);
  75193. #endif
  75194. #endif
  75195. return EXPECT_RESULT();
  75196. }
  75197. static int test_wolfSSL_DH_check(void)
  75198. {
  75199. EXPECT_DECLS;
  75200. #ifdef OPENSSL_ALL
  75201. #ifndef NO_DH
  75202. #ifndef NO_BIO
  75203. #ifndef NO_DSA
  75204. byte buf[6000];
  75205. char file[] = "./certs/dsaparams.pem";
  75206. XFILE f = XBADFILE;
  75207. int bytes;
  75208. BIO* bio = NULL;
  75209. DSA* dsa = NULL;
  75210. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75211. static const byte dh2048[] = {
  75212. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75213. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75214. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75215. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75216. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75217. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75218. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75219. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75220. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75221. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75222. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75223. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75224. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75225. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75226. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75227. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75228. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75229. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75230. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75231. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75232. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75233. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75234. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75235. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75236. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75237. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75238. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75239. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75240. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75241. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75242. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75243. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75244. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75245. 0x93, 0x02, 0x01, 0x02
  75246. };
  75247. const byte* params;
  75248. #endif
  75249. DH* dh = NULL;
  75250. WOLFSSL_BIGNUM* p = NULL;
  75251. WOLFSSL_BIGNUM* g = NULL;
  75252. WOLFSSL_BIGNUM* pTmp = NULL;
  75253. WOLFSSL_BIGNUM* gTmp = NULL;
  75254. int codes = -1;
  75255. #ifndef NO_DSA
  75256. /* Initialize DH */
  75257. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  75258. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  75259. if (f != XBADFILE)
  75260. XFCLOSE(f);
  75261. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  75262. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  75263. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  75264. ExpectNotNull(dh);
  75265. BIO_free(bio);
  75266. DSA_free(dsa);
  75267. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75268. params = dh2048;
  75269. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  75270. (long)sizeof(dh2048)));
  75271. #else
  75272. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  75273. #endif
  75274. /* Test assumed to be valid dh.
  75275. * Should return WOLFSSL_SUCCESS
  75276. * codes should be 0
  75277. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  75278. */
  75279. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75280. ExpectIntEQ(codes, 0);
  75281. /* Test NULL dh: expected BAD_FUNC_ARG */
  75282. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  75283. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  75284. if (dh != NULL) {
  75285. pTmp = dh->p;
  75286. dh->p = NULL;
  75287. }
  75288. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75289. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75290. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75291. /* set dh->p back to normal so it won't fail on next tests */
  75292. if (dh != NULL) {
  75293. dh->p = pTmp;
  75294. pTmp = NULL;
  75295. }
  75296. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  75297. if (dh != NULL) {
  75298. gTmp = dh->g;
  75299. dh->g = NULL;
  75300. }
  75301. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75302. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75303. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  75304. if (dh != NULL) {
  75305. dh->g = gTmp;
  75306. gTmp = NULL;
  75307. }
  75308. /* Cleanup */
  75309. DH_free(dh);
  75310. dh = NULL;
  75311. dh = DH_new();
  75312. ExpectNotNull(dh);
  75313. /* Check empty DH. */
  75314. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75315. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75316. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  75317. /* Check non-prime valued p. */
  75318. ExpectNotNull(p = BN_new());
  75319. ExpectIntEQ(BN_set_word(p, 4), 1);
  75320. ExpectNotNull(g = BN_new());
  75321. ExpectIntEQ(BN_set_word(g, 2), 1);
  75322. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  75323. if (EXPECT_FAIL()) {
  75324. wolfSSL_BN_free(p);
  75325. wolfSSL_BN_free(g);
  75326. }
  75327. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75328. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75329. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75330. DH_free(dh);
  75331. dh = NULL;
  75332. #endif
  75333. #endif /* !NO_DH && !NO_DSA */
  75334. #endif
  75335. return EXPECT_RESULT();
  75336. }
  75337. static int test_wolfSSL_DH_prime(void)
  75338. {
  75339. EXPECT_DECLS;
  75340. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75341. WOLFSSL_BIGNUM* bn = NULL;
  75342. #if WOLFSSL_MAX_BN_BITS >= 768
  75343. WOLFSSL_BIGNUM* bn2 = NULL;
  75344. #endif
  75345. bn = wolfSSL_DH_768_prime(NULL);
  75346. #if WOLFSSL_MAX_BN_BITS >= 768
  75347. ExpectNotNull(bn);
  75348. bn2 = wolfSSL_DH_768_prime(bn);
  75349. ExpectNotNull(bn2);
  75350. ExpectTrue(bn == bn2);
  75351. wolfSSL_BN_free(bn);
  75352. bn = NULL;
  75353. #else
  75354. ExpectNull(bn);
  75355. #endif
  75356. bn = wolfSSL_DH_1024_prime(NULL);
  75357. #if WOLFSSL_MAX_BN_BITS >= 1024
  75358. ExpectNotNull(bn);
  75359. wolfSSL_BN_free(bn);
  75360. bn = NULL;
  75361. #else
  75362. ExpectNull(bn);
  75363. #endif
  75364. bn = wolfSSL_DH_2048_prime(NULL);
  75365. #if WOLFSSL_MAX_BN_BITS >= 2048
  75366. ExpectNotNull(bn);
  75367. wolfSSL_BN_free(bn);
  75368. bn = NULL;
  75369. #else
  75370. ExpectNull(bn);
  75371. #endif
  75372. bn = wolfSSL_DH_3072_prime(NULL);
  75373. #if WOLFSSL_MAX_BN_BITS >= 3072
  75374. ExpectNotNull(bn);
  75375. wolfSSL_BN_free(bn);
  75376. bn = NULL;
  75377. #else
  75378. ExpectNull(bn);
  75379. #endif
  75380. bn = wolfSSL_DH_4096_prime(NULL);
  75381. #if WOLFSSL_MAX_BN_BITS >= 4096
  75382. ExpectNotNull(bn);
  75383. wolfSSL_BN_free(bn);
  75384. bn = NULL;
  75385. #else
  75386. ExpectNull(bn);
  75387. #endif
  75388. bn = wolfSSL_DH_6144_prime(NULL);
  75389. #if WOLFSSL_MAX_BN_BITS >= 6144
  75390. ExpectNotNull(bn);
  75391. wolfSSL_BN_free(bn);
  75392. bn = NULL;
  75393. #else
  75394. ExpectNull(bn);
  75395. #endif
  75396. bn = wolfSSL_DH_8192_prime(NULL);
  75397. #if WOLFSSL_MAX_BN_BITS >= 8192
  75398. ExpectNotNull(bn);
  75399. wolfSSL_BN_free(bn);
  75400. bn = NULL;
  75401. #else
  75402. ExpectNull(bn);
  75403. #endif
  75404. #endif
  75405. return EXPECT_RESULT();
  75406. }
  75407. static int test_wolfSSL_DH_1536_prime(void)
  75408. {
  75409. EXPECT_DECLS;
  75410. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75411. BIGNUM* bn = NULL;
  75412. unsigned char bits[200];
  75413. int sz = 192; /* known binary size */
  75414. const byte expected[] = {
  75415. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75416. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  75417. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  75418. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  75419. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  75420. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  75421. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  75422. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  75423. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  75424. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  75425. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  75426. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  75427. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  75428. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  75429. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  75430. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  75431. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  75432. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  75433. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  75434. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  75435. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  75436. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  75437. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  75438. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75439. };
  75440. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  75441. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  75442. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  75443. BN_free(bn);
  75444. #endif
  75445. return EXPECT_RESULT();
  75446. }
  75447. static int test_wolfSSL_DH_get_2048_256(void)
  75448. {
  75449. EXPECT_DECLS;
  75450. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75451. WOLFSSL_DH* dh = NULL;
  75452. const WOLFSSL_BIGNUM* pBn;
  75453. const WOLFSSL_BIGNUM* gBn;
  75454. const WOLFSSL_BIGNUM* qBn;
  75455. const byte pExpected[] = {
  75456. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  75457. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  75458. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  75459. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  75460. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  75461. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  75462. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  75463. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  75464. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  75465. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  75466. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  75467. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  75468. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  75469. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  75470. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  75471. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  75472. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  75473. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  75474. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  75475. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  75476. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  75477. 0x1E, 0x1A, 0x15, 0x97
  75478. };
  75479. const byte gExpected[] = {
  75480. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  75481. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  75482. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  75483. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  75484. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  75485. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  75486. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  75487. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  75488. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  75489. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  75490. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  75491. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  75492. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  75493. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  75494. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  75495. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  75496. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  75497. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  75498. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  75499. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  75500. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  75501. 0x6C, 0xC4, 0x16, 0x59
  75502. };
  75503. const byte qExpected[] = {
  75504. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  75505. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  75506. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  75507. };
  75508. int pSz = 0;
  75509. int qSz = 0;
  75510. int gSz = 0;
  75511. byte* pReturned = NULL;
  75512. byte* qReturned = NULL;
  75513. byte* gReturned = NULL;
  75514. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  75515. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  75516. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  75517. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  75518. DYNAMIC_TYPE_TMP_BUFFER));
  75519. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  75520. ExpectIntEQ(pSz, sizeof(pExpected));
  75521. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  75522. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  75523. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  75524. DYNAMIC_TYPE_TMP_BUFFER));
  75525. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  75526. ExpectIntEQ(qSz, sizeof(qExpected));
  75527. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  75528. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  75529. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  75530. DYNAMIC_TYPE_TMP_BUFFER));
  75531. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  75532. ExpectIntEQ(gSz, sizeof(gExpected));
  75533. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  75534. wolfSSL_DH_free(dh);
  75535. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75536. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75537. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75538. #endif
  75539. return EXPECT_RESULT();
  75540. }
  75541. static int test_wolfSSL_PEM_write_DHparams(void)
  75542. {
  75543. EXPECT_DECLS;
  75544. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  75545. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  75546. DH* dh = NULL;
  75547. BIO* bio = NULL;
  75548. XFILE fp = XBADFILE;
  75549. byte pem[2048];
  75550. int pemSz = 0;
  75551. const char expected[] =
  75552. "-----BEGIN DH PARAMETERS-----\n"
  75553. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  75554. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  75555. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  75556. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  75557. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  75558. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  75559. "-----END DH PARAMETERS-----\n";
  75560. const char badPem[] =
  75561. "-----BEGIN DH PARAMETERS-----\n"
  75562. "-----END DH PARAMETERS-----\n";
  75563. const char emptySeqPem[] =
  75564. "-----BEGIN DH PARAMETERS-----\n"
  75565. "MAA=\n"
  75566. "-----END DH PARAMETERS-----\n";
  75567. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  75568. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75569. if (fp != XBADFILE) {
  75570. XFCLOSE(fp);
  75571. fp = XBADFILE;
  75572. }
  75573. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  75574. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75575. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75576. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  75577. (int)sizeof(badPem));
  75578. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75579. BIO_free(bio);
  75580. bio = NULL;
  75581. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75582. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75583. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  75584. (int)sizeof(emptySeqPem));
  75585. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75586. BIO_free(bio);
  75587. bio = NULL;
  75588. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75589. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  75590. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75591. BIO_free(bio);
  75592. bio = NULL;
  75593. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  75594. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  75595. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75596. DH_free(dh);
  75597. dh = NULL;
  75598. dh = wolfSSL_DH_new();
  75599. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75600. if (fp != XBADFILE) {
  75601. XFCLOSE(fp);
  75602. fp = XBADFILE;
  75603. }
  75604. wolfSSL_DH_free(dh);
  75605. dh = NULL;
  75606. /* check results */
  75607. XMEMSET(pem, 0, sizeof(pem));
  75608. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  75609. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75610. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  75611. if (fp != XBADFILE)
  75612. XFCLOSE(fp);
  75613. #endif
  75614. return EXPECT_RESULT();
  75615. }
  75616. static int test_wolfSSL_d2i_DHparams(void)
  75617. {
  75618. EXPECT_DECLS;
  75619. #ifdef OPENSSL_ALL
  75620. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75621. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75622. XFILE f = XBADFILE;
  75623. unsigned char buf[4096];
  75624. const unsigned char* pt = buf;
  75625. #ifdef HAVE_FFDHE_2048
  75626. const char* params1 = "./certs/dh2048.der";
  75627. #endif
  75628. #ifdef HAVE_FFDHE_3072
  75629. const char* params2 = "./certs/dh3072.der";
  75630. #endif
  75631. long len = 0;
  75632. WOLFSSL_DH* dh = NULL;
  75633. XMEMSET(buf, 0, sizeof(buf));
  75634. /* Test 2048 bit parameters */
  75635. #ifdef HAVE_FFDHE_2048
  75636. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75637. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75638. if (f != XBADFILE) {
  75639. XFCLOSE(f);
  75640. f = XBADFILE;
  75641. }
  75642. /* Valid case */
  75643. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75644. ExpectNotNull(dh->p);
  75645. ExpectNotNull(dh->g);
  75646. ExpectTrue(pt == buf);
  75647. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  75648. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  75649. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  75650. /* Invalid cases */
  75651. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75652. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75653. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  75654. DH_free(dh);
  75655. dh = NULL;
  75656. *buf = 0;
  75657. pt = buf;
  75658. #endif /* HAVE_FFDHE_2048 */
  75659. /* Test 3072 bit parameters */
  75660. #ifdef HAVE_FFDHE_3072
  75661. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75662. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75663. if (f != XBADFILE) {
  75664. XFCLOSE(f);
  75665. f = XBADFILE;
  75666. }
  75667. /* Valid case */
  75668. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  75669. ExpectNotNull(dh->p);
  75670. ExpectNotNull(dh->g);
  75671. ExpectTrue(pt != buf);
  75672. ExpectIntEQ(DH_generate_key(dh), 1);
  75673. /* Invalid cases */
  75674. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75675. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75676. DH_free(dh);
  75677. dh = NULL;
  75678. #endif /* HAVE_FFDHE_3072 */
  75679. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75680. #endif /* !NO_DH */
  75681. #endif
  75682. return EXPECT_RESULT();
  75683. }
  75684. static int test_wolfSSL_DH_LoadDer(void)
  75685. {
  75686. EXPECT_DECLS;
  75687. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  75688. defined(OPENSSL_EXTRA)
  75689. static const byte dh2048[] = {
  75690. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75691. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75692. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75693. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75694. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75695. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75696. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75697. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75698. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75699. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75700. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75701. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75702. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75703. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75704. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75705. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75706. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75707. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75708. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75709. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75710. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75711. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75712. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75713. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75714. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75715. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75716. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75717. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75718. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75719. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75720. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75721. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75722. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75723. 0x93, 0x02, 0x01, 0x02
  75724. };
  75725. WOLFSSL_DH* dh = NULL;
  75726. ExpectNotNull(dh = wolfSSL_DH_new());
  75727. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  75728. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  75729. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  75730. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  75731. wolfSSL_DH_free(dh);
  75732. #endif
  75733. return EXPECT_RESULT();
  75734. }
  75735. static int test_wolfSSL_i2d_DHparams(void)
  75736. {
  75737. EXPECT_DECLS;
  75738. #ifdef OPENSSL_ALL
  75739. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75740. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75741. XFILE f = XBADFILE;
  75742. unsigned char buf[4096];
  75743. const unsigned char* pt;
  75744. unsigned char* pt2;
  75745. #ifdef HAVE_FFDHE_2048
  75746. const char* params1 = "./certs/dh2048.der";
  75747. #endif
  75748. #ifdef HAVE_FFDHE_3072
  75749. const char* params2 = "./certs/dh3072.der";
  75750. #endif
  75751. long len = 0;
  75752. WOLFSSL_DH* dh = NULL;
  75753. /* Test 2048 bit parameters */
  75754. #ifdef HAVE_FFDHE_2048
  75755. pt = buf;
  75756. pt2 = buf;
  75757. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75758. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75759. if (f != XBADFILE) {
  75760. XFCLOSE(f);
  75761. f = XBADFILE;
  75762. }
  75763. /* Valid case */
  75764. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75765. ExpectTrue(pt == buf);
  75766. ExpectIntEQ(DH_generate_key(dh), 1);
  75767. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  75768. /* Invalid case */
  75769. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  75770. /* Return length only */
  75771. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  75772. DH_free(dh);
  75773. dh = NULL;
  75774. *buf = 0;
  75775. #endif
  75776. /* Test 3072 bit parameters */
  75777. #ifdef HAVE_FFDHE_3072
  75778. pt = buf;
  75779. pt2 = buf;
  75780. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75781. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75782. if (f != XBADFILE) {
  75783. XFCLOSE(f);
  75784. f = XBADFILE;
  75785. }
  75786. /* Valid case */
  75787. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75788. ExpectTrue(pt == buf);
  75789. ExpectIntEQ(DH_generate_key(dh), 1);
  75790. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  75791. /* Invalid case */
  75792. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  75793. /* Return length only */
  75794. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  75795. DH_free(dh);
  75796. dh = NULL;
  75797. #endif
  75798. dh = DH_new();
  75799. ExpectNotNull(dh);
  75800. pt2 = buf;
  75801. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  75802. DH_free(dh);
  75803. dh = NULL;
  75804. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75805. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  75806. #endif
  75807. return EXPECT_RESULT();
  75808. }
  75809. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  75810. /*----------------------------------------------------------------------------*
  75811. | EC
  75812. *----------------------------------------------------------------------------*/
  75813. static int test_wolfSSL_EC_GROUP(void)
  75814. {
  75815. EXPECT_DECLS;
  75816. #ifdef OPENSSL_EXTRA
  75817. EC_GROUP *group = NULL;
  75818. EC_GROUP *group2 = NULL;
  75819. EC_GROUP *group3 = NULL;
  75820. #ifndef HAVE_ECC_BRAINPOOL
  75821. EC_GROUP *group4 = NULL;
  75822. #endif
  75823. WOLFSSL_BIGNUM* order = NULL;
  75824. int group_bits;
  75825. int i;
  75826. static const int knownEccNids[] = {
  75827. NID_X9_62_prime192v1,
  75828. NID_X9_62_prime192v2,
  75829. NID_X9_62_prime192v3,
  75830. NID_X9_62_prime239v1,
  75831. NID_X9_62_prime239v2,
  75832. NID_X9_62_prime239v3,
  75833. NID_X9_62_prime256v1,
  75834. NID_secp112r1,
  75835. NID_secp112r2,
  75836. NID_secp128r1,
  75837. NID_secp128r2,
  75838. NID_secp160r1,
  75839. NID_secp160r2,
  75840. NID_secp224r1,
  75841. NID_secp384r1,
  75842. NID_secp521r1,
  75843. NID_secp160k1,
  75844. NID_secp192k1,
  75845. NID_secp224k1,
  75846. NID_secp256k1,
  75847. NID_brainpoolP160r1,
  75848. NID_brainpoolP192r1,
  75849. NID_brainpoolP224r1,
  75850. NID_brainpoolP256r1,
  75851. NID_brainpoolP320r1,
  75852. NID_brainpoolP384r1,
  75853. NID_brainpoolP512r1,
  75854. };
  75855. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  75856. static const int knownEccEnums[] = {
  75857. ECC_SECP192R1,
  75858. ECC_PRIME192V2,
  75859. ECC_PRIME192V3,
  75860. ECC_PRIME239V1,
  75861. ECC_PRIME239V2,
  75862. ECC_PRIME239V3,
  75863. ECC_SECP256R1,
  75864. ECC_SECP112R1,
  75865. ECC_SECP112R2,
  75866. ECC_SECP128R1,
  75867. ECC_SECP128R2,
  75868. ECC_SECP160R1,
  75869. ECC_SECP160R2,
  75870. ECC_SECP224R1,
  75871. ECC_SECP384R1,
  75872. ECC_SECP521R1,
  75873. ECC_SECP160K1,
  75874. ECC_SECP192K1,
  75875. ECC_SECP224K1,
  75876. ECC_SECP256K1,
  75877. ECC_BRAINPOOLP160R1,
  75878. ECC_BRAINPOOLP192R1,
  75879. ECC_BRAINPOOLP224R1,
  75880. ECC_BRAINPOOLP256R1,
  75881. ECC_BRAINPOOLP320R1,
  75882. ECC_BRAINPOOLP384R1,
  75883. ECC_BRAINPOOLP512R1,
  75884. };
  75885. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  75886. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  75887. ExpectNotNull(group2 = EC_GROUP_dup(group));
  75888. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  75889. #ifndef HAVE_ECC_BRAINPOOL
  75890. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  75891. NID_brainpoolP256r1));
  75892. #endif
  75893. ExpectNull(EC_GROUP_dup(NULL));
  75894. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  75895. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  75896. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  75897. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  75898. #ifndef HAVE_ECC_BRAINPOOL
  75899. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  75900. #endif
  75901. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  75902. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  75903. ExpectNotNull(order = BN_new());
  75904. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  75905. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  75906. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  75907. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  75908. wolfSSL_BN_free(order);
  75909. ExpectNotNull(EC_GROUP_method_of(group));
  75910. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  75911. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  75912. NID_X9_62_prime_field);
  75913. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  75914. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  75915. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  75916. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  75917. #ifndef NO_WOLFSSL_STUB
  75918. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  75919. #endif
  75920. #ifndef HAVE_ECC_BRAINPOOL
  75921. EC_GROUP_free(group4);
  75922. #endif
  75923. EC_GROUP_free(group3);
  75924. EC_GROUP_free(group2);
  75925. EC_GROUP_free(group);
  75926. for (i = 0; i < knowEccNidsLen; i++) {
  75927. group = NULL;
  75928. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  75929. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  75930. EC_GROUP_free(group);
  75931. }
  75932. for (i = 0; i < knowEccEnumsLen; i++) {
  75933. group = NULL;
  75934. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  75935. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  75936. EC_GROUP_free(group);
  75937. }
  75938. #endif
  75939. return EXPECT_RESULT();
  75940. }
  75941. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  75942. {
  75943. EXPECT_DECLS;
  75944. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  75945. EC_GROUP *group = NULL;
  75946. BIO* bio = NULL;
  75947. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  75948. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  75949. EC_GROUP *ret = NULL;
  75950. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  75951. "BgUrgQQAIg==\n"
  75952. "-----END EC PARAMETERS-----";
  75953. #endif
  75954. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  75955. "MAA=\n"
  75956. "-----END EC PARAMETERS-----";
  75957. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  75958. "BgA=\n"
  75959. "-----END EC PARAMETERS-----";
  75960. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  75961. "BgE=\n"
  75962. "-----END EC PARAMETERS-----";
  75963. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  75964. "BgE*\n"
  75965. "-----END EC PARAMETERS-----";
  75966. /* Test that first parameter, bio, being NULL fails. */
  75967. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  75968. /* Test that reading named parameters works. */
  75969. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  75970. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  75971. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  75972. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  75973. BIO_free(bio);
  75974. bio = NULL;
  75975. EC_GROUP_free(group);
  75976. group = NULL;
  75977. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  75978. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  75979. /* Test that reusing group works. */
  75980. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  75981. sizeof(ec_nc_p384)));
  75982. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  75983. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  75984. BIO_free(bio);
  75985. bio = NULL;
  75986. EC_GROUP_free(group);
  75987. group = NULL;
  75988. /* Test that returning through group works. */
  75989. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  75990. sizeof(ec_nc_p384)));
  75991. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  75992. ExpectIntEQ(group == ret, 1);
  75993. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  75994. BIO_free(bio);
  75995. bio = NULL;
  75996. EC_GROUP_free(group);
  75997. group = NULL;
  75998. #endif
  75999. /* Test 0x30, 0x00 (not and object id) fails. */
  76000. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  76001. sizeof(ec_nc_bad_1)));
  76002. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76003. BIO_free(bio);
  76004. bio = NULL;
  76005. /* Test 0x06, 0x00 (empty object id) fails. */
  76006. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  76007. sizeof(ec_nc_bad_2)));
  76008. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76009. BIO_free(bio);
  76010. bio = NULL;
  76011. /* Test 0x06, 0x01 (badly formed object id) fails. */
  76012. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  76013. sizeof(ec_nc_bad_3)));
  76014. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76015. BIO_free(bio);
  76016. bio = NULL;
  76017. /* Test invalid PEM encoding - invalid character. */
  76018. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  76019. sizeof(ec_nc_bad_4)));
  76020. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76021. BIO_free(bio);
  76022. #endif
  76023. return EXPECT_RESULT();
  76024. }
  76025. static int test_wolfSSL_EC_POINT(void)
  76026. {
  76027. EXPECT_DECLS;
  76028. #if !defined(WOLFSSL_SP_MATH) && \
  76029. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  76030. #ifdef OPENSSL_EXTRA
  76031. BN_CTX* ctx = NULL;
  76032. EC_GROUP* group = NULL;
  76033. #ifndef HAVE_ECC_BRAINPOOL
  76034. EC_GROUP* group2 = NULL;
  76035. #endif
  76036. EC_POINT* Gxy = NULL;
  76037. EC_POINT* new_point = NULL;
  76038. EC_POINT* set_point = NULL;
  76039. EC_POINT* get_point = NULL;
  76040. EC_POINT* infinity = NULL;
  76041. BIGNUM* k = NULL;
  76042. BIGNUM* Gx = NULL;
  76043. BIGNUM* Gy = NULL;
  76044. BIGNUM* Gz = NULL;
  76045. BIGNUM* X = NULL;
  76046. BIGNUM* Y = NULL;
  76047. BIGNUM* set_point_bn = NULL;
  76048. char* hexStr = NULL;
  76049. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  76050. "17AF381913FF7A96314EA47055EA0FD0";
  76051. /* NISTP256R1 Gx/Gy */
  76052. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  76053. "77037D812DEB33A0F4A13945D898C296";
  76054. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76055. "2BCE33576B315ECECBB6406837BF51F5";
  76056. const char* uncompG
  76057. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  76058. "77037D812DEB33A0F4A13945D898C296"
  76059. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76060. "2BCE33576B315ECECBB6406837BF51F5";
  76061. const char* compG
  76062. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  76063. "77037D812DEB33A0F4A13945D898C296";
  76064. #ifndef HAVE_SELFTEST
  76065. EC_POINT *tmp = NULL;
  76066. size_t bin_len;
  76067. unsigned int blen = 0;
  76068. unsigned char* buf = NULL;
  76069. unsigned char bufInf[1] = { 0x00 };
  76070. const unsigned char binUncompG[] = {
  76071. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76072. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76073. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76074. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76075. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76076. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76077. };
  76078. const unsigned char binUncompGBad[] = {
  76079. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76080. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76081. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76082. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76083. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76084. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76085. };
  76086. #ifdef HAVE_COMP_KEY
  76087. const unsigned char binCompG[] = {
  76088. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76089. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76090. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76091. };
  76092. #endif
  76093. #endif
  76094. ExpectNotNull(ctx = BN_CTX_new());
  76095. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76096. #ifndef HAVE_ECC_BRAINPOOL
  76097. /* Used to make groups curve_idx == -1. */
  76098. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  76099. #endif
  76100. ExpectNull(EC_POINT_new(NULL));
  76101. ExpectNotNull(Gxy = EC_POINT_new(group));
  76102. ExpectNotNull(new_point = EC_POINT_new(group));
  76103. ExpectNotNull(set_point = EC_POINT_new(group));
  76104. ExpectNotNull(X = BN_new());
  76105. ExpectNotNull(Y = BN_new());
  76106. ExpectNotNull(set_point_bn = BN_new());
  76107. ExpectNotNull(infinity = EC_POINT_new(group));
  76108. /* load test values */
  76109. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  76110. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  76111. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  76112. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  76113. /* populate coordinates for input point */
  76114. if (Gxy != NULL) {
  76115. Gxy->X = Gx;
  76116. Gxy->Y = Gy;
  76117. Gxy->Z = Gz;
  76118. }
  76119. /* Test handling of NULL point. */
  76120. EC_POINT_clear_free(NULL);
  76121. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76122. NULL, NULL, ctx), 0);
  76123. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76124. NULL, NULL, ctx), 0);
  76125. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76126. NULL, NULL, ctx), 0);
  76127. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76128. X, NULL, ctx), 0);
  76129. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76130. NULL, Y, ctx), 0);
  76131. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76132. X, Y, ctx), 0);
  76133. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76134. X, Y, ctx), 0);
  76135. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76136. NULL, Y, ctx), 0);
  76137. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76138. X, NULL, ctx), 0);
  76139. /* Getting point at infinity returns an error. */
  76140. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  76141. X, Y, ctx), 0);
  76142. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76143. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76144. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76145. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  76146. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  76147. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  76148. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  76149. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  76150. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  76151. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  76152. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  76153. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  76154. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  76155. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  76156. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  76157. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  76158. /* perform point multiplication */
  76159. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  76160. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76161. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76162. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76163. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), 1);
  76164. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76165. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76166. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76167. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), 1);
  76168. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76169. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76170. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76171. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, NULL, NULL, ctx), 1);
  76172. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  76173. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  76174. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76175. /* Set point to something. */
  76176. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  76177. #else
  76178. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  76179. ctx), 1);
  76180. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76181. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76182. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76183. #endif
  76184. /* check if point X coordinate is zero */
  76185. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76186. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  76187. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  76188. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  76189. #endif
  76190. /* extract the coordinates from point */
  76191. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76192. ctx), WOLFSSL_SUCCESS);
  76193. /* check if point X coordinate is zero */
  76194. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76195. /* set the same X and Y points in another object */
  76196. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  76197. ctx), WOLFSSL_SUCCESS);
  76198. /* compare points as they should be the same */
  76199. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  76200. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  76201. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  76202. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  76203. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  76204. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  76205. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  76206. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  76207. /* Test copying */
  76208. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  76209. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  76210. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  76211. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  76212. /* Test inverting */
  76213. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  76214. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  76215. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  76216. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  76217. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76218. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76219. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76220. {
  76221. EC_POINT* orig_point = NULL;
  76222. ExpectNotNull(orig_point = EC_POINT_new(group));
  76223. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  76224. 1);
  76225. /* new_point should be set_point inverted so adding it will revert
  76226. * the point back to set_point */
  76227. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  76228. NULL), 1);
  76229. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  76230. EC_POINT_free(orig_point);
  76231. }
  76232. #endif
  76233. /* Test getting affine converts from projective. */
  76234. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  76235. /* Force non-affine coordinates */
  76236. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76237. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  76238. if (new_point != NULL) {
  76239. new_point->inSet = 0;
  76240. }
  76241. /* extract the coordinates from point */
  76242. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76243. ctx), WOLFSSL_SUCCESS);
  76244. /* check if point ordinates have changed. */
  76245. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  76246. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  76247. /* Test check for infinity */
  76248. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  76249. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  76250. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  76251. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  76252. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  76253. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  76254. #else
  76255. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  76256. #endif
  76257. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  76258. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  76259. /* check bn2hex */
  76260. hexStr = BN_bn2hex(k);
  76261. ExpectStrEQ(hexStr, kTest);
  76262. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76263. defined(XFPRINTF)
  76264. BN_print_fp(stderr, k);
  76265. fprintf(stderr, "\n");
  76266. #endif
  76267. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76268. hexStr = BN_bn2hex(Gx);
  76269. ExpectStrEQ(hexStr, kGx);
  76270. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76271. defined(XFPRINTF)
  76272. BN_print_fp(stderr, Gx);
  76273. fprintf(stderr, "\n");
  76274. #endif
  76275. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76276. hexStr = BN_bn2hex(Gy);
  76277. ExpectStrEQ(hexStr, kGy);
  76278. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76279. defined(XFPRINTF)
  76280. BN_print_fp(stderr, Gy);
  76281. fprintf(stderr, "\n");
  76282. #endif
  76283. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76284. /* Test point to hex */
  76285. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76286. ctx));
  76287. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76288. ctx));
  76289. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76290. ctx));
  76291. #ifndef HAVE_ECC_BRAINPOOL
  76292. /* Group not supported in wolfCrypt. */
  76293. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76294. ctx));
  76295. #endif
  76296. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  76297. ExpectNotNull(hexStr);
  76298. ExpectStrEQ(hexStr, uncompG);
  76299. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  76300. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76301. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76302. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  76303. ExpectNotNull(hexStr);
  76304. ExpectStrEQ(hexStr, compG);
  76305. #ifdef HAVE_COMP_KEY
  76306. ExpectNotNull(get_point = EC_POINT_hex2point
  76307. (group, hexStr, get_point, ctx));
  76308. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76309. #endif
  76310. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76311. EC_POINT_free(get_point);
  76312. #ifndef HAVE_SELFTEST
  76313. /* Test point to oct */
  76314. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76315. NULL, 0, ctx), 0);
  76316. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76317. NULL, 0, ctx), 0);
  76318. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76319. NULL, 0, ctx), 0);
  76320. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76321. NULL, 0, ctx);
  76322. ExpectIntEQ(bin_len, sizeof(binUncompG));
  76323. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76324. DYNAMIC_TYPE_ECC));
  76325. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76326. buf, bin_len, ctx), bin_len);
  76327. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76328. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76329. /* Infinity (x=0, y=0) encodes as '0x00'. */
  76330. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76331. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  76332. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76333. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  76334. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76335. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  76336. ExpectIntEQ(bufInf[0], 0);
  76337. wolfSSL_EC_POINT_dump(NULL, NULL);
  76338. /* Test point i2d */
  76339. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  76340. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  76341. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  76342. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  76343. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  76344. ExpectIntEQ(blen, sizeof(binUncompG));
  76345. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  76346. blen -= 1;
  76347. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  76348. blen += 1;
  76349. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  76350. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76351. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76352. #ifdef HAVE_COMP_KEY
  76353. /* Test point to oct compressed */
  76354. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  76355. 0, ctx);
  76356. ExpectIntEQ(bin_len, sizeof(binCompG));
  76357. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76358. DYNAMIC_TYPE_ECC));
  76359. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  76360. bin_len, ctx), bin_len);
  76361. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  76362. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76363. #endif
  76364. /* Test point BN */
  76365. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  76366. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76367. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  76368. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76369. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  76370. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76371. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  76372. /* Test oct to point */
  76373. ExpectNotNull(tmp = EC_POINT_new(group));
  76374. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  76375. ctx), 0);
  76376. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  76377. ctx), 0);
  76378. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  76379. ctx), 0);
  76380. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  76381. sizeof(binUncompGBad), ctx), 0);
  76382. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  76383. ctx), 1);
  76384. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76385. EC_POINT_free(tmp);
  76386. tmp = NULL;
  76387. /* Test setting BN ordinates. */
  76388. ExpectNotNull(tmp = EC_POINT_new(group));
  76389. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76390. NULL, ctx), 0);
  76391. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  76392. NULL, ctx), 0);
  76393. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  76394. NULL, ctx), 0);
  76395. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  76396. NULL, ctx), 0);
  76397. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76398. Gy, ctx), 0);
  76399. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  76400. ctx), 0);
  76401. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  76402. ctx), 0);
  76403. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  76404. Gy, ctx), 0);
  76405. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  76406. NULL, ctx), 0);
  76407. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  76408. ctx), 1);
  76409. EC_POINT_free(tmp);
  76410. tmp = NULL;
  76411. /* Test point d2i */
  76412. ExpectNotNull(tmp = EC_POINT_new(group));
  76413. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  76414. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  76415. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  76416. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  76417. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  76418. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  76419. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  76420. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  76421. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  76422. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76423. EC_POINT_free(tmp);
  76424. tmp = NULL;
  76425. #ifdef HAVE_COMP_KEY
  76426. /* Test oct compressed to point */
  76427. ExpectNotNull(tmp = EC_POINT_new(group));
  76428. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  76429. 1);
  76430. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76431. EC_POINT_free(tmp);
  76432. tmp = NULL;
  76433. /* Test point d2i - compressed */
  76434. ExpectNotNull(tmp = EC_POINT_new(group));
  76435. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  76436. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76437. EC_POINT_free(tmp);
  76438. tmp = NULL;
  76439. #endif
  76440. #endif
  76441. /* test BN_mod_add */
  76442. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76443. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  76444. 1);
  76445. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76446. /* cleanup */
  76447. BN_free(X);
  76448. BN_free(Y);
  76449. BN_free(k);
  76450. BN_free(set_point_bn);
  76451. EC_POINT_free(infinity);
  76452. EC_POINT_free(new_point);
  76453. EC_POINT_free(set_point);
  76454. EC_POINT_clear_free(Gxy);
  76455. #ifndef HAVE_ECC_BRAINPOOL
  76456. EC_GROUP_free(group2);
  76457. #endif
  76458. EC_GROUP_free(group);
  76459. BN_CTX_free(ctx);
  76460. #endif
  76461. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  76462. return EXPECT_RESULT();
  76463. }
  76464. static int test_wolfSSL_SPAKE(void)
  76465. {
  76466. EXPECT_DECLS;
  76467. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  76468. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  76469. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76470. BIGNUM* x = NULL; /* kdc priv */
  76471. BIGNUM* y = NULL; /* client priv */
  76472. BIGNUM* w = NULL; /* shared value */
  76473. byte M_bytes[] = {
  76474. /* uncompressed */
  76475. 0x04,
  76476. /* x */
  76477. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  76478. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  76479. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  76480. /* y */
  76481. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  76482. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  76483. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  76484. };
  76485. EC_POINT* M = NULL; /* shared value */
  76486. byte N_bytes[] = {
  76487. /* uncompressed */
  76488. 0x04,
  76489. /* x */
  76490. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  76491. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  76492. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  76493. /* y */
  76494. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  76495. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  76496. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  76497. };
  76498. EC_POINT* N = NULL; /* shared value */
  76499. EC_POINT* T = NULL; /* kdc pub */
  76500. EC_POINT* tmp1 = NULL; /* kdc pub */
  76501. EC_POINT* tmp2 = NULL; /* kdc pub */
  76502. EC_POINT* S = NULL; /* client pub */
  76503. EC_POINT* client_secret = NULL;
  76504. EC_POINT* kdc_secret = NULL;
  76505. EC_GROUP* group = NULL;
  76506. BN_CTX* bn_ctx = NULL;
  76507. /* Values taken from a test run of Kerberos 5 */
  76508. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76509. ExpectNotNull(bn_ctx = BN_CTX_new());
  76510. ExpectNotNull(M = EC_POINT_new(group));
  76511. ExpectNotNull(N = EC_POINT_new(group));
  76512. ExpectNotNull(T = EC_POINT_new(group));
  76513. ExpectNotNull(tmp1 = EC_POINT_new(group));
  76514. ExpectNotNull(tmp2 = EC_POINT_new(group));
  76515. ExpectNotNull(S = EC_POINT_new(group));
  76516. ExpectNotNull(client_secret = EC_POINT_new(group));
  76517. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  76518. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  76519. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  76520. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  76521. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  76522. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  76523. "506AB395478F0AAB647752CF117B36250"), 1);
  76524. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  76525. 1);
  76526. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  76527. 1);
  76528. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  76529. /* kdc */
  76530. /* T=x*P+w*M */
  76531. /* All in one function call */
  76532. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  76533. /* Spread into separate calls */
  76534. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  76535. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  76536. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76537. 1);
  76538. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  76539. /* client */
  76540. /* S=y*P+w*N */
  76541. /* All in one function call */
  76542. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  76543. /* Spread into separate calls */
  76544. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  76545. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  76546. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76547. 1);
  76548. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  76549. /* K=y*(T-w*M) */
  76550. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  76551. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  76552. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  76553. 1);
  76554. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  76555. bn_ctx), 1);
  76556. /* kdc */
  76557. /* K=x*(S-w*N) */
  76558. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  76559. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  76560. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  76561. 1);
  76562. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  76563. 1);
  76564. /* kdc_secret == client_secret */
  76565. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  76566. BN_free(x);
  76567. BN_free(y);
  76568. BN_free(w);
  76569. EC_POINT_free(M);
  76570. EC_POINT_free(N);
  76571. EC_POINT_free(T);
  76572. EC_POINT_free(tmp1);
  76573. EC_POINT_free(tmp2);
  76574. EC_POINT_free(S);
  76575. EC_POINT_free(client_secret);
  76576. EC_POINT_free(kdc_secret);
  76577. EC_GROUP_free(group);
  76578. BN_CTX_free(bn_ctx);
  76579. #endif
  76580. return EXPECT_RESULT();
  76581. }
  76582. static int test_wolfSSL_EC_KEY_generate(void)
  76583. {
  76584. EXPECT_DECLS;
  76585. #ifdef OPENSSL_EXTRA
  76586. WOLFSSL_EC_KEY* key = NULL;
  76587. #ifndef HAVE_ECC_BRAINPOOL
  76588. WOLFSSL_EC_GROUP* group = NULL;
  76589. #endif
  76590. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76591. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  76592. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76593. wolfSSL_EC_KEY_free(key);
  76594. key = NULL;
  76595. #ifndef HAVE_ECC_BRAINPOOL
  76596. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  76597. NID_brainpoolP256r1));
  76598. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  76599. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  76600. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  76601. wolfSSL_EC_KEY_free(key);
  76602. wolfSSL_EC_GROUP_free(group);
  76603. #endif
  76604. #endif
  76605. return EXPECT_RESULT();
  76606. }
  76607. static int test_EC_i2d(void)
  76608. {
  76609. EXPECT_DECLS;
  76610. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  76611. EC_KEY *key = NULL;
  76612. EC_KEY *copy = NULL;
  76613. int len = 0;
  76614. unsigned char *buf = NULL;
  76615. unsigned char *p = NULL;
  76616. const unsigned char *tmp = NULL;
  76617. const unsigned char octBad[] = {
  76618. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76619. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76620. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76621. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76622. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76623. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76624. };
  76625. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76626. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  76627. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  76628. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76629. DYNAMIC_TYPE_TMP_BUFFER));
  76630. p = buf;
  76631. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  76632. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  76633. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  76634. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  76635. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76636. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  76637. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  76638. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  76639. tmp = buf;
  76640. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  76641. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  76642. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76643. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  76644. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  76645. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  76646. tmp = buf;
  76647. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  76648. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  76649. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  76650. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  76651. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  76652. {
  76653. EC_KEY *pubkey = NULL;
  76654. BIO* bio = NULL;
  76655. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76656. ExpectIntGT(BIO_write(bio, buf, len), 0);
  76657. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  76658. BIO_free(bio);
  76659. EC_KEY_free(pubkey);
  76660. }
  76661. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  76662. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  76663. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  76664. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  76665. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  76666. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  76667. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  76668. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  76669. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76670. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  76671. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76672. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  76673. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76674. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  76675. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76676. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  76677. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  76678. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76679. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76680. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76681. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76682. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76683. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76684. buf = NULL;
  76685. buf = NULL;
  76686. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  76687. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76688. DYNAMIC_TYPE_TMP_BUFFER));
  76689. p = buf;
  76690. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76691. p = NULL;
  76692. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76693. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76694. p = NULL;
  76695. /* Bad point is also an invalid private key. */
  76696. tmp = octBad;
  76697. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  76698. tmp = buf;
  76699. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  76700. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76701. buf = NULL;
  76702. buf = NULL;
  76703. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  76704. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76705. DYNAMIC_TYPE_TMP_BUFFER));
  76706. p = buf;
  76707. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76708. p = NULL;
  76709. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76710. tmp = buf;
  76711. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  76712. tmp = octBad;
  76713. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  76714. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  76715. ExpectIntEQ(EC_KEY_check_key(key), 1);
  76716. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  76717. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  76718. EC_KEY_free(key);
  76719. EC_KEY_free(copy);
  76720. #endif
  76721. return EXPECT_RESULT();
  76722. }
  76723. static int test_wolfSSL_EC_curve(void)
  76724. {
  76725. EXPECT_DECLS;
  76726. #if defined(OPENSSL_EXTRA)
  76727. int nid = NID_secp160k1;
  76728. const char* nid_name = NULL;
  76729. ExpectNull(EC_curve_nid2nist(NID_sha256));
  76730. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  76731. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  76732. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  76733. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  76734. #endif
  76735. return EXPECT_RESULT();
  76736. }
  76737. static int test_wolfSSL_EC_KEY_dup(void)
  76738. {
  76739. EXPECT_DECLS;
  76740. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  76741. WOLFSSL_EC_KEY* ecKey = NULL;
  76742. WOLFSSL_EC_KEY* dupKey = NULL;
  76743. ecc_key* srcKey = NULL;
  76744. ecc_key* destKey = NULL;
  76745. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76746. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76747. /* Valid cases */
  76748. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76749. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  76750. /* Compare pubkey */
  76751. if (ecKey != NULL) {
  76752. srcKey = (ecc_key*)ecKey->internal;
  76753. }
  76754. if (dupKey != NULL) {
  76755. destKey = (ecc_key*)dupKey->internal;
  76756. }
  76757. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  76758. /* compare EC_GROUP */
  76759. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  76760. /* compare EC_POINT */
  76761. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  76762. dupKey->pub_key, NULL), MP_EQ);
  76763. /* compare BIGNUM */
  76764. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  76765. wolfSSL_EC_KEY_free(dupKey);
  76766. dupKey = NULL;
  76767. /* Invalid cases */
  76768. /* NULL key */
  76769. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  76770. /* NULL ecc_key */
  76771. if (ecKey != NULL) {
  76772. wc_ecc_free((ecc_key*)ecKey->internal);
  76773. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  76774. ecKey->internal = NULL; /* Set ecc_key to NULL */
  76775. }
  76776. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76777. wolfSSL_EC_KEY_free(ecKey);
  76778. ecKey = NULL;
  76779. wolfSSL_EC_KEY_free(dupKey);
  76780. dupKey = NULL;
  76781. /* NULL Group */
  76782. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76783. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76784. if (ecKey != NULL) {
  76785. wolfSSL_EC_GROUP_free(ecKey->group);
  76786. ecKey->group = NULL; /* Set group to NULL */
  76787. }
  76788. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76789. wolfSSL_EC_KEY_free(ecKey);
  76790. ecKey = NULL;
  76791. wolfSSL_EC_KEY_free(dupKey);
  76792. dupKey = NULL;
  76793. /* NULL public key */
  76794. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76795. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76796. if (ecKey != NULL) {
  76797. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  76798. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  76799. }
  76800. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76801. if (ecKey != NULL) {
  76802. wolfSSL_EC_POINT_free(ecKey->pub_key);
  76803. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  76804. }
  76805. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76806. wolfSSL_EC_KEY_free(ecKey);
  76807. ecKey = NULL;
  76808. wolfSSL_EC_KEY_free(dupKey);
  76809. dupKey = NULL;
  76810. /* NULL private key */
  76811. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76812. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  76813. if (ecKey != NULL) {
  76814. wolfSSL_BN_free(ecKey->priv_key);
  76815. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  76816. }
  76817. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76818. wolfSSL_EC_KEY_free(ecKey);
  76819. ecKey = NULL;
  76820. wolfSSL_EC_KEY_free(dupKey);
  76821. dupKey = NULL;
  76822. /* Test EC_KEY_up_ref */
  76823. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  76824. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  76825. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76826. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  76827. /* reference count doesn't follow duplicate */
  76828. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  76829. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  76830. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  76831. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  76832. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  76833. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  76834. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  76835. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  76836. #endif
  76837. return EXPECT_RESULT();
  76838. }
  76839. static int test_wolfSSL_EC_KEY_set_group(void)
  76840. {
  76841. EXPECT_DECLS;
  76842. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  76843. defined(OPENSSL_EXTRA)
  76844. EC_KEY *key = NULL;
  76845. EC_GROUP *group = NULL;
  76846. const EC_GROUP *group2 = NULL;
  76847. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76848. ExpectNotNull(key = EC_KEY_new());
  76849. ExpectNull(EC_KEY_get0_group(NULL));
  76850. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  76851. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  76852. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  76853. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  76854. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  76855. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  76856. EC_GROUP_free(group);
  76857. EC_KEY_free(key);
  76858. #endif
  76859. return EXPECT_RESULT();
  76860. }
  76861. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  76862. {
  76863. EXPECT_DECLS;
  76864. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76865. BIO* bio = NULL;
  76866. EC_KEY* key = NULL;
  76867. /* Error condition: NULL key. */
  76868. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  76869. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  76870. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  76871. /* Conversion form defaults to uncompressed. */
  76872. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76873. #ifdef HAVE_COMP_KEY
  76874. /* Explicitly set to compressed. */
  76875. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  76876. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  76877. #else
  76878. /* Will still work just won't change anything. */
  76879. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  76880. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76881. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  76882. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  76883. #endif
  76884. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  76885. BIO_free(bio);
  76886. EC_KEY_free(key);
  76887. #endif
  76888. return EXPECT_RESULT();
  76889. }
  76890. static int test_wolfSSL_EC_KEY_private_key(void)
  76891. {
  76892. EXPECT_DECLS;
  76893. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76894. WOLFSSL_EC_KEY* key = NULL;
  76895. WOLFSSL_BIGNUM* priv = NULL;
  76896. WOLFSSL_BIGNUM* priv2 = NULL;
  76897. WOLFSSL_BIGNUM* bn;
  76898. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76899. ExpectNotNull(priv = wolfSSL_BN_new());
  76900. ExpectNotNull(priv2 = wolfSSL_BN_new());
  76901. ExpectIntNE(BN_set_word(priv, 2), 0);
  76902. ExpectIntNE(BN_set_word(priv2, 2), 0);
  76903. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  76904. /* No private key set. */
  76905. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  76906. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  76907. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  76908. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  76909. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  76910. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  76911. ExpectPtrNE(bn, priv);
  76912. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  76913. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  76914. ExpectPtrNE(bn, priv2);
  76915. wolfSSL_BN_free(priv2);
  76916. wolfSSL_BN_free(priv);
  76917. wolfSSL_EC_KEY_free(key);
  76918. #endif
  76919. return EXPECT_RESULT();
  76920. }
  76921. static int test_wolfSSL_EC_KEY_public_key(void)
  76922. {
  76923. EXPECT_DECLS;
  76924. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76925. WOLFSSL_EC_KEY* key = NULL;
  76926. WOLFSSL_EC_POINT* pub = NULL;
  76927. WOLFSSL_EC_POINT* point = NULL;
  76928. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76929. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  76930. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  76931. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76932. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  76933. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  76934. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  76935. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  76936. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  76937. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  76938. ExpectPtrEq(point, pub);
  76939. wolfSSL_EC_KEY_free(key);
  76940. #endif
  76941. return EXPECT_RESULT();
  76942. }
  76943. static int test_wolfSSL_EC_KEY_print_fp(void)
  76944. {
  76945. EXPECT_DECLS;
  76946. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  76947. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  76948. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  76949. !defined(NO_STDIO_FILESYSTEM)
  76950. EC_KEY* key = NULL;
  76951. /* Bad file pointer. */
  76952. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76953. /* NULL key. */
  76954. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76955. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  76956. /* Negative indent. */
  76957. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76958. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76959. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  76960. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76961. wolfSSL_EC_KEY_free(key);
  76962. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  76963. NID_X9_62_prime256v1)));
  76964. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  76965. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  76966. wolfSSL_EC_KEY_free(key);
  76967. #endif
  76968. return EXPECT_RESULT();
  76969. }
  76970. static int test_wolfSSL_EC_get_builtin_curves(void)
  76971. {
  76972. EXPECT_DECLS;
  76973. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  76974. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76975. EC_builtin_curve* curves = NULL;
  76976. size_t crv_len = 0;
  76977. size_t i = 0;
  76978. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  76979. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  76980. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  76981. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  76982. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  76983. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  76984. if (curves[i].comment != NULL) {
  76985. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  76986. }
  76987. }
  76988. if (crv_len > 1) {
  76989. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  76990. }
  76991. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76992. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76993. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  76994. return EXPECT_RESULT();
  76995. }
  76996. static int test_wolfSSL_ECDSA_SIG(void)
  76997. {
  76998. EXPECT_DECLS;
  76999. #ifdef OPENSSL_EXTRA
  77000. WOLFSSL_ECDSA_SIG* sig = NULL;
  77001. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  77002. WOLFSSL_BIGNUM* r = NULL;
  77003. WOLFSSL_BIGNUM* s = NULL;
  77004. const WOLFSSL_BIGNUM* r2 = NULL;
  77005. const WOLFSSL_BIGNUM* s2 = NULL;
  77006. const unsigned char* cp = NULL;
  77007. unsigned char* p = NULL;
  77008. unsigned char outSig[8];
  77009. unsigned char sigData[8] =
  77010. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77011. unsigned char sigDataBad[8] =
  77012. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77013. wolfSSL_ECDSA_SIG_free(NULL);
  77014. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  77015. ExpectNotNull(r = wolfSSL_BN_new());
  77016. ExpectNotNull(s = wolfSSL_BN_new());
  77017. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  77018. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  77019. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  77020. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  77021. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  77022. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77023. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  77024. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  77025. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  77026. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  77027. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  77028. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  77029. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  77030. r2 = NULL;
  77031. s2 = NULL;
  77032. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77033. ExpectNull(r2);
  77034. ExpectNull(s2);
  77035. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  77036. if (EXPECT_FAIL()) {
  77037. wolfSSL_BN_free(r);
  77038. wolfSSL_BN_free(s);
  77039. }
  77040. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  77041. ExpectPtrEq(r2, r);
  77042. ExpectPtrEq(s2, s);
  77043. r2 = NULL;
  77044. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  77045. ExpectPtrEq(r2, r);
  77046. s2 = NULL;
  77047. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  77048. ExpectPtrEq(s2, s);
  77049. /* r and s are freed when sig is freed. */
  77050. wolfSSL_ECDSA_SIG_free(sig);
  77051. sig = NULL;
  77052. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  77053. cp = sigDataBad;
  77054. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  77055. cp = sigData;
  77056. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  77057. ExpectIntEQ((cp == sigData + 8), 1);
  77058. cp = sigData;
  77059. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  77060. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  77061. ExpectIntEQ((sig == sig2), 1);
  77062. cp = outSig;
  77063. p = outSig;
  77064. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  77065. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  77066. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  77067. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  77068. ExpectIntEQ((p == outSig + 8), 1);
  77069. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  77070. p = NULL;
  77071. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  77072. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  77073. ExpectNull(p);
  77074. #else
  77075. ExpectNotNull(p);
  77076. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  77077. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  77078. #endif
  77079. wolfSSL_ECDSA_SIG_free(sig);
  77080. #endif
  77081. return EXPECT_RESULT();
  77082. }
  77083. static int test_ECDSA_size_sign(void)
  77084. {
  77085. EXPECT_DECLS;
  77086. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  77087. EC_KEY* key = NULL;
  77088. ECDSA_SIG* ecdsaSig = NULL;
  77089. int id;
  77090. byte hash[WC_MAX_DIGEST_SIZE];
  77091. byte hash2[WC_MAX_DIGEST_SIZE];
  77092. byte sig[ECC_MAX_SIG_SIZE];
  77093. unsigned int sigSz = sizeof(sig);
  77094. XMEMSET(hash, 123, sizeof(hash));
  77095. XMEMSET(hash2, 234, sizeof(hash2));
  77096. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  77097. ExpectIntEQ(id, ECC_SECP256R1);
  77098. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77099. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  77100. ExpectIntGE(ECDSA_size(NULL), 0);
  77101. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  77102. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  77103. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  77104. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  77105. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  77106. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  77107. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  77108. ExpectIntGE(ECDSA_size(key), sigSz);
  77109. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  77110. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  77111. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  77112. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  77113. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  77114. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  77115. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  77116. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  77117. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  77118. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  77119. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  77120. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  77121. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  77122. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  77123. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  77124. ECDSA_SIG_free(ecdsaSig);
  77125. EC_KEY_free(key);
  77126. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  77127. return EXPECT_RESULT();
  77128. }
  77129. static int test_ECDH_compute_key(void)
  77130. {
  77131. EXPECT_DECLS;
  77132. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77133. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77134. EC_KEY* key1 = NULL;
  77135. EC_KEY* key2 = NULL;
  77136. EC_POINT* pub1 = NULL;
  77137. EC_POINT* pub2 = NULL;
  77138. byte secret1[32];
  77139. byte secret2[32];
  77140. int i;
  77141. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77142. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  77143. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  77144. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77145. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  77146. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  77147. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  77148. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  77149. 0);
  77150. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  77151. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  77152. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  77153. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  77154. 0);
  77155. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  77156. 0);
  77157. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  77158. NULL), 0);
  77159. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  77160. sizeof(secret1));
  77161. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  77162. sizeof(secret2));
  77163. for (i = 0; i < (int)sizeof(secret1); i++) {
  77164. ExpectIntEQ(secret1[i], secret2[i]);
  77165. }
  77166. EC_KEY_free(key2);
  77167. EC_KEY_free(key1);
  77168. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  77169. * !WOLF_CRYPTO_CB_ONLY_ECC */
  77170. return EXPECT_RESULT();
  77171. }
  77172. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  77173. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  77174. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  77175. !defined(NO_ASN_TIME)
  77176. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  77177. int expectedDerSz)
  77178. {
  77179. EXPECT_DECLS;
  77180. X509* x509 = NULL;
  77181. BIGNUM* serial_number = NULL;
  77182. X509_NAME* name = NULL;
  77183. time_t epoch_off = 0;
  77184. ASN1_INTEGER* asn1_serial_number;
  77185. long not_before, not_after;
  77186. int derSz;
  77187. ExpectNotNull(x509 = X509_new());
  77188. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  77189. ExpectNotNull(serial_number = BN_new());
  77190. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  77191. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  77192. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  77193. /* version 3 */
  77194. ExpectIntNE(X509_set_version(x509, 2L), 0);
  77195. ExpectNotNull(name = X509_NAME_new());
  77196. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  77197. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  77198. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  77199. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  77200. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  77201. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  77202. not_before = (long)wc_Time(NULL);
  77203. not_after = not_before + (365 * 24 * 60 * 60);
  77204. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  77205. &epoch_off));
  77206. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  77207. &epoch_off));
  77208. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  77209. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  77210. ExpectIntGE(derSz, expectedDerSz);
  77211. BN_free(serial_number);
  77212. X509_NAME_free(name);
  77213. X509_free(x509);
  77214. return EXPECT_RESULT();
  77215. }
  77216. #endif
  77217. static int test_openssl_generate_key_and_cert(void)
  77218. {
  77219. EXPECT_DECLS;
  77220. #if defined(OPENSSL_EXTRA)
  77221. int expectedDerSz;
  77222. EVP_PKEY* pkey = NULL;
  77223. #ifdef HAVE_ECC
  77224. EC_KEY* ec_key = NULL;
  77225. #endif
  77226. #if !defined(NO_RSA)
  77227. int key_length = 2048;
  77228. BIGNUM* exponent = NULL;
  77229. RSA* rsa = NULL;
  77230. ExpectNotNull(pkey = EVP_PKEY_new());
  77231. ExpectNotNull(exponent = BN_new());
  77232. ExpectNotNull(rsa = RSA_new());
  77233. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  77234. #ifndef WOLFSSL_KEY_GEN
  77235. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77236. #if defined(USE_CERT_BUFFERS_1024)
  77237. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  77238. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77239. key_length = 1024;
  77240. #elif defined(USE_CERT_BUFFERS_2048)
  77241. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  77242. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77243. #else
  77244. RSA_free(rsa);
  77245. rsa = NULL;
  77246. #endif
  77247. #else
  77248. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  77249. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  77250. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  77251. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77252. #endif
  77253. if (rsa) {
  77254. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  77255. if (EXPECT_FAIL()) {
  77256. RSA_free(rsa);
  77257. }
  77258. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77259. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77260. expectedDerSz = 743;
  77261. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  77262. expectedDerSz), TEST_SUCCESS);
  77263. #endif
  77264. }
  77265. EVP_PKEY_free(pkey);
  77266. pkey = NULL;
  77267. BN_free(exponent);
  77268. #endif /* !NO_RSA */
  77269. #ifdef HAVE_ECC
  77270. ExpectNotNull(pkey = EVP_PKEY_new());
  77271. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77272. #ifndef NO_WOLFSSL_STUB
  77273. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  77274. #endif
  77275. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  77276. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  77277. if (EXPECT_FAIL()) {
  77278. EC_KEY_free(ec_key);
  77279. }
  77280. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77281. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77282. expectedDerSz = 344;
  77283. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  77284. TEST_SUCCESS);
  77285. #endif
  77286. EVP_PKEY_free(pkey);
  77287. #endif /* HAVE_ECC */
  77288. (void)pkey;
  77289. (void)expectedDerSz;
  77290. #endif /* OPENSSL_EXTRA */
  77291. return EXPECT_RESULT();
  77292. }
  77293. static int test_stubs_are_stubs(void)
  77294. {
  77295. EXPECT_DECLS;
  77296. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  77297. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77298. WOLFSSL_CTX* ctx = NULL;
  77299. WOLFSSL_CTX* ctxN = NULL;
  77300. #ifndef NO_WOLFSSL_CLIENT
  77301. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77302. #elif !defined(NO_WOLFSSL_SERVER)
  77303. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  77304. #endif
  77305. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  77306. ExpectIntEQ((int) x(z), 0)
  77307. /* test logic, all stubs return same result regardless of ctx being NULL
  77308. * as there are no sanity checks, it's just a stub! If at some
  77309. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  77310. * if invalid inputs are supplied. Test calling both
  77311. * with and without valid inputs, if a stub functionality remains unchanged.
  77312. */
  77313. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  77314. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  77315. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  77316. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  77317. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  77318. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  77319. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  77320. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  77321. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  77322. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  77323. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  77324. /* when implemented this should take WOLFSSL object instead, right now
  77325. * always returns 0 */
  77326. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77327. wolfSSL_CTX_free(ctx);
  77328. ctx = NULL;
  77329. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  77330. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77331. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  77332. * !NO_WOLFSSL_SERVER) */
  77333. return EXPECT_RESULT();
  77334. }
  77335. static int test_CONF_modules_xxx(void)
  77336. {
  77337. int res = TEST_SKIPPED;
  77338. #if defined(OPENSSL_EXTRA)
  77339. CONF_modules_free();
  77340. CONF_modules_unload(0);
  77341. CONF_modules_unload(1);
  77342. CONF_modules_unload(-1);
  77343. res = TEST_SUCCESS;
  77344. #endif /* OPENSSL_EXTRA */
  77345. return res;
  77346. }
  77347. static int test_CRYPTO_set_dynlock_xxx(void)
  77348. {
  77349. int res = TEST_SKIPPED;
  77350. #if defined(OPENSSL_EXTRA)
  77351. CRYPTO_set_dynlock_create_callback(
  77352. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  77353. CRYPTO_set_dynlock_create_callback(
  77354. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  77355. CRYPTO_set_dynlock_destroy_callback(
  77356. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  77357. CRYPTO_set_dynlock_destroy_callback(
  77358. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  77359. CRYPTO_set_dynlock_lock_callback(
  77360. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  77361. CRYPTO_set_dynlock_lock_callback(
  77362. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  77363. res = TEST_SUCCESS;
  77364. #endif /* OPENSSL_EXTRA */
  77365. return res;
  77366. }
  77367. static int test_CRYPTO_THREADID_xxx(void)
  77368. {
  77369. EXPECT_DECLS;
  77370. #if defined(OPENSSL_EXTRA)
  77371. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  77372. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  77373. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  77374. #endif /* OPENSSL_EXTRA */
  77375. return EXPECT_RESULT();
  77376. }
  77377. static int test_ENGINE_cleanup(void)
  77378. {
  77379. int res = TEST_SKIPPED;
  77380. #if defined(OPENSSL_EXTRA)
  77381. ENGINE_cleanup();
  77382. res = TEST_SUCCESS;
  77383. #endif /* OPENSSL_EXTRA */
  77384. return res;
  77385. }
  77386. static int test_wolfSSL_CTX_LoadCRL(void)
  77387. {
  77388. EXPECT_DECLS;
  77389. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  77390. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77391. WOLFSSL_CTX* ctx = NULL;
  77392. WOLFSSL* ssl = NULL;
  77393. const char* badPath = "dummypath";
  77394. const char* validPath = "./certs/crl";
  77395. const char* validFilePath = "./certs/crl/cliCrl.pem";
  77396. const char* issuerCert = "./certs/client-cert.pem";
  77397. int derType = WOLFSSL_FILETYPE_ASN1;
  77398. int pemType = WOLFSSL_FILETYPE_PEM;
  77399. #ifdef HAVE_CRL_MONITOR
  77400. int monitor = WOLFSSL_CRL_MONITOR;
  77401. #else
  77402. int monitor = 0;
  77403. #endif
  77404. WOLFSSL_CERT_MANAGER* cm = NULL;
  77405. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77406. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  77407. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77408. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  77409. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77410. WOLFSSL_SUCCESS)
  77411. #ifndef NO_WOLFSSL_CLIENT
  77412. #define NEW_CTX(ctx) ExpectNotNull( \
  77413. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  77414. #elif !defined(NO_WOLFSSL_SERVER)
  77415. #define NEW_CTX(ctx) ExpectNotNull( \
  77416. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  77417. #else
  77418. #define NEW_CTX(ctx) return
  77419. #endif
  77420. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77421. NEW_CTX(ctx);
  77422. #ifndef HAVE_CRL_MONITOR
  77423. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  77424. wolfSSL_CTX_free(ctx);
  77425. NEW_CTX(ctx);
  77426. #endif
  77427. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77428. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  77429. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  77430. wolfSSL_CTX_free(ctx);
  77431. ctx = NULL;
  77432. NEW_CTX(ctx);
  77433. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77434. WOLFSSL_SUCCESS);
  77435. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  77436. wolfSSL_CTX_free(ctx);
  77437. ctx = NULL;
  77438. NEW_CTX(ctx);
  77439. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77440. WOLFSSL_SUCCESS);
  77441. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77442. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  77443. wolfSSL_free(ssl);
  77444. ssl = NULL;
  77445. wolfSSL_CTX_free(ctx);
  77446. ctx = NULL;
  77447. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  77448. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  77449. WOLFSSL_SUCCESS);
  77450. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  77451. WOLFSSL_SUCCESS);
  77452. wolfSSL_CertManagerFree(cm);
  77453. #endif
  77454. return EXPECT_RESULT();
  77455. }
  77456. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77457. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77458. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  77459. {
  77460. EXPECT_DECLS;
  77461. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  77462. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  77463. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  77464. return EXPECT_RESULT();
  77465. }
  77466. #endif
  77467. static int test_multiple_crls_same_issuer(void)
  77468. {
  77469. EXPECT_DECLS;
  77470. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77471. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77472. test_ssl_cbf client_cbs, server_cbs;
  77473. struct {
  77474. const char* server_cert;
  77475. const char* server_key;
  77476. } test_params[] = {
  77477. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  77478. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  77479. };
  77480. size_t i;
  77481. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  77482. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77483. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77484. server_cbs.certPemFile = test_params[i].server_cert;
  77485. server_cbs.keyPemFile = test_params[i].server_key;
  77486. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  77487. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  77488. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  77489. &server_cbs, NULL), TEST_FAIL);
  77490. }
  77491. #endif
  77492. return EXPECT_RESULT();
  77493. }
  77494. static int test_SetTmpEC_DHE_Sz(void)
  77495. {
  77496. EXPECT_DECLS;
  77497. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  77498. WOLFSSL_CTX *ctx = NULL;
  77499. WOLFSSL *ssl = NULL;
  77500. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77501. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  77502. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77503. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  77504. wolfSSL_free(ssl);
  77505. wolfSSL_CTX_free(ctx);
  77506. #endif
  77507. return EXPECT_RESULT();
  77508. }
  77509. static int test_wolfSSL_CTX_get0_privatekey(void)
  77510. {
  77511. EXPECT_DECLS;
  77512. #ifdef OPENSSL_ALL
  77513. WOLFSSL_CTX* ctx = NULL;
  77514. (void)ctx;
  77515. #ifndef NO_RSA
  77516. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77517. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77518. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  77519. WOLFSSL_FILETYPE_PEM));
  77520. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77521. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  77522. WOLFSSL_FILETYPE_PEM));
  77523. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77524. wolfSSL_CTX_free(ctx);
  77525. ctx = NULL;
  77526. #endif
  77527. #ifdef HAVE_ECC
  77528. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77529. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77530. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  77531. WOLFSSL_FILETYPE_PEM));
  77532. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77533. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  77534. WOLFSSL_FILETYPE_PEM));
  77535. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77536. wolfSSL_CTX_free(ctx);
  77537. #endif
  77538. #endif
  77539. return EXPECT_RESULT();
  77540. }
  77541. static int test_wolfSSL_dtls_set_mtu(void)
  77542. {
  77543. EXPECT_DECLS;
  77544. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  77545. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  77546. !defined(WOLFSSL_NO_TLS12)
  77547. WOLFSSL_CTX* ctx = NULL;
  77548. WOLFSSL* ssl = NULL;
  77549. const char* testCertFile;
  77550. const char* testKeyFile;
  77551. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  77552. #ifndef NO_RSA
  77553. testCertFile = svrCertFile;
  77554. testKeyFile = svrKeyFile;
  77555. #elif defined(HAVE_ECC)
  77556. testCertFile = eccCertFile;
  77557. testKeyFile = eccKeyFile;
  77558. #endif
  77559. if (testCertFile != NULL && testKeyFile != NULL) {
  77560. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  77561. WOLFSSL_FILETYPE_PEM));
  77562. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  77563. WOLFSSL_FILETYPE_PEM));
  77564. }
  77565. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77566. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77567. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77568. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77569. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77570. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77571. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  77572. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  77573. wolfSSL_free(ssl);
  77574. wolfSSL_CTX_free(ctx);
  77575. #endif
  77576. return EXPECT_RESULT();
  77577. }
  77578. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77579. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77580. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  77581. enum HandShakeType hsType, word16 length)
  77582. {
  77583. size_t idx = 0;
  77584. byte* l;
  77585. /* record layer */
  77586. /* handshake type */
  77587. out[idx++] = handshake;
  77588. /* protocol version */
  77589. out[idx++] = 0xfe;
  77590. out[idx++] = 0xfd; /* DTLS 1.2 */
  77591. /* epoch 0 */
  77592. XMEMSET(out + idx, 0, 2);
  77593. idx += 2;
  77594. /* sequence number */
  77595. XMEMSET(out + idx, 0, 6);
  77596. c32toa(seq, out + idx + 2);
  77597. idx += 6;
  77598. /* length in BE */
  77599. if (length)
  77600. c16toa(length, out + idx);
  77601. else
  77602. c16toa(outSz - idx - 2, out + idx);
  77603. idx += 2;
  77604. /* handshake layer */
  77605. /* handshake type */
  77606. out[idx++] = (byte)hsType;
  77607. /* length */
  77608. l = out + idx;
  77609. idx += 3;
  77610. /* message seq */
  77611. c16toa(0, out + idx);
  77612. idx += 2;
  77613. /* frag offset */
  77614. c32to24(0, out + idx);
  77615. idx += 3;
  77616. /* frag length */
  77617. c32to24((word32)outSz - (word32)idx - 3, l);
  77618. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  77619. idx += 3;
  77620. XMEMSET(out + idx, 0, outSz - idx);
  77621. }
  77622. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  77623. {
  77624. byte msg[] = "This is a msg for the client";
  77625. byte reply[40];
  77626. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77627. reply[sizeof(reply) - 1] = '\0';
  77628. fprintf(stderr, "Client message: %s\n", reply);
  77629. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77630. }
  77631. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  77632. {
  77633. byte ch[50];
  77634. int fd = wolfSSL_get_fd(ssl);
  77635. byte msg[] = "This is a msg for the server";
  77636. byte reply[40];
  77637. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  77638. /* Server should ignore this datagram */
  77639. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77640. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  77641. /* Server should ignore this datagram */
  77642. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77643. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77644. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77645. reply[sizeof(reply) - 1] = '\0';
  77646. fprintf(stderr, "Server response: %s\n", reply);
  77647. }
  77648. static int test_wolfSSL_dtls_plaintext(void)
  77649. {
  77650. callback_functions func_cb_client;
  77651. callback_functions func_cb_server;
  77652. size_t i;
  77653. struct test_params {
  77654. method_provider client_meth;
  77655. method_provider server_meth;
  77656. ssl_callback on_result_server;
  77657. ssl_callback on_result_client;
  77658. } params[] = {
  77659. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77660. test_wolfSSL_dtls_plaintext_server,
  77661. test_wolfSSL_dtls_plaintext_client},
  77662. };
  77663. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77664. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77665. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77666. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77667. func_cb_server.method = params[i].server_meth;
  77668. func_cb_client.method = params[i].client_meth;
  77669. func_cb_client.on_result = params[i].on_result_client;
  77670. func_cb_server.on_result = params[i].on_result_server;
  77671. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77672. if (!func_cb_client.return_code)
  77673. return TEST_FAIL;
  77674. if (!func_cb_server.return_code)
  77675. return TEST_FAIL;
  77676. }
  77677. return TEST_RES_CHECK(1);
  77678. }
  77679. #else
  77680. static int test_wolfSSL_dtls_plaintext(void) {
  77681. return TEST_SKIPPED;
  77682. }
  77683. #endif
  77684. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77685. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77686. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  77687. {
  77688. byte b[1100]; /* buffer for the messages to send */
  77689. size_t idx = 0;
  77690. size_t seq_offset = 0;
  77691. size_t msg_offset = 0;
  77692. int i;
  77693. int fd = wolfSSL_get_fd(ssl);
  77694. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77695. word32 seq_number = 100; /* start high so server definitely reads this */
  77696. word16 msg_number = 50; /* start high so server has to buffer this */
  77697. AssertIntEQ(ret, 1);
  77698. /* Now let's start spamming the peer with fragments it needs to store */
  77699. XMEMSET(b, -1, sizeof(b));
  77700. /* record layer */
  77701. /* handshake type */
  77702. b[idx++] = 22;
  77703. /* protocol version */
  77704. b[idx++] = 0xfe;
  77705. b[idx++] = 0xfd; /* DTLS 1.2 */
  77706. /* epoch 0 */
  77707. XMEMSET(b + idx, 0, 2);
  77708. idx += 2;
  77709. /* sequence number */
  77710. XMEMSET(b + idx, 0, 6);
  77711. seq_offset = idx + 2; /* increment only the low 32 bits */
  77712. idx += 6;
  77713. /* static length in BE */
  77714. c16toa(42, b + idx);
  77715. idx += 2;
  77716. /* handshake layer */
  77717. /* cert type */
  77718. b[idx++] = 11;
  77719. /* length */
  77720. c32to24(1000, b + idx);
  77721. idx += 3;
  77722. /* message seq */
  77723. c16toa(0, b + idx);
  77724. msg_offset = idx;
  77725. idx += 2;
  77726. /* frag offset */
  77727. c32to24(500, b + idx);
  77728. idx += 3;
  77729. /* frag length */
  77730. c32to24(30, b + idx);
  77731. idx += 3;
  77732. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  77733. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  77734. seq_number++, msg_number++, i++) {
  77735. struct timespec delay;
  77736. XMEMSET(&delay, 0, sizeof(delay));
  77737. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  77738. c32toa(seq_number, b + seq_offset);
  77739. c16toa(msg_number, b + msg_offset);
  77740. ret = (int)send(fd, b, 55, 0);
  77741. nanosleep(&delay, NULL);
  77742. }
  77743. }
  77744. #ifdef WOLFSSL_DTLS13
  77745. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  77746. {
  77747. const word16 sendCountMax = 100;
  77748. byte b[150]; /* buffer for the messages to send */
  77749. size_t idx = 0;
  77750. size_t msg_offset = 0;
  77751. int fd = wolfSSL_get_fd(ssl);
  77752. word16 msg_number = 10; /* start high so server has to buffer this */
  77753. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77754. AssertIntEQ(ret, 1);
  77755. /* Now let's start spamming the peer with fragments it needs to store */
  77756. XMEMSET(b, -1, sizeof(b));
  77757. /* handshake type */
  77758. b[idx++] = 11;
  77759. /* length */
  77760. c32to24(10000, b + idx);
  77761. idx += 3;
  77762. /* message_seq */
  77763. msg_offset = idx;
  77764. idx += 2;
  77765. /* fragment_offset */
  77766. c32to24(5000, b + idx);
  77767. idx += 3;
  77768. /* fragment_length */
  77769. c32to24(100, b + idx);
  77770. idx += 3;
  77771. /* fragment contents */
  77772. idx += 100;
  77773. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  77774. byte sendBuf[150];
  77775. int sendSz = sizeof(sendBuf);
  77776. struct timespec delay;
  77777. XMEMSET(&delay, 0, sizeof(delay));
  77778. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  77779. c16toa(msg_number, b + msg_offset);
  77780. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  77781. (int)idx, handshake, 0, 0, 0);
  77782. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  77783. nanosleep(&delay, NULL);
  77784. }
  77785. }
  77786. #endif
  77787. static int test_wolfSSL_dtls_fragments(void)
  77788. {
  77789. EXPECT_DECLS;
  77790. callback_functions func_cb_client;
  77791. callback_functions func_cb_server;
  77792. size_t i;
  77793. struct test_params {
  77794. method_provider client_meth;
  77795. method_provider server_meth;
  77796. ssl_callback spammer;
  77797. } params[] = {
  77798. #if !defined(WOLFSSL_NO_TLS12)
  77799. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77800. test_wolfSSL_dtls12_fragments_spammer},
  77801. #endif
  77802. #ifdef WOLFSSL_DTLS13
  77803. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  77804. test_wolfSSL_dtls13_fragments_spammer},
  77805. #endif
  77806. };
  77807. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77808. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77809. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77810. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77811. func_cb_server.method = params[i].server_meth;
  77812. func_cb_client.method = params[i].client_meth;
  77813. func_cb_client.ssl_ready = params[i].spammer;
  77814. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77815. ExpectFalse(func_cb_client.return_code);
  77816. ExpectFalse(func_cb_server.return_code);
  77817. /* The socket should be closed by the server resulting in a
  77818. * socket error, fatal error or reading a close notify alert */
  77819. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  77820. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  77821. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  77822. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  77823. }
  77824. /* Check the server returned an error indicating the msg buffer
  77825. * was full */
  77826. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  77827. if (EXPECT_FAIL())
  77828. break;
  77829. }
  77830. return EXPECT_RESULT();
  77831. }
  77832. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  77833. {
  77834. int fd, ret;
  77835. byte alert_msg[] = {
  77836. 0x15, /* alert type */
  77837. 0xfe, 0xfd, /* version */
  77838. 0x00, 0x00, /* epoch */
  77839. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  77840. 0x00, 0x02, /* length */
  77841. 0x02, /* level: fatal */
  77842. 0x46 /* protocol version */
  77843. };
  77844. fd = wolfSSL_get_fd(ssl);
  77845. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  77846. AssertIntGT(ret, 0);
  77847. }
  77848. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  77849. {
  77850. callback_functions client_cbs, server_cbs;
  77851. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77852. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77853. client_cbs.doUdp = server_cbs.doUdp = 1;
  77854. if (version12) {
  77855. #if !defined(WOLFSSL_NO_TLS12)
  77856. client_cbs.method = wolfDTLSv1_2_client_method;
  77857. server_cbs.method = wolfDTLSv1_2_server_method;
  77858. #else
  77859. return TEST_SKIPPED;
  77860. #endif
  77861. }
  77862. else
  77863. {
  77864. #ifdef WOLFSSL_DTLS13
  77865. client_cbs.method = wolfDTLSv1_3_client_method;
  77866. server_cbs.method = wolfDTLSv1_3_server_method;
  77867. #else
  77868. return TEST_SKIPPED;
  77869. #endif /* WOLFSSL_DTLS13 */
  77870. }
  77871. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  77872. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  77873. if (!client_cbs.return_code)
  77874. return TEST_FAIL;
  77875. if (!server_cbs.return_code)
  77876. return TEST_FAIL;
  77877. return TEST_SUCCESS;
  77878. }
  77879. static int test_wolfSSL_ignore_alert_before_cookie(void)
  77880. {
  77881. int ret;
  77882. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  77883. if (ret != 0)
  77884. return ret;
  77885. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  77886. if (ret != 0)
  77887. return ret;
  77888. return 0;
  77889. }
  77890. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  77891. {
  77892. int ret;
  77893. int fd;
  77894. byte bad_msg[] = {
  77895. 0x17, /* app data */
  77896. 0xaa, 0xfd, /* bad version */
  77897. 0x00, 0x01, /* epoch 1 */
  77898. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  77899. 0x00, 0x26, /* length: 38 bytes */
  77900. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  77901. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  77902. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  77903. 0x03, 0x18, 0x72
  77904. };
  77905. fd = wolfSSL_get_fd(ssl);
  77906. AssertIntGE(fd, 0);
  77907. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  77908. AssertIntEQ(ret, sizeof(bad_msg));
  77909. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  77910. AssertIntEQ(ret, sizeof("badrecordtest"));
  77911. }
  77912. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  77913. {
  77914. byte buf[100];
  77915. int ret;
  77916. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  77917. AssertIntGT(ret, 0);
  77918. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  77919. }
  77920. static int _test_wolfSSL_dtls_bad_record(
  77921. method_provider client_method, method_provider server_method)
  77922. {
  77923. callback_functions client_cbs, server_cbs;
  77924. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77925. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77926. client_cbs.doUdp = server_cbs.doUdp = 1;
  77927. client_cbs.method = client_method;
  77928. server_cbs.method = server_method;
  77929. client_cbs.on_result = test_wolfSSL_send_bad_record;
  77930. server_cbs.on_result = test_wolfSSL_read_string;
  77931. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  77932. if (!client_cbs.return_code)
  77933. return TEST_FAIL;
  77934. if (!server_cbs.return_code)
  77935. return TEST_FAIL;
  77936. return TEST_SUCCESS;
  77937. }
  77938. static int test_wolfSSL_dtls_bad_record(void)
  77939. {
  77940. int ret = TEST_SUCCESS;
  77941. #if !defined(WOLFSSL_NO_TLS12)
  77942. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  77943. wolfDTLSv1_2_server_method);
  77944. #endif
  77945. #ifdef WOLFSSL_DTLS13
  77946. if (ret == TEST_SUCCESS) {
  77947. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  77948. wolfDTLSv1_3_server_method);
  77949. }
  77950. #endif /* WOLFSSL_DTLS13 */
  77951. return ret;
  77952. }
  77953. #else
  77954. static int test_wolfSSL_dtls_fragments(void) {
  77955. return TEST_SKIPPED;
  77956. }
  77957. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  77958. return TEST_SKIPPED;
  77959. }
  77960. static int test_wolfSSL_dtls_bad_record(void) {
  77961. return TEST_SKIPPED;
  77962. }
  77963. #endif
  77964. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  77965. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  77966. defined(HAVE_IO_TESTS_DEPENDENCIES)
  77967. static byte test_AEAD_fail_decryption = 0;
  77968. static byte test_AEAD_seq_num = 0;
  77969. static byte test_AEAD_done = 0;
  77970. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  77971. {
  77972. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  77973. if (ret > 0) {
  77974. if (test_AEAD_fail_decryption) {
  77975. /* Modify the packet to trigger a decryption failure */
  77976. buf[ret/2] ^= 0xFF;
  77977. if (test_AEAD_fail_decryption == 1)
  77978. test_AEAD_fail_decryption = 0;
  77979. }
  77980. }
  77981. (void)ctx;
  77982. return ret;
  77983. }
  77984. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  77985. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  77986. {
  77987. if (sendLimit)
  77988. w64Zero(sendLimit);
  77989. switch (ssl->specs.bulk_cipher_algorithm) {
  77990. case wolfssl_aes_gcm:
  77991. if (sendLimit)
  77992. *sendLimit = AEAD_AES_LIMIT;
  77993. FALL_THROUGH;
  77994. case wolfssl_chacha:
  77995. if (hardLimit)
  77996. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  77997. if (keyUpdateLimit)
  77998. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  77999. break;
  78000. case wolfssl_aes_ccm:
  78001. if (sendLimit)
  78002. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  78003. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  78004. if (hardLimit)
  78005. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  78006. if (keyUpdateLimit)
  78007. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  78008. }
  78009. else {
  78010. if (hardLimit)
  78011. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  78012. if (keyUpdateLimit)
  78013. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  78014. }
  78015. break;
  78016. default:
  78017. fprintf(stderr, "Unrecognized bulk cipher");
  78018. AssertFalse(1);
  78019. break;
  78020. }
  78021. }
  78022. static void test_AEAD_limit_client(WOLFSSL* ssl)
  78023. {
  78024. int ret;
  78025. int i;
  78026. int didReKey = 0;
  78027. char msgBuf[20];
  78028. w64wrapper hardLimit;
  78029. w64wrapper keyUpdateLimit;
  78030. w64wrapper counter;
  78031. w64wrapper sendLimit;
  78032. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  78033. w64Zero(&counter);
  78034. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  78035. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  78036. for (i = 0; i < 10; i++) {
  78037. /* Test some failed decryptions */
  78038. test_AEAD_fail_decryption = 1;
  78039. w64Increment(&counter);
  78040. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78041. /* Should succeed since decryption failures are dropped */
  78042. AssertIntGT(ret, 0);
  78043. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  78044. }
  78045. test_AEAD_fail_decryption = 1;
  78046. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  78047. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78048. /* 100 read calls should be enough to complete the key update */
  78049. w64Zero(&counter);
  78050. for (i = 0; i < 100; i++) {
  78051. /* Key update should be sent and negotiated */
  78052. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78053. AssertIntGT(ret, 0);
  78054. /* Epoch after one key update is 4 */
  78055. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  78056. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  78057. didReKey = 1;
  78058. break;
  78059. }
  78060. }
  78061. AssertTrue(didReKey);
  78062. if (!w64IsZero(sendLimit)) {
  78063. /* Test the sending limit for AEAD ciphers */
  78064. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  78065. test_AEAD_seq_num = 1;
  78066. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78067. AssertIntGT(ret, 0);
  78068. didReKey = 0;
  78069. w64Zero(&counter);
  78070. /* 100 read calls should be enough to complete the key update */
  78071. for (i = 0; i < 100; i++) {
  78072. /* Key update should be sent and negotiated */
  78073. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78074. AssertIntGT(ret, 0);
  78075. /* Epoch after another key update is 5 */
  78076. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  78077. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  78078. didReKey = 1;
  78079. break;
  78080. }
  78081. }
  78082. AssertTrue(didReKey);
  78083. }
  78084. test_AEAD_fail_decryption = 2;
  78085. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  78086. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78087. /* Connection should fail with a DECRYPT_ERROR */
  78088. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78089. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78090. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  78091. test_AEAD_done = 1;
  78092. }
  78093. int counter = 0;
  78094. static void test_AEAD_limit_server(WOLFSSL* ssl)
  78095. {
  78096. char msgBuf[] = "Sending data";
  78097. int ret = WOLFSSL_SUCCESS;
  78098. w64wrapper sendLimit;
  78099. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78100. struct timespec delay;
  78101. XMEMSET(&delay, 0, sizeof(delay));
  78102. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  78103. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  78104. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78105. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  78106. while (!test_AEAD_done && ret > 0) {
  78107. counter++;
  78108. if (test_AEAD_seq_num) {
  78109. /* We need to update the seq number so that we can understand the
  78110. * peer. Otherwise we will incorrectly interpret the seq number. */
  78111. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  78112. AssertNotNull(e);
  78113. e->nextPeerSeqNumber = sendLimit;
  78114. test_AEAD_seq_num = 0;
  78115. }
  78116. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78117. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78118. nanosleep(&delay, NULL);
  78119. }
  78120. }
  78121. static int test_wolfSSL_dtls_AEAD_limit(void)
  78122. {
  78123. callback_functions func_cb_client;
  78124. callback_functions func_cb_server;
  78125. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78126. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78127. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78128. func_cb_server.method = wolfDTLSv1_3_server_method;
  78129. func_cb_client.method = wolfDTLSv1_3_client_method;
  78130. func_cb_server.on_result = test_AEAD_limit_server;
  78131. func_cb_client.on_result = test_AEAD_limit_client;
  78132. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78133. if (!func_cb_client.return_code)
  78134. return TEST_FAIL;
  78135. if (!func_cb_server.return_code)
  78136. return TEST_FAIL;
  78137. return TEST_SUCCESS;
  78138. }
  78139. #else
  78140. static int test_wolfSSL_dtls_AEAD_limit(void)
  78141. {
  78142. return TEST_SKIPPED;
  78143. }
  78144. #endif
  78145. #if defined(WOLFSSL_DTLS) && \
  78146. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78147. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  78148. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  78149. {
  78150. int fd, ret;
  78151. byte ch_msg[] = {
  78152. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78153. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78154. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  78155. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  78156. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  78157. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78158. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78159. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78160. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78161. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78162. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78163. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78164. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78165. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  78166. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  78167. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  78168. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  78169. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  78170. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  78171. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  78172. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  78173. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  78174. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  78175. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  78176. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  78177. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  78178. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  78179. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  78180. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  78181. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  78182. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  78183. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  78184. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  78185. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  78186. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  78187. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  78188. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  78189. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  78190. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  78191. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  78192. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  78193. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  78194. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  78195. 0x31, 0x68, 0x4c
  78196. };
  78197. fd = wolfSSL_get_fd(ssl);
  78198. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  78199. AssertIntGT(ret, 0);
  78200. /* consume the HRR otherwise handshake will fail */
  78201. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  78202. AssertIntGT(ret, 0);
  78203. }
  78204. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78205. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  78206. {
  78207. int fd, ret;
  78208. byte ch_msh_invalid_cookie[] = {
  78209. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  78210. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  78211. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  78212. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  78213. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  78214. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78215. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78216. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78217. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78218. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78219. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78220. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78221. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78222. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  78223. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78224. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78225. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78226. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78227. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78228. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  78229. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  78230. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  78231. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  78232. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  78233. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  78234. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  78235. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  78236. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  78237. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  78238. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  78239. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  78240. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  78241. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  78242. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  78243. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  78244. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  78245. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  78246. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  78247. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  78248. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  78249. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  78250. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  78251. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  78252. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  78253. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  78254. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  78255. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  78256. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  78257. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  78258. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  78259. 0x23, 0x00, 0x00
  78260. };
  78261. byte alert_reply[50];
  78262. byte expected_alert_reply[] = {
  78263. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  78264. 0x02, 0x02, 0x2f
  78265. };
  78266. fd = wolfSSL_get_fd(ssl);
  78267. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  78268. AssertIntGT(ret, 0);
  78269. /* should reply with an illegal_parameter reply */
  78270. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  78271. AssertIntEQ(ret, sizeof(expected_alert_reply));
  78272. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  78273. }
  78274. #endif
  78275. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  78276. {
  78277. #ifndef NO_MD5
  78278. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  78279. #elif !defined(NO_SHA)
  78280. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  78281. #elif !defined(NO_SHA256)
  78282. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  78283. #else
  78284. #error "We need a digest to hash the WOLFSSL object"
  78285. #endif
  78286. byte hashBuf[WC_MAX_DIGEST_SIZE];
  78287. wc_HashAlg hash;
  78288. const TLSX* exts = ssl->extensions;
  78289. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  78290. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  78291. * InitHandshakeHashes */
  78292. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  78293. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  78294. /* Following fields are not important to compare */
  78295. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78296. sslCopy.buffers.inputBuffer.buffer = NULL;
  78297. sslCopy.buffers.inputBuffer.bufferSize = 0;
  78298. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  78299. sslCopy.buffers.inputBuffer.offset = 0;
  78300. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78301. sslCopy.buffers.outputBuffer.buffer = NULL;
  78302. sslCopy.buffers.outputBuffer.bufferSize = 0;
  78303. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  78304. sslCopy.buffers.outputBuffer.offset = 0;
  78305. sslCopy.error = 0;
  78306. sslCopy.curSize = 0;
  78307. sslCopy.curStartIdx = 0;
  78308. sslCopy.keys.curSeq_lo = 0;
  78309. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  78310. #ifdef WOLFSSL_DTLS13
  78311. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  78312. sslCopy.dtls13FastTimeout = 0;
  78313. #endif
  78314. sslCopy.keys.dtls_peer_handshake_number = 0;
  78315. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  78316. sslCopy.hsHashes = NULL;
  78317. #ifdef WOLFSSL_ASYNC_IO
  78318. #ifdef WOLFSSL_ASYNC_CRYPT
  78319. sslCopy.asyncDev = NULL;
  78320. #endif
  78321. sslCopy.async = NULL;
  78322. #endif
  78323. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  78324. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  78325. /* hash extension list */
  78326. while (exts != NULL) {
  78327. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  78328. exts = exts->next;
  78329. }
  78330. /* Hash suites */
  78331. if (sslCopy.suites != NULL) {
  78332. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  78333. sizeof(struct Suites)), 0);
  78334. }
  78335. /* Hash hsHashes */
  78336. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  78337. sizeof(*hsHashes)), 0);
  78338. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  78339. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  78340. return MakeWordFromHash(hashBuf);
  78341. }
  78342. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  78343. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  78344. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  78345. char *buf, int sz, void *ctx)
  78346. {
  78347. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  78348. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  78349. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  78350. }
  78351. else {
  78352. return WOLFSSL_CBIO_ERR_WANT_READ;
  78353. }
  78354. }
  78355. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  78356. {
  78357. /* Compare the ssl object before and after one ClientHello msg */
  78358. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78359. int res;
  78360. int err;
  78361. word32 initHash;
  78362. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  78363. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  78364. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78365. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  78366. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  78367. (void)initHash;
  78368. res = tcp_select(fd, 5);
  78369. /* We are expecting a msg. A timeout indicates failure. */
  78370. AssertIntEQ(res, TEST_RECV_READY);
  78371. res = wolfSSL_accept(ssl);
  78372. err = wolfSSL_get_error(ssl, res);
  78373. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78374. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  78375. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  78376. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  78377. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  78378. }
  78379. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78380. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  78381. {
  78382. int ret;
  78383. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  78384. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  78385. test_wolfSSL_dtls_compare_stateless(ssl);
  78386. }
  78387. #endif
  78388. static int test_wolfSSL_dtls_stateless(void)
  78389. {
  78390. callback_functions client_cbs, server_cbs;
  78391. size_t i;
  78392. struct {
  78393. method_provider client_meth;
  78394. method_provider server_meth;
  78395. ssl_callback client_ssl_ready;
  78396. ssl_callback server_ssl_ready;
  78397. } test_params[] = {
  78398. #if !defined(WOLFSSL_NO_TLS12)
  78399. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78400. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  78401. #endif
  78402. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78403. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78404. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  78405. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78406. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  78407. #endif
  78408. };
  78409. if (0 == sizeof(test_params)){
  78410. return TEST_SKIPPED;
  78411. }
  78412. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  78413. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78414. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78415. client_cbs.doUdp = server_cbs.doUdp = 1;
  78416. client_cbs.method = test_params[i].client_meth;
  78417. server_cbs.method = test_params[i].server_meth;
  78418. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  78419. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  78420. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78421. if (!client_cbs.return_code)
  78422. return TEST_FAIL;
  78423. if (!server_cbs.return_code)
  78424. return TEST_FAIL;
  78425. }
  78426. return TEST_SUCCESS;
  78427. }
  78428. #else
  78429. static int test_wolfSSL_dtls_stateless(void)
  78430. {
  78431. return TEST_SKIPPED;
  78432. }
  78433. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  78434. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  78435. #ifdef HAVE_CERT_CHAIN_VALIDATION
  78436. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78437. {
  78438. int ret;
  78439. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  78440. fprintf(stderr, "loading cert %s failed\n", certA);
  78441. fprintf(stderr, "Error: (%d): %s\n", ret,
  78442. wolfSSL_ERR_reason_error_string(ret));
  78443. return -1;
  78444. }
  78445. return 0;
  78446. }
  78447. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78448. {
  78449. int ret;
  78450. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  78451. != WOLFSSL_SUCCESS) {
  78452. fprintf(stderr, "could not verify the cert: %s\n", certA);
  78453. fprintf(stderr, "Error: (%d): %s\n", ret,
  78454. wolfSSL_ERR_reason_error_string(ret));
  78455. return -1;
  78456. }
  78457. else {
  78458. fprintf(stderr, "successfully verified: %s\n", certA);
  78459. }
  78460. return 0;
  78461. }
  78462. #define LOAD_ONE_CA(a, b, c, d) \
  78463. do { \
  78464. (a) = load_ca_into_cm(c, d); \
  78465. if ((a) != 0) \
  78466. return (b); \
  78467. else \
  78468. (b)--; \
  78469. } while(0)
  78470. #define VERIFY_ONE_CERT(a, b, c, d) \
  78471. do { \
  78472. (a) = verify_cert_with_cm(c, d);\
  78473. if ((a) != 0) \
  78474. return (b); \
  78475. else \
  78476. (b)--; \
  78477. } while(0)
  78478. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  78479. {
  78480. int ret;
  78481. int i = -1;
  78482. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  78483. char chainGArr[9][50] = {"certs/ca-cert.pem",
  78484. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  78485. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  78486. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  78487. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  78488. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  78489. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  78490. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  78491. "certs/test-pathlen/chainG-entity.pem"};
  78492. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  78493. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  78494. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  78495. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  78496. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  78497. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  78498. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  78499. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  78500. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  78501. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  78502. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  78503. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  78504. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  78505. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  78506. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  78507. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  78508. /* test validating the entity twice, should have no effect on pathLen since
  78509. * entity/leaf cert */
  78510. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  78511. return ret;
  78512. }
  78513. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  78514. {
  78515. int ret;
  78516. int i = -1;
  78517. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  78518. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  78519. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  78520. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  78521. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  78522. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78523. */
  78524. char chainHArr[6][50] = {"certs/ca-cert.pem",
  78525. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  78526. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  78527. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  78528. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  78529. "certs/test-pathlen/chainH-entity.pem"};
  78530. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  78531. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  78532. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  78533. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  78534. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  78535. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  78536. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  78537. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  78538. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  78539. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  78540. return ret;
  78541. }
  78542. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  78543. {
  78544. int ret;
  78545. int i = -1;
  78546. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  78547. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  78548. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  78549. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  78550. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78551. */
  78552. char chainIArr[5][50] = {"certs/ca-cert.pem",
  78553. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  78554. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  78555. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  78556. "certs/test-pathlen/chainI-entity.pem"};
  78557. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  78558. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  78559. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  78560. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  78561. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  78562. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  78563. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  78564. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  78565. return ret;
  78566. }
  78567. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  78568. {
  78569. int ret;
  78570. int i = -1;
  78571. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  78572. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  78573. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  78574. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  78575. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  78576. */
  78577. char chainJArr[6][50] = {"certs/ca-cert.pem",
  78578. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  78579. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  78580. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  78581. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  78582. "certs/test-pathlen/chainJ-entity.pem"};
  78583. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  78584. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  78585. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  78586. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  78587. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  78588. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  78589. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  78590. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  78591. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  78592. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  78593. return ret;
  78594. }
  78595. static int test_various_pathlen_chains(void)
  78596. {
  78597. EXPECT_DECLS;
  78598. WOLFSSL_CERT_MANAGER* cm = NULL;
  78599. /* Test chain G (large chain with varying pathLens) */
  78600. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78601. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78602. ExpectIntEQ(test_chainG(cm), -1);
  78603. #else
  78604. ExpectIntEQ(test_chainG(cm), 0);
  78605. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78606. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78607. wolfSSL_CertManagerFree(cm);
  78608. /* end test chain G */
  78609. /* Test chain H (5 chain with same pathLens) */
  78610. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78611. ExpectIntLT(test_chainH(cm), 0);
  78612. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78613. wolfSSL_CertManagerFree(cm);
  78614. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78615. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78616. wolfSSL_CertManagerFree(cm);
  78617. /* end test chain H */
  78618. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  78619. * followed by 2 ICA's, should pass) */
  78620. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78621. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78622. ExpectIntEQ(test_chainI(cm), -1);
  78623. #else
  78624. ExpectIntEQ(test_chainI(cm), 0);
  78625. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78626. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78627. wolfSSL_CertManagerFree(cm);
  78628. cm = NULL;
  78629. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78630. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78631. wolfSSL_CertManagerFree(cm);
  78632. cm = NULL;
  78633. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  78634. * this time followed by 3 ICA's, should fail */
  78635. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78636. ExpectIntLT(test_chainJ(cm), 0);
  78637. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78638. wolfSSL_CertManagerFree(cm);
  78639. cm = NULL;
  78640. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78641. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78642. wolfSSL_CertManagerFree(cm);
  78643. return EXPECT_RESULT();
  78644. }
  78645. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  78646. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  78647. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  78648. {
  78649. EXPECT_DECLS;
  78650. byte ekm[100] = {0};
  78651. (void)ctx;
  78652. /* Success Cases */
  78653. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78654. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  78655. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78656. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  78657. /* Use some random context */
  78658. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78659. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  78660. /* Failure cases */
  78661. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78662. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  78663. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78664. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  78665. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78666. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  78667. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78668. "extended master secret", XSTR_SIZEOF("extended master secret"),
  78669. NULL, 0, 0), 0);
  78670. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78671. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  78672. return EXPECT_RESULT();
  78673. }
  78674. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  78675. {
  78676. wolfSSL_KeepArrays(ssl);
  78677. return TEST_SUCCESS;
  78678. }
  78679. static int test_export_keying_material(void)
  78680. {
  78681. EXPECT_DECLS;
  78682. test_ssl_cbf serverCb;
  78683. test_ssl_cbf clientCb;
  78684. XMEMSET(&serverCb, 0, sizeof(serverCb));
  78685. XMEMSET(&clientCb, 0, sizeof(clientCb));
  78686. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  78687. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  78688. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  78689. return EXPECT_RESULT();
  78690. }
  78691. #endif /* HAVE_KEYING_MATERIAL */
  78692. static int test_wolfSSL_THREADID_hash(void)
  78693. {
  78694. EXPECT_DECLS;
  78695. #if defined(OPENSSL_EXTRA)
  78696. CRYPTO_THREADID id;
  78697. CRYPTO_THREADID_current(NULL);
  78698. /* Hash result is unsigned long. */
  78699. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  78700. XMEMSET(&id, 0, sizeof(id));
  78701. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  78702. #endif /* OPENSSL_EXTRA */
  78703. return EXPECT_RESULT();
  78704. }
  78705. static int test_wolfSSL_set_ecdh_auto(void)
  78706. {
  78707. EXPECT_DECLS;
  78708. #if defined(OPENSSL_EXTRA)
  78709. WOLFSSL* ssl = NULL;
  78710. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  78711. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  78712. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  78713. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  78714. #endif /* OPENSSL_EXTRA */
  78715. return EXPECT_RESULT();
  78716. }
  78717. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  78718. {
  78719. EXPECT_DECLS;
  78720. #if defined(OPENSSL_EXTRA)
  78721. WOLFSSL_CTX* ctx = NULL;
  78722. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  78723. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  78724. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  78725. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  78726. #endif /* OPENSSL_EXTRA */
  78727. return EXPECT_RESULT();
  78728. }
  78729. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78730. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  78731. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  78732. {
  78733. EXPECT_DECLS;
  78734. callback_functions* callbacks = NULL;
  78735. WOLFSSL_CTX* ctx = NULL;
  78736. WOLFSSL* ssl = NULL;
  78737. SOCKET_T sfd = 0;
  78738. SOCKET_T cfd = 0;
  78739. word16 port;
  78740. char msg[] = "I hear you fa shizzle!";
  78741. int len = (int) XSTRLEN(msg);
  78742. char input[1024];
  78743. int ret = 0;
  78744. int err = 0;
  78745. if (!args)
  78746. WOLFSSL_RETURN_FROM_THREAD(0);
  78747. ((func_args*)args)->return_code = TEST_FAIL;
  78748. callbacks = ((func_args*)args)->callbacks;
  78749. ctx = wolfSSL_CTX_new(callbacks->method());
  78750. #if defined(USE_WINDOWS_API)
  78751. port = ((func_args*)args)->signal->port;
  78752. #else
  78753. /* Let tcp_listen assign port */
  78754. port = 0;
  78755. #endif
  78756. #ifdef WOLFSSL_TIRTOS
  78757. fdOpenSession(Task_self());
  78758. #endif
  78759. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  78760. caCertFile, 0));
  78761. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  78762. svrCertFile, WOLFSSL_FILETYPE_PEM));
  78763. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  78764. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  78765. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  78766. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  78767. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  78768. #elif !defined(NO_DH)
  78769. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  78770. #endif
  78771. if (callbacks->ctx_ready)
  78772. callbacks->ctx_ready(ctx);
  78773. ssl = wolfSSL_new(ctx);
  78774. ExpectNotNull(ssl);
  78775. /* listen and accept */
  78776. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  78777. CloseSocket(sfd);
  78778. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  78779. if (callbacks->ssl_ready)
  78780. callbacks->ssl_ready(ssl);
  78781. if (EXPECT_SUCCESS()) {
  78782. do {
  78783. err = 0; /* Reset error */
  78784. ret = wolfSSL_accept(ssl);
  78785. if (ret != WOLFSSL_SUCCESS) {
  78786. err = wolfSSL_get_error(ssl, 0);
  78787. }
  78788. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  78789. }
  78790. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  78791. /* read and write data */
  78792. XMEMSET(input, 0, sizeof(input));
  78793. while (EXPECT_SUCCESS()) {
  78794. ret = wolfSSL_read(ssl, input, sizeof(input));
  78795. if (ret > 0) {
  78796. break;
  78797. }
  78798. else {
  78799. err = wolfSSL_get_error(ssl,ret);
  78800. if (err == WOLFSSL_ERROR_WANT_READ) {
  78801. continue;
  78802. }
  78803. break;
  78804. }
  78805. }
  78806. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  78807. do {
  78808. ret = wolfSSL_write(ssl, msg, len);
  78809. if (ret > 0) {
  78810. break;
  78811. }
  78812. } while (ret < 0);
  78813. }
  78814. /* bidirectional shutdown */
  78815. while (EXPECT_SUCCESS()) {
  78816. ret = wolfSSL_shutdown(ssl);
  78817. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78818. if (ret == WOLFSSL_SUCCESS) {
  78819. break;
  78820. }
  78821. }
  78822. if (EXPECT_SUCCESS()) {
  78823. /* wait for the peer to disconnect the tcp connection */
  78824. do {
  78825. ret = wolfSSL_read(ssl, input, sizeof(input));
  78826. err = wolfSSL_get_error(ssl, ret);
  78827. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  78828. }
  78829. /* detect TCP disconnect */
  78830. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78831. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  78832. ((func_args*)args)->return_code = EXPECT_RESULT();
  78833. wolfSSL_free(ssl);
  78834. wolfSSL_CTX_free(ctx);
  78835. CloseSocket(cfd);
  78836. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  78837. wc_ecc_fp_free(); /* free per thread cache */
  78838. #endif
  78839. WOLFSSL_RETURN_FROM_THREAD(0);
  78840. }
  78841. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  78842. {
  78843. EXPECT_DECLS;
  78844. callback_functions* callbacks = NULL;
  78845. WOLFSSL_CTX* ctx = NULL;
  78846. WOLFSSL* ssl = NULL;
  78847. SOCKET_T sfd = 0;
  78848. char msg[] = "hello wolfssl server!";
  78849. int len = (int) XSTRLEN(msg);
  78850. char input[1024];
  78851. int idx;
  78852. int ret, err;
  78853. if (!args)
  78854. WOLFSSL_RETURN_FROM_THREAD(0);
  78855. ((func_args*)args)->return_code = TEST_FAIL;
  78856. callbacks = ((func_args*)args)->callbacks;
  78857. ctx = wolfSSL_CTX_new(callbacks->method());
  78858. #ifdef WOLFSSL_TIRTOS
  78859. fdOpenSession(Task_self());
  78860. #endif
  78861. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  78862. caCertFile, 0));
  78863. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  78864. cliCertFile, WOLFSSL_FILETYPE_PEM));
  78865. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  78866. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  78867. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  78868. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  78869. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  78870. if (EXPECT_SUCCESS()) {
  78871. do {
  78872. err = 0; /* Reset error */
  78873. ret = wolfSSL_connect(ssl);
  78874. if (ret != WOLFSSL_SUCCESS) {
  78875. err = wolfSSL_get_error(ssl, 0);
  78876. }
  78877. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  78878. }
  78879. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  78880. if (EXPECT_SUCCESS()) {
  78881. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  78882. input[idx] = 0;
  78883. }
  78884. }
  78885. if (EXPECT_SUCCESS()) {
  78886. ret = wolfSSL_shutdown(ssl);
  78887. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  78888. ret = wolfSSL_shutdown(ssl);
  78889. }
  78890. }
  78891. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  78892. ((func_args*)args)->return_code = EXPECT_RESULT();
  78893. wolfSSL_free(ssl);
  78894. wolfSSL_CTX_free(ctx);
  78895. CloseSocket(sfd);
  78896. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  78897. wc_ecc_fp_free(); /* free per thread cache */
  78898. #endif
  78899. WOLFSSL_RETURN_FROM_THREAD(0);
  78900. }
  78901. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  78902. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  78903. /* This test is to check wolfSSL_read behaves as same as
  78904. * openSSL when it is called after SSL_shutdown completes.
  78905. */
  78906. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  78907. {
  78908. EXPECT_DECLS;
  78909. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78910. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  78911. tcp_ready ready;
  78912. func_args client_args;
  78913. func_args server_args;
  78914. THREAD_TYPE serverThread;
  78915. THREAD_TYPE clientThread;
  78916. callback_functions server_cbf;
  78917. callback_functions client_cbf;
  78918. #ifdef WOLFSSL_TIRTOS
  78919. fdOpenSession(Task_self());
  78920. #endif
  78921. StartTCP();
  78922. InitTcpReady(&ready);
  78923. #if defined(USE_WINDOWS_API)
  78924. /* use RNG to get random port if using windows */
  78925. ready.port = GetRandomPort();
  78926. #endif
  78927. XMEMSET(&client_args, 0, sizeof(func_args));
  78928. XMEMSET(&server_args, 0, sizeof(func_args));
  78929. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  78930. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  78931. server_cbf.method = wolfTLSv1_2_server_method;
  78932. client_cbf.method = wolfTLSv1_2_client_method;
  78933. server_args.callbacks = &server_cbf;
  78934. client_args.callbacks = &client_cbf;
  78935. server_args.signal = &ready;
  78936. client_args.signal = &ready;
  78937. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  78938. wait_tcp_ready(&server_args);
  78939. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  78940. join_thread(clientThread);
  78941. join_thread(serverThread);
  78942. ExpectTrue(client_args.return_code);
  78943. ExpectTrue(server_args.return_code);
  78944. FreeTcpReady(&ready);
  78945. #endif
  78946. return EXPECT_RESULT();
  78947. }
  78948. static int test_wolfSSL_CTX_get_min_proto_version(void)
  78949. {
  78950. EXPECT_DECLS;
  78951. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  78952. WOLFSSL_CTX *ctx = NULL;
  78953. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78954. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  78955. WOLFSSL_SUCCESS);
  78956. #ifdef WOLFSSL_ALLOW_SSLV3
  78957. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  78958. #else
  78959. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  78960. #endif
  78961. wolfSSL_CTX_free(ctx);
  78962. ctx = NULL;
  78963. #ifndef NO_OLD_TLS
  78964. #ifdef WOLFSSL_ALLOW_TLSV10
  78965. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  78966. #else
  78967. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78968. #endif
  78969. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  78970. WOLFSSL_SUCCESS);
  78971. #ifdef WOLFSSL_ALLOW_TLSV10
  78972. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  78973. #else
  78974. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  78975. #endif
  78976. wolfSSL_CTX_free(ctx);
  78977. ctx = NULL;
  78978. #endif
  78979. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78980. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  78981. WOLFSSL_SUCCESS);
  78982. #ifndef NO_OLD_TLS
  78983. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  78984. #else
  78985. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  78986. #endif
  78987. wolfSSL_CTX_free(ctx);
  78988. ctx = NULL;
  78989. #ifndef WOLFSSL_NO_TLS12
  78990. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  78991. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  78992. WOLFSSL_SUCCESS);
  78993. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  78994. wolfSSL_CTX_free(ctx);
  78995. ctx = NULL;
  78996. #endif
  78997. #ifdef WOLFSSL_TLS13
  78998. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  78999. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  79000. WOLFSSL_SUCCESS);
  79001. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  79002. wolfSSL_CTX_free(ctx);
  79003. ctx = NULL;
  79004. #endif
  79005. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79006. return EXPECT_RESULT();
  79007. }
  79008. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79009. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79010. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79011. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  79012. static int test_wolfSSL_set_SSL_CTX(void)
  79013. {
  79014. EXPECT_DECLS;
  79015. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  79016. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  79017. !defined(NO_RSA)
  79018. WOLFSSL_CTX *ctx1 = NULL;
  79019. WOLFSSL_CTX *ctx2 = NULL;
  79020. WOLFSSL *ssl = NULL;
  79021. const byte *session_id1 = (const byte *)"CTX1";
  79022. const byte *session_id2 = (const byte *)"CTX2";
  79023. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79024. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  79025. WOLFSSL_FILETYPE_PEM));
  79026. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  79027. WOLFSSL_FILETYPE_PEM));
  79028. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  79029. WOLFSSL_SUCCESS);
  79030. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  79031. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  79032. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  79033. WOLFSSL_SUCCESS);
  79034. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79035. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  79036. WOLFSSL_FILETYPE_PEM));
  79037. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  79038. WOLFSSL_FILETYPE_PEM));
  79039. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  79040. WOLFSSL_SUCCESS);
  79041. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  79042. WOLFSSL_SUCCESS);
  79043. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  79044. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  79045. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  79046. WOLFSSL_SUCCESS);
  79047. #ifdef HAVE_SESSION_TICKET
  79048. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  79049. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  79050. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  79051. #endif
  79052. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  79053. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79054. #ifdef WOLFSSL_INT_H
  79055. #ifdef WOLFSSL_SESSION_ID_CTX
  79056. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  79057. #endif
  79058. #ifdef WOLFSSL_COPY_CERT
  79059. if (ctx2 != NULL && ctx2->certificate != NULL) {
  79060. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  79061. }
  79062. if (ctx2 != NULL && ctx2->certChain != NULL) {
  79063. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  79064. }
  79065. #else
  79066. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  79067. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  79068. #endif
  79069. #endif
  79070. #ifdef HAVE_SESSION_TICKET
  79071. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79072. #endif
  79073. /* Set the ctx1 that has TLSv1.3 as max proto version */
  79074. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  79075. /* MUST not change proto versions of ssl */
  79076. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79077. #ifdef HAVE_SESSION_TICKET
  79078. /* MUST not change */
  79079. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79080. #endif
  79081. /* MUST change */
  79082. #ifdef WOLFSSL_INT_H
  79083. #ifdef WOLFSSL_COPY_CERT
  79084. if (ctx1 != NULL && ctx1->certificate != NULL) {
  79085. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  79086. }
  79087. if (ctx1 != NULL && ctx1->certChain != NULL) {
  79088. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  79089. }
  79090. #else
  79091. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  79092. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  79093. #endif
  79094. #ifdef WOLFSSL_SESSION_ID_CTX
  79095. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  79096. #endif
  79097. #endif
  79098. wolfSSL_free(ssl);
  79099. wolfSSL_CTX_free(ctx1);
  79100. wolfSSL_CTX_free(ctx2);
  79101. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79102. return EXPECT_RESULT();
  79103. }
  79104. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79105. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79106. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79107. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  79108. static int test_wolfSSL_security_level(void)
  79109. {
  79110. EXPECT_DECLS;
  79111. #if defined(OPENSSL_EXTRA)
  79112. SSL_CTX *ctx = NULL;
  79113. #ifdef WOLFSSL_TLS13
  79114. #ifdef NO_WOLFSSL_SERVER
  79115. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79116. #else
  79117. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79118. #endif
  79119. SSL_CTX_set_security_level(NULL, 1);
  79120. SSL_CTX_set_security_level(ctx, 1);
  79121. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  79122. /* Stub so nothing happens. */
  79123. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  79124. SSL_CTX_free(ctx);
  79125. #else
  79126. (void)ctx;
  79127. #endif
  79128. #endif
  79129. return EXPECT_RESULT();
  79130. }
  79131. static int test_wolfSSL_SSL_in_init(void)
  79132. {
  79133. EXPECT_DECLS;
  79134. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  79135. SSL_CTX* ctx = NULL;
  79136. SSL* ssl = NULL;
  79137. const char* testCertFile;
  79138. const char* testKeyFile;
  79139. #ifdef WOLFSSL_TLS13
  79140. #ifdef NO_WOLFSSL_SERVER
  79141. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79142. #else
  79143. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79144. #endif
  79145. #else
  79146. #ifdef NO_WOLFSSL_SERVER
  79147. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79148. #else
  79149. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79150. #endif
  79151. #endif
  79152. #ifndef NO_RSA
  79153. testCertFile = svrCertFile;
  79154. testKeyFile = svrKeyFile;
  79155. #elif defined(HAVE_ECC)
  79156. testCertFile = eccCertFile;
  79157. testKeyFile = eccKeyFile;
  79158. #else
  79159. testCertFile = NULL;
  79160. testKeyFile = NULL;
  79161. #endif
  79162. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79163. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79164. SSL_FILETYPE_PEM));
  79165. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79166. SSL_FILETYPE_PEM));
  79167. }
  79168. ExpectNotNull(ssl = SSL_new(ctx));
  79169. ExpectIntEQ(SSL_in_init(ssl), 1);
  79170. SSL_CTX_free(ctx);
  79171. SSL_free(ssl);
  79172. #endif
  79173. return EXPECT_RESULT();
  79174. }
  79175. static int test_wolfSSL_CTX_set_timeout(void)
  79176. {
  79177. EXPECT_DECLS;
  79178. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  79179. int timeout;
  79180. WOLFSSL_CTX* ctx = NULL;
  79181. (void)timeout;
  79182. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79183. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  79184. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  79185. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  79186. */
  79187. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79188. /* giving 0 as timeout value sets default timeout */
  79189. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  79190. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  79191. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  79192. #else
  79193. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79194. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  79195. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  79196. #endif
  79197. wolfSSL_CTX_free(ctx);
  79198. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  79199. return EXPECT_RESULT();
  79200. }
  79201. static int test_wolfSSL_OpenSSL_version(void)
  79202. {
  79203. EXPECT_DECLS;
  79204. #if defined(OPENSSL_EXTRA)
  79205. const char* ver;
  79206. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  79207. ExpectNotNull(ver = OpenSSL_version(0));
  79208. #else
  79209. ExpectNotNull(ver = OpenSSL_version());
  79210. #endif
  79211. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  79212. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  79213. #endif
  79214. return EXPECT_RESULT();
  79215. }
  79216. static int test_CONF_CTX_CMDLINE(void)
  79217. {
  79218. EXPECT_DECLS;
  79219. #if defined(OPENSSL_ALL)
  79220. SSL_CTX* ctx = NULL;
  79221. SSL_CONF_CTX* cctx = NULL;
  79222. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79223. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79224. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79225. /* set flags */
  79226. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  79227. WOLFSSL_CONF_FLAG_CMDLINE);
  79228. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79229. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79230. /* cmd invalid command */
  79231. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79232. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79233. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79234. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79235. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79236. /* cmd Certificate and Private Key*/
  79237. {
  79238. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79239. const char* ourCert = svrCertFile;
  79240. const char* ourKey = svrKeyFile;
  79241. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  79242. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  79243. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  79244. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  79245. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79246. #endif
  79247. }
  79248. /* cmd curves */
  79249. {
  79250. #if defined(HAVE_ECC)
  79251. const char* curve = "secp256r1";
  79252. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  79253. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  79254. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79255. #endif
  79256. }
  79257. /* cmd CipherString */
  79258. {
  79259. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79260. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  79261. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  79262. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79263. }
  79264. /* cmd DH parameter */
  79265. {
  79266. #if !defined(NO_DH) && !defined(NO_BIO)
  79267. const char* ourdhcert = "./certs/dh2048.pem";
  79268. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  79269. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  79270. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79271. #endif
  79272. }
  79273. SSL_CTX_free(ctx);
  79274. SSL_CONF_CTX_free(cctx);
  79275. #endif /* OPENSSL_EXTRA */
  79276. return EXPECT_RESULT();
  79277. }
  79278. static int test_CONF_CTX_FILE(void)
  79279. {
  79280. EXPECT_DECLS;
  79281. #if defined(OPENSSL_ALL)
  79282. SSL_CTX* ctx = NULL;
  79283. SSL_CONF_CTX* cctx = NULL;
  79284. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79285. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79286. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79287. /* set flags */
  79288. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  79289. WOLFSSL_CONF_FLAG_FILE);
  79290. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79291. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79292. /* sanity check */
  79293. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79294. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79295. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79296. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79297. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79298. /* cmd Certificate and Private Key*/
  79299. {
  79300. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79301. const char* ourCert = svrCertFile;
  79302. const char* ourKey = svrKeyFile;
  79303. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  79304. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  79305. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  79306. WOLFSSL_SUCCESS);
  79307. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  79308. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79309. #endif
  79310. }
  79311. /* cmd curves */
  79312. {
  79313. #if defined(HAVE_ECC)
  79314. const char* curve = "secp256r1";
  79315. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  79316. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  79317. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79318. #endif
  79319. }
  79320. /* cmd CipherString */
  79321. {
  79322. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79323. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  79324. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  79325. WOLFSSL_SUCCESS);
  79326. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79327. }
  79328. /* cmd DH parameter */
  79329. {
  79330. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  79331. const char* ourdhcert = "./certs/dh3072.pem";
  79332. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  79333. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  79334. WOLFSSL_SUCCESS);
  79335. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79336. #endif
  79337. }
  79338. SSL_CTX_free(ctx);
  79339. SSL_CONF_CTX_free(cctx);
  79340. #endif /* OPENSSL_EXTRA */
  79341. return EXPECT_RESULT();
  79342. }
  79343. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  79344. {
  79345. EXPECT_DECLS;
  79346. #ifdef HAVE_EX_DATA
  79347. int idx1, idx2;
  79348. /* test for unsupported class index */
  79349. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  79350. 0,NULL, NULL, NULL, NULL ), -1);
  79351. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  79352. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  79353. 0,NULL, NULL, NULL, NULL ), -1);
  79354. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  79355. 0,NULL, NULL, NULL, NULL ), -1);
  79356. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  79357. 0,NULL, NULL, NULL, NULL ), -1);
  79358. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  79359. 0,NULL, NULL, NULL, NULL ), -1);
  79360. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  79361. 0,NULL, NULL, NULL, NULL ), -1);
  79362. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  79363. 0,NULL, NULL, NULL, NULL ), -1);
  79364. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  79365. 0,NULL, NULL, NULL, NULL ), -1);
  79366. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  79367. 0,NULL, NULL, NULL, NULL ), -1);
  79368. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  79369. 0,NULL, NULL, NULL, NULL ), -1);
  79370. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  79371. 0,NULL, NULL, NULL, NULL ), -1);
  79372. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  79373. 0,NULL, NULL, NULL, NULL ), -1);
  79374. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  79375. 0,NULL, NULL, NULL, NULL ), -1);
  79376. /* test for supported class index */
  79377. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79378. 0,NULL, NULL, NULL, NULL );
  79379. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79380. 0,NULL, NULL, NULL, NULL );
  79381. ExpectIntNE(idx1, -1);
  79382. ExpectIntNE(idx2, -1);
  79383. ExpectIntNE(idx1, idx2);
  79384. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79385. 0,NULL, NULL, NULL, NULL );
  79386. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79387. 0,NULL, NULL, NULL, NULL );
  79388. ExpectIntNE(idx1, -1);
  79389. ExpectIntNE(idx2, -1);
  79390. ExpectIntNE(idx1, idx2);
  79391. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79392. 0,NULL, NULL, NULL, NULL );
  79393. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79394. 0,NULL, NULL, NULL, NULL );
  79395. ExpectIntNE(idx1, -1);
  79396. ExpectIntNE(idx2, -1);
  79397. ExpectIntNE(idx1, idx2);
  79398. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79399. 0,NULL, NULL, NULL, NULL );
  79400. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79401. 0,NULL, NULL, NULL, NULL );
  79402. ExpectIntNE(idx1, -1);
  79403. ExpectIntNE(idx2, -1);
  79404. ExpectIntNE(idx1, idx2);
  79405. #endif /* HAVE_EX_DATA */
  79406. return EXPECT_RESULT();
  79407. }
  79408. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  79409. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79410. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79411. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79412. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  79413. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  79414. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  79415. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  79416. #define SESSION_NEW_IDX_PTR "Testing"
  79417. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  79418. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79419. {
  79420. AssertNotNull(p);
  79421. AssertNull(ptr);
  79422. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  79423. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79424. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  79425. }
  79426. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  79427. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  79428. void* arg)
  79429. {
  79430. EXPECT_DECLS;
  79431. ExpectNotNull(out);
  79432. ExpectNotNull(in);
  79433. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  79434. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  79435. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  79436. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  79437. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79438. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  79439. if (EXPECT_SUCCESS()) {
  79440. return SSL_SUCCESS;
  79441. }
  79442. else {
  79443. return SSL_FAILURE;
  79444. }
  79445. }
  79446. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  79447. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  79448. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79449. {
  79450. EXPECT_DECLS;
  79451. ExpectNotNull(p);
  79452. ExpectNull(ptr);
  79453. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  79454. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79455. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79456. if (EXPECT_SUCCESS()) {
  79457. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  79458. }
  79459. }
  79460. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79461. {
  79462. EXPECT_DECLS;
  79463. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  79464. (void*)SESSION_NEW_IDX_PTR,
  79465. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  79466. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  79467. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  79468. SSL_SESSION* s = SSL_SESSION_new();
  79469. SSL_SESSION* d = NULL;
  79470. ExpectNotNull(s);
  79471. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  79472. ExpectNotNull(d = SSL_SESSION_dup(s));
  79473. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  79474. SSL_SESSION_free(s);
  79475. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  79476. SSL_SESSION_free(d);
  79477. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  79478. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  79479. crypto_ex_cb_ctx_session = NULL;
  79480. return EXPECT_RESULT();
  79481. }
  79482. #else
  79483. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79484. {
  79485. return TEST_SKIPPED;
  79486. }
  79487. #endif
  79488. static int test_wolfSSL_set_psk_use_session_callback(void)
  79489. {
  79490. EXPECT_DECLS;
  79491. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  79492. SSL_CTX* ctx = NULL;
  79493. SSL* ssl = NULL;
  79494. const char* testCertFile;
  79495. const char* testKeyFile;
  79496. #ifdef WOLFSSL_TLS13
  79497. #ifdef NO_WOLFSSL_SERVER
  79498. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79499. #else
  79500. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79501. #endif
  79502. #else
  79503. #ifdef NO_WOLFSSL_SERVER
  79504. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79505. #else
  79506. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79507. #endif
  79508. #endif
  79509. #ifndef NO_RSA
  79510. testCertFile = svrCertFile;
  79511. testKeyFile = svrKeyFile;
  79512. #elif defined(HAVE_ECC)
  79513. testCertFile = eccCertFile;
  79514. testKeyFile = eccKeyFile;
  79515. #else
  79516. testCertFile = NULL;
  79517. testKeyFile = NULL;
  79518. #endif
  79519. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79520. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79521. SSL_FILETYPE_PEM));
  79522. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79523. SSL_FILETYPE_PEM));
  79524. }
  79525. ExpectNotNull(ssl = SSL_new(ctx));
  79526. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  79527. SSL_CTX_free(ctx);
  79528. SSL_free(ssl);
  79529. #endif
  79530. return EXPECT_RESULT();
  79531. }
  79532. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  79533. * TLS layer.
  79534. */
  79535. static int error_test(void)
  79536. {
  79537. EXPECT_DECLS;
  79538. const char* errStr;
  79539. const char* unknownStr = wc_GetErrorString(0);
  79540. #ifdef NO_ERROR_STRINGS
  79541. /* Ensure a valid error code's string matches an invalid code's.
  79542. * The string is that error strings are not available.
  79543. */
  79544. errStr = wc_GetErrorString(OPEN_RAN_E);
  79545. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79546. if (EXPECT_FAIL())
  79547. return OPEN_RAN_E;
  79548. #else
  79549. int i;
  79550. int j = 0;
  79551. /* Values that are not or no longer error codes. */
  79552. static const struct {
  79553. int first;
  79554. int last;
  79555. } missing[] = {
  79556. #ifndef OPENSSL_EXTRA
  79557. { 0, 0 },
  79558. #endif
  79559. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  79560. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  79561. { -11, -12 },
  79562. { -15, -17 },
  79563. { -19, -19 },
  79564. { -26, -27 },
  79565. { -30, WC_FIRST_E+1 },
  79566. #else
  79567. { -9, WC_FIRST_E+1 },
  79568. #endif
  79569. { -124, -124 },
  79570. { -166, -169 },
  79571. { -300, -300 },
  79572. { -334, -336 },
  79573. { -346, -349 },
  79574. { -356, -356 },
  79575. { -358, -358 },
  79576. { -372, -372 },
  79577. { -384, -384 },
  79578. { -466, -499 },
  79579. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  79580. };
  79581. /* Check that all errors have a string and it's the same through the two
  79582. * APIs. Check that the values that are not errors map to the unknown
  79583. * string.
  79584. */
  79585. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  79586. int this_missing = 0;
  79587. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  79588. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  79589. this_missing = 1;
  79590. break;
  79591. }
  79592. }
  79593. errStr = wolfSSL_ERR_reason_error_string(i);
  79594. if (! this_missing) {
  79595. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  79596. if (EXPECT_FAIL()) {
  79597. return i;
  79598. }
  79599. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  79600. if (EXPECT_FAIL()) {
  79601. return i;
  79602. }
  79603. }
  79604. else {
  79605. j++;
  79606. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79607. if (EXPECT_FAIL()) {
  79608. return i;
  79609. }
  79610. }
  79611. }
  79612. #endif
  79613. return 1;
  79614. }
  79615. static int test_wolfSSL_ERR_strings(void)
  79616. {
  79617. EXPECT_DECLS;
  79618. #if !defined(NO_ERROR_STRINGS)
  79619. const char* err1 = "unsupported cipher suite";
  79620. const char* err2 = "wolfSSL PEM routines";
  79621. const char* err = NULL;
  79622. (void)err;
  79623. (void)err1;
  79624. (void)err2;
  79625. #if defined(OPENSSL_EXTRA)
  79626. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79627. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79628. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79629. ExpectIntEQ((*err == '\0'), 1);
  79630. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  79631. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  79632. #else
  79633. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79634. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79635. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79636. ExpectIntEQ((*err == '\0'), 1);
  79637. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  79638. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  79639. ExpectIntEQ((*err == '\0'), 1);
  79640. #endif
  79641. #endif
  79642. ExpectIntEQ(error_test(), 1);
  79643. return EXPECT_RESULT();
  79644. }
  79645. static int test_wolfSSL_EVP_shake128(void)
  79646. {
  79647. EXPECT_DECLS;
  79648. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79649. defined(WOLFSSL_SHAKE128)
  79650. const EVP_MD* md = NULL;
  79651. ExpectNotNull(md = EVP_shake128());
  79652. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  79653. #endif
  79654. return EXPECT_RESULT();
  79655. }
  79656. static int test_wolfSSL_EVP_shake256(void)
  79657. {
  79658. EXPECT_DECLS;
  79659. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79660. defined(WOLFSSL_SHAKE256)
  79661. const EVP_MD* md = NULL;
  79662. ExpectNotNull(md = EVP_shake256());
  79663. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  79664. #endif
  79665. return EXPECT_RESULT();
  79666. }
  79667. /*
  79668. * Testing EVP digest API with SM3
  79669. */
  79670. static int test_wolfSSL_EVP_sm3(void)
  79671. {
  79672. int res = TEST_SKIPPED;
  79673. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  79674. EXPECT_DECLS;
  79675. const EVP_MD* md = NULL;
  79676. EVP_MD_CTX* mdCtx = NULL;
  79677. byte data[WC_SM3_BLOCK_SIZE * 4];
  79678. byte hash[WC_SM3_DIGEST_SIZE];
  79679. byte calcHash[WC_SM3_DIGEST_SIZE];
  79680. byte expHash[WC_SM3_DIGEST_SIZE] = {
  79681. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  79682. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  79683. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  79684. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  79685. };
  79686. word32 chunk;
  79687. word32 i;
  79688. unsigned int sz;
  79689. int ret;
  79690. XMEMSET(data, 0, sizeof(data));
  79691. md = EVP_sm3();
  79692. ExpectTrue(md != NULL);
  79693. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  79694. mdCtx = EVP_MD_CTX_new();
  79695. ExpectTrue(mdCtx != NULL);
  79696. /* Invalid Parameters */
  79697. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79698. /* Valid Parameters */
  79699. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  79700. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79701. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79702. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79703. /* Valid Parameters */
  79704. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  79705. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79706. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79707. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  79708. WOLFSSL_SUCCESS);
  79709. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  79710. WOLFSSL_SUCCESS);
  79711. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  79712. WOLFSSL_SUCCESS);
  79713. /* Ensure too many bytes for lengths. */
  79714. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  79715. WOLFSSL_SUCCESS);
  79716. /* Invalid Parameters */
  79717. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79718. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79719. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79720. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79721. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79722. /* Valid Parameters */
  79723. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79724. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  79725. /* Chunk tests. */
  79726. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  79727. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  79728. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  79729. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  79730. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  79731. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  79732. WOLFSSL_SUCCESS);
  79733. }
  79734. if (i < (word32)sizeof(data)) {
  79735. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  79736. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  79737. }
  79738. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79739. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  79740. }
  79741. /* Not testing when the low 32-bit length overflows. */
  79742. ret = EVP_MD_CTX_cleanup(mdCtx);
  79743. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79744. wolfSSL_EVP_MD_CTX_free(mdCtx);
  79745. res = EXPECT_RESULT();
  79746. #endif
  79747. return res;
  79748. } /* END test_EVP_sm3 */
  79749. static int test_EVP_blake2(void)
  79750. {
  79751. EXPECT_DECLS;
  79752. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  79753. const EVP_MD* md = NULL;
  79754. (void)md;
  79755. #if defined(HAVE_BLAKE2)
  79756. ExpectNotNull(md = EVP_blake2b512());
  79757. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  79758. #endif
  79759. #if defined(HAVE_BLAKE2S)
  79760. ExpectNotNull(md = EVP_blake2s256());
  79761. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  79762. #endif
  79763. #endif
  79764. return EXPECT_RESULT();
  79765. }
  79766. #if defined(OPENSSL_EXTRA)
  79767. static void list_md_fn(const EVP_MD* m, const char* from,
  79768. const char* to, void* arg)
  79769. {
  79770. const char* mn;
  79771. BIO *bio;
  79772. (void) from;
  79773. (void) to;
  79774. (void) arg;
  79775. (void) mn;
  79776. (void) bio;
  79777. if (!m) {
  79778. /* alias */
  79779. AssertNull(m);
  79780. AssertNotNull(to);
  79781. }
  79782. else {
  79783. AssertNotNull(m);
  79784. AssertNull(to);
  79785. }
  79786. AssertNotNull(from);
  79787. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  79788. mn = EVP_get_digestbyname(from);
  79789. /* print to stderr */
  79790. AssertNotNull(arg);
  79791. bio = BIO_new(BIO_s_file());
  79792. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  79793. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  79794. BIO_free(bio);
  79795. #endif
  79796. }
  79797. #endif
  79798. static int test_EVP_MD_do_all(void)
  79799. {
  79800. int res = TEST_SKIPPED;
  79801. #if defined(OPENSSL_EXTRA)
  79802. EVP_MD_do_all(NULL, stderr);
  79803. EVP_MD_do_all(list_md_fn, stderr);
  79804. res = TEST_SUCCESS;
  79805. #endif
  79806. return res;
  79807. }
  79808. #if defined(OPENSSL_EXTRA)
  79809. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  79810. {
  79811. (void)arg;
  79812. (void)nm;
  79813. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  79814. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  79815. /* print to stderr */
  79816. AssertNotNull(arg);
  79817. BIO *bio = BIO_new(BIO_s_file());
  79818. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  79819. BIO_printf(bio, "%s\n", nm);
  79820. BIO_free(bio);
  79821. #endif
  79822. }
  79823. #endif
  79824. static int test_OBJ_NAME_do_all(void)
  79825. {
  79826. int res = TEST_SKIPPED;
  79827. #if defined(OPENSSL_EXTRA)
  79828. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  79829. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  79830. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  79831. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  79832. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  79833. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  79834. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  79835. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  79836. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  79837. res = TEST_SUCCESS;
  79838. #endif
  79839. return res;
  79840. }
  79841. static int test_SSL_CIPHER_get_xxx(void)
  79842. {
  79843. EXPECT_DECLS;
  79844. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  79845. !defined(NO_FILESYSTEM)
  79846. const SSL_CIPHER* cipher = NULL;
  79847. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  79848. int i, numCiphers = 0;
  79849. SSL_CTX* ctx = NULL;
  79850. SSL* ssl = NULL;
  79851. const char* testCertFile;
  79852. const char* testKeyFile;
  79853. char buf[256] = {0};
  79854. const char* cipher_id = NULL;
  79855. int expect_nid1 = NID_undef;
  79856. int expect_nid2 = NID_undef;
  79857. int expect_nid3 = NID_undef;
  79858. int expect_nid4 = NID_undef;
  79859. int expect_nid5 = 0;
  79860. const char* cipher_id2 = NULL;
  79861. int expect_nid21 = NID_undef;
  79862. int expect_nid22 = NID_undef;
  79863. int expect_nid23 = NID_undef;
  79864. int expect_nid24 = NID_undef;
  79865. int expect_nid25 = 0;
  79866. (void)cipher;
  79867. (void)supportedCiphers;
  79868. (void)i;
  79869. (void)numCiphers;
  79870. (void)ctx;
  79871. (void)ssl;
  79872. (void)testCertFile;
  79873. (void)testKeyFile;
  79874. #if defined(WOLFSSL_TLS13)
  79875. cipher_id = "TLS13-AES128-GCM-SHA256";
  79876. expect_nid1 = NID_auth_rsa;
  79877. expect_nid2 = NID_aes_128_gcm;
  79878. expect_nid3 = NID_sha256;
  79879. expect_nid4 = NID_kx_any;
  79880. expect_nid5 = 1;
  79881. #if !defined(WOLFSSL_NO_TLS12)
  79882. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  79883. expect_nid21 = NID_auth_rsa;
  79884. expect_nid22 = NID_aes_256_gcm;
  79885. expect_nid23 = NID_sha384;
  79886. expect_nid24 = NID_kx_ecdhe;
  79887. expect_nid25 = 1;
  79888. #endif
  79889. #endif
  79890. #ifdef NO_WOLFSSL_SERVER
  79891. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79892. #else
  79893. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79894. #endif
  79895. if (cipher_id) {
  79896. #ifndef NO_RSA
  79897. testCertFile = svrCertFile;
  79898. testKeyFile = svrKeyFile;
  79899. #elif defined(HAVE_ECC)
  79900. testCertFile = eccCertFile;
  79901. testKeyFile = eccKeyFile;
  79902. #else
  79903. testCertFile = NULL;
  79904. testKeyFile = NULL;
  79905. #endif
  79906. if (testCertFile != NULL && testKeyFile != NULL) {
  79907. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79908. SSL_FILETYPE_PEM));
  79909. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79910. SSL_FILETYPE_PEM));
  79911. }
  79912. ExpectNotNull(ssl = SSL_new(ctx));
  79913. ExpectIntEQ(SSL_in_init(ssl), 1);
  79914. supportedCiphers = SSL_get_ciphers(ssl);
  79915. numCiphers = sk_num(supportedCiphers);
  79916. for (i = 0; i < numCiphers; ++i) {
  79917. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  79918. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  79919. }
  79920. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  79921. break;
  79922. }
  79923. }
  79924. /* test case for */
  79925. if (i != numCiphers) {
  79926. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  79927. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  79928. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  79929. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  79930. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  79931. }
  79932. if (cipher_id2) {
  79933. for (i = 0; i < numCiphers; ++i) {
  79934. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  79935. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  79936. }
  79937. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  79938. break;
  79939. }
  79940. }
  79941. /* test case for */
  79942. if (i != numCiphers) {
  79943. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  79944. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  79945. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  79946. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  79947. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  79948. }
  79949. }
  79950. }
  79951. SSL_CTX_free(ctx);
  79952. SSL_free(ssl);
  79953. #endif
  79954. return EXPECT_RESULT();
  79955. }
  79956. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  79957. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  79958. int* keyFormat)
  79959. {
  79960. int ret;
  79961. byte* key_buf = NULL;
  79962. size_t key_sz = 0;
  79963. EncryptedInfo encInfo;
  79964. XMEMSET(&encInfo, 0, sizeof(encInfo));
  79965. ret = load_file(privKeyFile, &key_buf, &key_sz);
  79966. if (ret == 0) {
  79967. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  79968. NULL, &encInfo, keyFormat);
  79969. }
  79970. if (key_buf != NULL) {
  79971. free(key_buf); key_buf = NULL;
  79972. }
  79973. (void)encInfo; /* not used in this test */
  79974. #ifdef DEBUG_WOLFSSL
  79975. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  79976. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  79977. (*pDer)->length);
  79978. #endif
  79979. return ret;
  79980. }
  79981. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  79982. {
  79983. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  79984. const char* privKeyFile = (const char*)ctx;
  79985. DerBuffer* pDer = NULL;
  79986. int keyFormat = 0;
  79987. if (info->algo_type == WC_ALGO_TYPE_PK) {
  79988. #ifdef DEBUG_WOLFSSL
  79989. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  79990. #endif
  79991. #ifndef NO_RSA
  79992. if (info->pk.type == WC_PK_TYPE_RSA) {
  79993. switch (info->pk.rsa.type) {
  79994. case RSA_PUBLIC_ENCRYPT:
  79995. case RSA_PUBLIC_DECRYPT:
  79996. /* perform software based RSA public op */
  79997. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  79998. break;
  79999. case RSA_PRIVATE_ENCRYPT:
  80000. case RSA_PRIVATE_DECRYPT:
  80001. {
  80002. RsaKey key;
  80003. /* perform software based RSA private op */
  80004. #ifdef DEBUG_WOLFSSL
  80005. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  80006. #endif
  80007. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80008. &keyFormat);
  80009. if (ret != 0) {
  80010. return ret;
  80011. }
  80012. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80013. if (ret == 0) {
  80014. word32 keyIdx = 0;
  80015. /* load RSA private key and perform private transform */
  80016. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80017. &key, pDer->length);
  80018. if (ret == 0) {
  80019. ret = wc_RsaFunction(
  80020. info->pk.rsa.in, info->pk.rsa.inLen,
  80021. info->pk.rsa.out, info->pk.rsa.outLen,
  80022. info->pk.rsa.type, &key, info->pk.rsa.rng);
  80023. }
  80024. else {
  80025. /* if decode fails, then fall-back to software based crypto */
  80026. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  80027. "key decode failed %d, falling back to "
  80028. "software\n", ret);
  80029. ret = CRYPTOCB_UNAVAILABLE;
  80030. }
  80031. wc_FreeRsaKey(&key);
  80032. }
  80033. wc_FreeDer(&pDer); pDer = NULL;
  80034. break;
  80035. }
  80036. }
  80037. #ifdef DEBUG_WOLFSSL
  80038. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  80039. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  80040. #endif
  80041. }
  80042. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  80043. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  80044. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  80045. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  80046. RsaKey key;
  80047. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  80048. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  80049. /* Have all public key ops fall back to SW */
  80050. return CRYPTOCB_UNAVAILABLE;
  80051. }
  80052. if (info->pk.rsa.padding == NULL) {
  80053. return BAD_FUNC_ARG;
  80054. }
  80055. /* Initialize key */
  80056. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80057. &keyFormat);
  80058. if (ret != 0) {
  80059. return ret;
  80060. }
  80061. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80062. if (ret == 0) {
  80063. word32 keyIdx = 0;
  80064. /* load RSA private key and perform private transform */
  80065. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80066. &key, pDer->length);
  80067. }
  80068. /* Perform RSA operation */
  80069. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  80070. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  80071. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  80072. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  80073. info->pk.rsa.rng);
  80074. #else
  80075. ret = CRYPTOCB_UNAVAILABLE;
  80076. #endif
  80077. }
  80078. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  80079. #ifdef WC_RSA_PSS
  80080. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  80081. info->pk.rsa.out, *info->pk.rsa.outLen,
  80082. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  80083. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  80084. #else
  80085. ret = CRYPTOCB_UNAVAILABLE;
  80086. #endif
  80087. }
  80088. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  80089. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  80090. ret = wc_RsaPrivateDecrypt_ex(
  80091. info->pk.rsa.in, info->pk.rsa.inLen,
  80092. info->pk.rsa.out, *info->pk.rsa.outLen,
  80093. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  80094. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  80095. info->pk.rsa.padding->labelSz);
  80096. #else
  80097. ret = CRYPTOCB_UNAVAILABLE;
  80098. #endif
  80099. }
  80100. if (ret > 0) {
  80101. *info->pk.rsa.outLen = ret;
  80102. }
  80103. wc_FreeRsaKey(&key);
  80104. wc_FreeDer(&pDer); pDer = NULL;
  80105. }
  80106. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  80107. #endif /* !NO_RSA */
  80108. #ifdef HAVE_ECC
  80109. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  80110. /* mark this key as ephemeral */
  80111. if (info->pk.eckg.key != NULL) {
  80112. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  80113. sizeof(info->pk.eckg.key->label));
  80114. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  80115. }
  80116. }
  80117. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  80118. ecc_key key;
  80119. /* perform software based ECC sign */
  80120. #ifdef DEBUG_WOLFSSL
  80121. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  80122. #endif
  80123. if (info->pk.eccsign.key != NULL &&
  80124. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  80125. /* this is an empheral key */
  80126. #ifdef DEBUG_WOLFSSL
  80127. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  80128. "ephemeral key\n");
  80129. #endif
  80130. return CRYPTOCB_UNAVAILABLE;
  80131. }
  80132. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80133. if (ret != 0) {
  80134. return ret;
  80135. }
  80136. ret = wc_ecc_init(&key);
  80137. if (ret == 0) {
  80138. word32 keyIdx = 0;
  80139. /* load ECC private key and perform private transform */
  80140. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  80141. &key, pDer->length);
  80142. if (ret == 0) {
  80143. ret = wc_ecc_sign_hash(
  80144. info->pk.eccsign.in, info->pk.eccsign.inlen,
  80145. info->pk.eccsign.out, info->pk.eccsign.outlen,
  80146. info->pk.eccsign.rng, &key);
  80147. }
  80148. else {
  80149. /* if decode fails, then fall-back to software based crypto */
  80150. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  80151. "decode failed %d, falling back to software\n", ret);
  80152. ret = CRYPTOCB_UNAVAILABLE;
  80153. }
  80154. wc_ecc_free(&key);
  80155. }
  80156. wc_FreeDer(&pDer); pDer = NULL;
  80157. #ifdef DEBUG_WOLFSSL
  80158. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  80159. ret, *info->pk.eccsign.outlen);
  80160. #endif
  80161. }
  80162. #endif /* HAVE_ECC */
  80163. #ifdef HAVE_ED25519
  80164. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  80165. ed25519_key key;
  80166. /* perform software based ED25519 sign */
  80167. #ifdef DEBUG_WOLFSSL
  80168. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  80169. #endif
  80170. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80171. if (ret != 0) {
  80172. return ret;
  80173. }
  80174. ret = wc_ed25519_init(&key);
  80175. if (ret == 0) {
  80176. word32 keyIdx = 0;
  80177. /* load ED25519 private key and perform private transform */
  80178. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  80179. &key, pDer->length);
  80180. if (ret == 0) {
  80181. /* calculate public key */
  80182. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  80183. if (ret == 0) {
  80184. key.pubKeySet = 1;
  80185. ret = wc_ed25519_sign_msg_ex(
  80186. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  80187. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  80188. &key, info->pk.ed25519sign.type,
  80189. info->pk.ed25519sign.context,
  80190. info->pk.ed25519sign.contextLen);
  80191. }
  80192. }
  80193. else {
  80194. /* if decode fails, then fall-back to software based crypto */
  80195. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  80196. "decode failed %d, falling back to software\n", ret);
  80197. ret = CRYPTOCB_UNAVAILABLE;
  80198. }
  80199. wc_ed25519_free(&key);
  80200. }
  80201. wc_FreeDer(&pDer); pDer = NULL;
  80202. #ifdef DEBUG_WOLFSSL
  80203. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  80204. ret, *info->pk.ed25519sign.outLen);
  80205. #endif
  80206. }
  80207. #endif /* HAVE_ED25519 */
  80208. }
  80209. (void)thisDevId;
  80210. (void)keyFormat;
  80211. return ret;
  80212. }
  80213. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80214. static int test_wc_CryptoCb_TLS(int tlsVer,
  80215. const char* cliCaPemFile, const char* cliCertPemFile,
  80216. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  80217. const char* svrCaPemFile, const char* svrCertPemFile,
  80218. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  80219. {
  80220. EXPECT_DECLS;
  80221. callback_functions client_cbf;
  80222. callback_functions server_cbf;
  80223. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80224. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80225. if (tlsVer == WOLFSSL_TLSV1_3) {
  80226. #ifdef WOLFSSL_TLS13
  80227. server_cbf.method = wolfTLSv1_3_server_method;
  80228. client_cbf.method = wolfTLSv1_3_client_method;
  80229. #endif
  80230. }
  80231. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80232. #ifndef WOLFSSL_NO_TLS12
  80233. server_cbf.method = wolfTLSv1_2_server_method;
  80234. client_cbf.method = wolfTLSv1_2_client_method;
  80235. #endif
  80236. }
  80237. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80238. #ifndef NO_OLD_TLS
  80239. server_cbf.method = wolfTLSv1_1_server_method;
  80240. client_cbf.method = wolfTLSv1_1_client_method;
  80241. #endif
  80242. }
  80243. else if (tlsVer == WOLFSSL_TLSV1) {
  80244. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80245. server_cbf.method = wolfTLSv1_server_method;
  80246. client_cbf.method = wolfTLSv1_client_method;
  80247. #endif
  80248. }
  80249. else if (tlsVer == WOLFSSL_SSLV3) {
  80250. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80251. defined(WOLFSSL_STATIC_RSA)
  80252. server_cbf.method = wolfSSLv3_server_method;
  80253. client_cbf.method = wolfSSLv3_client_method;
  80254. #endif
  80255. }
  80256. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80257. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80258. server_cbf.method = wolfDTLSv1_2_server_method;
  80259. client_cbf.method = wolfDTLSv1_2_client_method;
  80260. #endif
  80261. }
  80262. else if (tlsVer == WOLFSSL_DTLSV1) {
  80263. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80264. server_cbf.method = wolfDTLSv1_server_method;
  80265. client_cbf.method = wolfDTLSv1_client_method;
  80266. #endif
  80267. }
  80268. if (server_cbf.method == NULL) {
  80269. /* not enabled */
  80270. return TEST_SUCCESS;
  80271. }
  80272. /* Setup the keys for the TLS test */
  80273. client_cbf.certPemFile = cliCertPemFile;
  80274. client_cbf.keyPemFile = cliPubKeyPemFile;
  80275. client_cbf.caPemFile = cliCaPemFile;
  80276. server_cbf.certPemFile = svrCertPemFile;
  80277. server_cbf.keyPemFile = svrPubKeyPemFile;
  80278. server_cbf.caPemFile = svrCaPemFile;
  80279. /* Setup a crypto callback with pointer to private key file for testing */
  80280. client_cbf.devId = 1;
  80281. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  80282. (void*)cliPrivKeyPemFile);
  80283. server_cbf.devId = 2;
  80284. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  80285. (void*)svrPrivKeyPemFile);
  80286. /* Perform TLS server and client test */
  80287. /* First test is at WOLFSSL_CTX level */
  80288. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80289. /* Check for success */
  80290. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80291. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80292. if (EXPECT_SUCCESS()) {
  80293. /* Second test is a WOLFSSL object level */
  80294. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80295. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80296. }
  80297. /* Check for success */
  80298. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80299. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80300. /* Un register the devId's */
  80301. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  80302. client_cbf.devId = INVALID_DEVID;
  80303. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  80304. server_cbf.devId = INVALID_DEVID;
  80305. return EXPECT_RESULT();
  80306. }
  80307. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  80308. static int test_wc_CryptoCb(void)
  80309. {
  80310. EXPECT_DECLS;
  80311. #ifdef WOLF_CRYPTO_CB
  80312. /* TODO: Add crypto callback API tests */
  80313. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80314. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80315. int tlsVer;
  80316. #endif
  80317. #ifndef NO_RSA
  80318. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80319. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80320. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  80321. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  80322. TEST_SUCCESS);
  80323. }
  80324. #endif
  80325. #ifdef HAVE_ECC
  80326. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80327. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80328. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  80329. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  80330. TEST_SUCCESS);
  80331. }
  80332. #endif
  80333. #ifdef HAVE_ED25519
  80334. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80335. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80336. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80337. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  80338. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  80339. TEST_SUCCESS);
  80340. }
  80341. #endif
  80342. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80343. #endif /* WOLF_CRYPTO_CB */
  80344. return EXPECT_RESULT();
  80345. }
  80346. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80347. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80348. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  80349. const char* cliCaPemFile, const char* cliCertPemFile,
  80350. const char* cliPrivKeyPemFile,
  80351. const char* svrCaPemFile, const char* svrCertPemFile,
  80352. const char* svrPrivKeyPemFile,
  80353. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  80354. {
  80355. EXPECT_DECLS;
  80356. callback_functions client_cbf;
  80357. callback_functions server_cbf;
  80358. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80359. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80360. if (tlsVer == WOLFSSL_TLSV1_3) {
  80361. #ifdef WOLFSSL_TLS13
  80362. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  80363. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  80364. #endif
  80365. }
  80366. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80367. #ifndef WOLFSSL_NO_TLS12
  80368. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  80369. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  80370. #endif
  80371. }
  80372. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80373. #ifndef NO_OLD_TLS
  80374. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  80375. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  80376. #endif
  80377. }
  80378. else if (tlsVer == WOLFSSL_TLSV1) {
  80379. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80380. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  80381. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  80382. #endif
  80383. }
  80384. else if (tlsVer == WOLFSSL_SSLV3) {
  80385. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80386. defined(WOLFSSL_STATIC_RSA)
  80387. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  80388. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  80389. #endif
  80390. }
  80391. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80392. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80393. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  80394. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  80395. #endif
  80396. }
  80397. else if (tlsVer == WOLFSSL_DTLSV1) {
  80398. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80399. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  80400. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  80401. #endif
  80402. }
  80403. if (server_cbf.method_ex == NULL) {
  80404. /* not enabled */
  80405. return TEST_SUCCESS;
  80406. }
  80407. /* Setup the keys for the TLS test */
  80408. client_cbf.certPemFile = cliCertPemFile;
  80409. client_cbf.keyPemFile = cliPrivKeyPemFile;
  80410. client_cbf.caPemFile = cliCaPemFile;
  80411. server_cbf.certPemFile = svrCertPemFile;
  80412. server_cbf.keyPemFile = svrPrivKeyPemFile;
  80413. server_cbf.caPemFile = svrCaPemFile;
  80414. client_cbf.mem = cliMem;
  80415. client_cbf.memSz = cliMemSz;
  80416. server_cbf.mem = svrMem;
  80417. server_cbf.memSz = svrMemSz;
  80418. client_cbf.devId = INVALID_DEVID;
  80419. server_cbf.devId = INVALID_DEVID;
  80420. /* Perform TLS server and client test */
  80421. /* First test is at WOLFSSL_CTX level */
  80422. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80423. /* Check for success */
  80424. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80425. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80426. if (EXPECT_SUCCESS()) {
  80427. /* Second test is a WOLFSSL object level */
  80428. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80429. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80430. }
  80431. /* Check for success */
  80432. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80433. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80434. return EXPECT_RESULT();
  80435. }
  80436. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  80437. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80438. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  80439. {
  80440. EXPECT_DECLS;
  80441. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  80442. WOLFSSL_MEM_STATS mem_stats;
  80443. WOLFSSL_MEM_CONN_STATS ssl_stats;
  80444. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  80445. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  80446. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80447. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  80448. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80449. #endif
  80450. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  80451. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  80452. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  80453. /* this should fail because kMaxCtxClients == 2 */
  80454. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  80455. #else
  80456. (void)ssl3;
  80457. #endif
  80458. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  80459. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80460. wolfSSL_PrintStatsConn(&ssl_stats);
  80461. #endif
  80462. (void)ssl_stats;
  80463. }
  80464. /* display collected statistics */
  80465. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  80466. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80467. wolfSSL_PrintStats(&mem_stats);
  80468. #endif
  80469. (void)mem_stats;
  80470. }
  80471. wolfSSL_free(ssl1);
  80472. wolfSSL_free(ssl2);
  80473. return EXPECT_RESULT();
  80474. }
  80475. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80476. static int test_wolfSSL_CTX_StaticMemory(void)
  80477. {
  80478. EXPECT_DECLS;
  80479. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80480. wolfSSL_method_func method_func;
  80481. WOLFSSL_CTX* ctx;
  80482. const int kMaxCtxClients = 2;
  80483. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80484. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80485. int tlsVer;
  80486. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  80487. #endif
  80488. #endif
  80489. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  80490. #ifndef NO_WOLFSSL_SERVER
  80491. #ifndef WOLFSSL_NO_TLS12
  80492. method_func = wolfTLSv1_2_server_method_ex;
  80493. #else
  80494. method_func = wolfTLSv1_3_server_method_ex;
  80495. #endif
  80496. #else
  80497. #ifndef WOLFSSL_NO_TLS12
  80498. method_func = wolfTLSv1_2_client_method_ex;
  80499. #else
  80500. method_func = wolfTLSv1_3_client_method_ex;
  80501. #endif
  80502. #endif
  80503. /* Test creating CTX directly from static memory pool */
  80504. ctx = NULL;
  80505. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  80506. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80507. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80508. wolfSSL_CTX_free(ctx);
  80509. ctx = NULL;
  80510. /* Test for heap allocated CTX, then assigning static pool to it */
  80511. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  80512. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  80513. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80514. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80515. wolfSSL_CTX_free(ctx);
  80516. /* TLS Level Tests using static memory */
  80517. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80518. #ifndef NO_RSA
  80519. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80520. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80521. svrCertFile, cliCertFile, cliKeyFile,
  80522. cliCertFile, svrCertFile, svrKeyFile,
  80523. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80524. TEST_SUCCESS);
  80525. }
  80526. #endif
  80527. #ifdef HAVE_ECC
  80528. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80529. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80530. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  80531. cliEccCertFile, eccCertFile, eccKeyFile,
  80532. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80533. TEST_SUCCESS);
  80534. }
  80535. #endif
  80536. #ifdef HAVE_ED25519
  80537. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80538. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80539. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80540. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  80541. cliEdCertFile, edCertFile, edKeyFile,
  80542. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80543. TEST_SUCCESS);
  80544. }
  80545. #endif
  80546. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80547. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80548. return EXPECT_RESULT();
  80549. }
  80550. static int test_openssl_FIPS_drbg(void)
  80551. {
  80552. EXPECT_DECLS;
  80553. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  80554. DRBG_CTX* dctx = NULL;
  80555. byte data1[32], data2[32], zeroData[32];
  80556. byte testSeed[16];
  80557. size_t dlen = sizeof(data1);
  80558. int i;
  80559. XMEMSET(data1, 0, dlen);
  80560. XMEMSET(data2, 0, dlen);
  80561. XMEMSET(zeroData, 0, sizeof(zeroData));
  80562. for (i = 0; i < (int)sizeof(testSeed); i++) {
  80563. testSeed[i] = (byte)i;
  80564. }
  80565. ExpectNotNull(dctx = FIPS_get_default_drbg());
  80566. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  80567. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  80568. WOLFSSL_SUCCESS);
  80569. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  80570. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  80571. WOLFSSL_SUCCESS);
  80572. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80573. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  80574. WOLFSSL_SUCCESS);
  80575. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  80576. WOLFSSL_SUCCESS);
  80577. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80578. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  80579. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  80580. #ifndef HAVE_GLOBAL_RNG
  80581. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  80582. wolfSSL_FIPS_drbg_free(dctx);
  80583. #endif
  80584. #endif
  80585. return EXPECT_RESULT();
  80586. }
  80587. static int test_wolfSSL_FIPS_mode(void)
  80588. {
  80589. EXPECT_DECLS;
  80590. #if defined(OPENSSL_ALL)
  80591. #ifdef HAVE_FIPS
  80592. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  80593. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80594. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  80595. #else
  80596. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  80597. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  80598. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80599. #endif
  80600. #endif
  80601. return EXPECT_RESULT();
  80602. }
  80603. #ifdef WOLFSSL_DTLS
  80604. /* Prints out the current window */
  80605. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  80606. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80607. int i;
  80608. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  80609. word32 b = w[i];
  80610. int j;
  80611. /* Prints out a 32 bit binary number in big endian order */
  80612. for (j = 0; j < 32; j++, b <<= 1) {
  80613. if (b & (((word32)1) << 31))
  80614. fprintf(stderr, "1");
  80615. else
  80616. fprintf(stderr, "0");
  80617. }
  80618. fprintf(stderr, " ");
  80619. }
  80620. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  80621. #else
  80622. (void)h;
  80623. (void)l;
  80624. (void)w;
  80625. #endif
  80626. }
  80627. /* a - cur_hi
  80628. * b - cur_lo
  80629. * c - next_hi
  80630. * d - next_lo
  80631. * e - window
  80632. * f - expected next_hi
  80633. * g - expected next_lo
  80634. * h - expected window[1]
  80635. * i - expected window[0]
  80636. */
  80637. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  80638. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  80639. DUW_TEST_print_window_binary((a), (b), (e)); \
  80640. ExpectIntEQ((c), (f)); \
  80641. ExpectIntEQ((d), (g)); \
  80642. ExpectIntEQ((e)[1], (h)); \
  80643. ExpectIntEQ((e)[0], (i)); \
  80644. } while (0)
  80645. static int test_wolfSSL_DtlsUpdateWindow(void)
  80646. {
  80647. EXPECT_DECLS;
  80648. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  80649. word32 next_lo = 0;
  80650. word16 next_hi = 0;
  80651. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80652. fprintf(stderr, "\n");
  80653. #endif
  80654. XMEMSET(window, 0, sizeof window);
  80655. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  80656. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  80657. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  80658. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  80659. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  80660. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  80661. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  80662. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  80663. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  80664. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  80665. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  80666. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  80667. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  80668. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  80669. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  80670. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  80671. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  80672. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  80673. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  80674. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  80675. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  80676. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80677. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80678. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  80679. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  80680. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80681. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80682. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80683. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80684. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80685. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  80686. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  80687. return EXPECT_RESULT();
  80688. }
  80689. #endif /* WOLFSSL_DTLS */
  80690. #ifdef WOLFSSL_DTLS
  80691. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  80692. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  80693. {
  80694. DtlsMsg* cur;
  80695. static byte msg[100];
  80696. static byte msgInit = 0;
  80697. if (!msgInit) {
  80698. int i;
  80699. for (i = 0; i < 100; i++)
  80700. msg[i] = i + 1;
  80701. msgInit = 1;
  80702. }
  80703. /* Sanitize test parameters */
  80704. if (len > sizeof(msg))
  80705. return -1;
  80706. if (f_offset + f_len > sizeof(msg))
  80707. return -1;
  80708. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  80709. if (ssl->dtls_rx_msg_list == NULL)
  80710. return -100;
  80711. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  80712. return -200;
  80713. if (cur->fragBucketListCount != f_count)
  80714. return -300;
  80715. if (cur->ready != ready)
  80716. return -400;
  80717. if (cur->bytesReceived != bytesReceived)
  80718. return -500;
  80719. if (ready) {
  80720. if (cur->fragBucketList != NULL)
  80721. return -600;
  80722. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  80723. return -700;
  80724. }
  80725. else {
  80726. DtlsFragBucket* fb;
  80727. if (cur->fragBucketList == NULL)
  80728. return -800;
  80729. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  80730. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  80731. return -900;
  80732. }
  80733. }
  80734. return 0;
  80735. }
  80736. static int test_wolfSSL_DTLS_fragment_buckets(void)
  80737. {
  80738. EXPECT_DECLS;
  80739. WOLFSSL ssl[1];
  80740. XMEMSET(ssl, 0, sizeof(*ssl));
  80741. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  80742. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80743. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  80744. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  80745. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  80746. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  80747. /* Test all permutations of 3 regions */
  80748. /* 1 2 3 */
  80749. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80750. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  80751. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  80752. /* 1 3 2 */
  80753. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80754. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  80755. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  80756. /* 2 1 3 */
  80757. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  80758. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  80759. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  80760. /* 2 3 1 */
  80761. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  80762. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  80763. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  80764. /* 3 1 2 */
  80765. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  80766. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  80767. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  80768. /* 3 2 1 */
  80769. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  80770. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  80771. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  80772. /* Test overlapping regions */
  80773. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  80774. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  80775. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  80776. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  80777. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  80778. /* Test overlapping multiple regions */
  80779. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80780. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  80781. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  80782. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  80783. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  80784. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  80785. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  80786. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  80787. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  80788. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  80789. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  80790. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  80791. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  80792. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  80793. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  80794. ssl->dtls_rx_msg_list = NULL;
  80795. ssl->dtls_rx_msg_list_sz = 0;
  80796. return EXPECT_RESULT();
  80797. }
  80798. #endif
  80799. #if !defined(NO_FILESYSTEM) && \
  80800. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  80801. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  80802. static int test_wolfSSL_dtls_stateless2(void)
  80803. {
  80804. EXPECT_DECLS;
  80805. WOLFSSL *ssl_c = NULL;
  80806. WOLFSSL *ssl_c2 = NULL;
  80807. WOLFSSL *ssl_s = NULL;
  80808. struct test_memio_ctx test_ctx;
  80809. WOLFSSL_CTX *ctx_c = NULL;
  80810. WOLFSSL_CTX *ctx_s = NULL;
  80811. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80812. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80813. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80814. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  80815. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80816. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80817. /* send CH */
  80818. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80819. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80820. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80821. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80822. ExpectIntNE(test_ctx.c_len, 0);
  80823. /* consume HRR */
  80824. test_ctx.c_len = 0;
  80825. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80826. wolfSSL_free(ssl_c2);
  80827. wolfSSL_free(ssl_c);
  80828. wolfSSL_free(ssl_s);
  80829. wolfSSL_CTX_free(ctx_c);
  80830. wolfSSL_CTX_free(ctx_s);
  80831. return EXPECT_RESULT();
  80832. }
  80833. #ifdef HAVE_MAX_FRAGMENT
  80834. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  80835. {
  80836. EXPECT_DECLS;
  80837. WOLFSSL *ssl_c = NULL;
  80838. WOLFSSL *ssl_c2 = NULL;
  80839. WOLFSSL *ssl_s = NULL;
  80840. struct test_memio_ctx test_ctx;
  80841. WOLFSSL_CTX *ctx_c = NULL;
  80842. WOLFSSL_CTX *ctx_s = NULL;
  80843. word16 max_fragment = 0;
  80844. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80845. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80846. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80847. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  80848. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  80849. WOLFSSL_SUCCESS);
  80850. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80851. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80852. if (ssl_s != NULL) {
  80853. max_fragment = ssl_s->max_fragment;
  80854. }
  80855. /* send CH */
  80856. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80857. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80858. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80859. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80860. /* CH without cookie shouldn't change state */
  80861. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  80862. ExpectIntNE(test_ctx.c_len, 0);
  80863. /* consume HRR from buffer */
  80864. test_ctx.c_len = 0;
  80865. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80866. wolfSSL_free(ssl_c2);
  80867. wolfSSL_free(ssl_c);
  80868. wolfSSL_free(ssl_s);
  80869. wolfSSL_CTX_free(ctx_c);
  80870. wolfSSL_CTX_free(ctx_s);
  80871. return EXPECT_RESULT();
  80872. }
  80873. #endif /* HAVE_MAX_FRAGMENT */
  80874. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  80875. #define ROUNDS_WITH_HVR 4
  80876. #define ROUNDS_WITHOUT_HVR 2
  80877. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  80878. static int buf_is_hvr(const byte *data, int len)
  80879. {
  80880. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  80881. return 0;
  80882. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  80883. }
  80884. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  80885. {
  80886. EXPECT_DECLS;
  80887. struct test_memio_ctx test_ctx;
  80888. WOLFSSL_CTX *ctx_c = NULL;
  80889. WOLFSSL_CTX *ctx_s = NULL;
  80890. WOLFSSL *ssl_c = NULL;
  80891. WOLFSSL *ssl_s = NULL;
  80892. WOLFSSL_SESSION *sess = NULL;
  80893. int round_trips;
  80894. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80895. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  80896. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80897. #ifdef HAVE_SESSION_TICKET
  80898. if (useticket) {
  80899. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  80900. }
  80901. #endif
  80902. round_trips = ROUNDS_WITH_HVR;
  80903. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  80904. &round_trips), 0);
  80905. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  80906. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  80907. wolfSSL_shutdown(ssl_c);
  80908. wolfSSL_shutdown(ssl_s);
  80909. wolfSSL_free(ssl_c);
  80910. ssl_c = NULL;
  80911. wolfSSL_free(ssl_s);
  80912. ssl_s = NULL;
  80913. test_ctx.c_len = test_ctx.s_len = 0;
  80914. /* make resumption invalid */
  80915. if (bad && (sess != NULL)) {
  80916. if (useticket) {
  80917. #ifdef HAVE_SESSION_TICKET
  80918. if (sess->ticket != NULL) {
  80919. sess->ticket[0] = !sess->ticket[0];
  80920. }
  80921. #endif /* HAVE_SESSION_TICKET */
  80922. }
  80923. else {
  80924. sess->sessionID[0] = !sess->sessionID[0];
  80925. }
  80926. }
  80927. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  80928. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  80929. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  80930. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  80931. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  80932. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  80933. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  80934. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80935. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  80936. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80937. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80938. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  80939. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  80940. if (!useticket) {
  80941. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  80942. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  80943. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  80944. }
  80945. wolfSSL_SESSION_free(sess);
  80946. wolfSSL_free(ssl_c);
  80947. wolfSSL_free(ssl_s);
  80948. wolfSSL_CTX_free(ctx_c);
  80949. wolfSSL_CTX_free(ctx_s);
  80950. return EXPECT_RESULT();
  80951. }
  80952. static int test_wolfSSL_dtls_stateless_resume(void)
  80953. {
  80954. EXPECT_DECLS;
  80955. #ifdef HAVE_SESSION_TICKET
  80956. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  80957. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  80958. #endif /* HAVE_SESION_TICKET */
  80959. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  80960. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  80961. return EXPECT_RESULT();
  80962. }
  80963. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  80964. #if !defined(NO_OLD_TLS)
  80965. static int test_wolfSSL_dtls_stateless_downgrade(void)
  80966. {
  80967. EXPECT_DECLS;
  80968. WOLFSSL_CTX *ctx_c = NULL;
  80969. WOLFSSL_CTX *ctx_c2 = NULL;
  80970. WOLFSSL_CTX *ctx_s = NULL;
  80971. WOLFSSL *ssl_c = NULL;
  80972. WOLFSSL *ssl_c2 = NULL;
  80973. WOLFSSL *ssl_s = NULL;
  80974. struct test_memio_ctx test_ctx;
  80975. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  80976. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  80977. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  80978. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  80979. WOLFSSL_SUCCESS);
  80980. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  80981. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  80982. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  80983. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  80984. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  80985. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  80986. /* send CH */
  80987. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80988. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  80989. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  80990. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  80991. ExpectIntNE(test_ctx.c_len, 0);
  80992. /* consume HRR */
  80993. test_ctx.c_len = 0;
  80994. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  80995. wolfSSL_free(ssl_c2);
  80996. wolfSSL_free(ssl_c);
  80997. wolfSSL_free(ssl_s);
  80998. wolfSSL_CTX_free(ctx_c);
  80999. wolfSSL_CTX_free(ctx_c2);
  81000. wolfSSL_CTX_free(ctx_s);
  81001. return EXPECT_RESULT();
  81002. }
  81003. #endif /* !defined(NO_OLD_TLS) */
  81004. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81005. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  81006. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81007. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81008. static int test_WOLFSSL_dtls_version_alert(void)
  81009. {
  81010. EXPECT_DECLS;
  81011. struct test_memio_ctx test_ctx;
  81012. WOLFSSL_CTX *ctx_c = NULL;
  81013. WOLFSSL_CTX *ctx_s = NULL;
  81014. WOLFSSL *ssl_c = NULL;
  81015. WOLFSSL *ssl_s = NULL;
  81016. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81017. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81018. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  81019. /* client hello */
  81020. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81021. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81022. /* hrr */
  81023. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81024. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81025. /* client hello 1 */
  81026. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81027. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81028. /* server hello */
  81029. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81030. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81031. /* should fail */
  81032. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81033. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  81034. /* shuould fail */
  81035. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81036. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  81037. wolfSSL_free(ssl_c);
  81038. wolfSSL_free(ssl_s);
  81039. wolfSSL_CTX_free(ctx_c);
  81040. wolfSSL_CTX_free(ctx_s);
  81041. return EXPECT_RESULT();
  81042. }
  81043. #else
  81044. static int test_WOLFSSL_dtls_version_alert(void)
  81045. {
  81046. return TEST_SKIPPED;
  81047. }
  81048. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  81049. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  81050. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  81051. */
  81052. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  81053. && defined(WOLFSSL_TLS13) && \
  81054. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  81055. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81056. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  81057. {
  81058. struct test_memio_ctx *test_ctx;
  81059. byte buf[2048];
  81060. int idx, sz;
  81061. word32 tmp;
  81062. int ret;
  81063. idx = 5; /* space for record header */
  81064. buf[idx] = session_ticket; /* type */
  81065. idx++;
  81066. tmp = OPAQUE32_LEN +
  81067. OPAQUE32_LEN +
  81068. OPAQUE8_LEN + nonceLength +
  81069. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  81070. c32to24(tmp, buf + idx);
  81071. idx += OPAQUE24_LEN;
  81072. c32toa((word32)12345, buf+idx); /* lifetime */
  81073. idx += OPAQUE32_LEN;
  81074. c32toa((word32)12345, buf+idx); /* add */
  81075. idx += OPAQUE32_LEN;
  81076. buf[idx] = nonceLength; /* nonce length */
  81077. idx++;
  81078. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  81079. idx += nonceLength;
  81080. tmp = 1; /* ticket len */
  81081. c16toa((word16)tmp, buf+idx);
  81082. idx += 2;
  81083. buf[idx] = 0xFF; /* ticket */
  81084. idx++;
  81085. tmp = 0; /* ext len */
  81086. c16toa((word16)tmp, buf+idx);
  81087. idx += 2;
  81088. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  81089. handshake, 0, 0, 0);
  81090. AssertIntGT(sz, 0);
  81091. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  81092. AssertNotNull(test_ctx);
  81093. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  81094. return !(ret == sz);
  81095. }
  81096. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  81097. {
  81098. int ret = 0;
  81099. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  81100. ret = -1;
  81101. }
  81102. else {
  81103. int i;
  81104. for (i = 0; i < len; i++) {
  81105. if (sess->ticketNonce.data[i] != len) {
  81106. ret = -1;
  81107. break;
  81108. }
  81109. }
  81110. }
  81111. return ret;
  81112. }
  81113. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81114. {
  81115. EXPECT_DECLS;
  81116. char *buf[1024];
  81117. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  81118. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81119. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81120. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  81121. return EXPECT_RESULT();
  81122. }
  81123. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81124. {
  81125. EXPECT_DECLS;
  81126. WOLFSSL_SESSION *sess = NULL;
  81127. WOLFSSL_SESSION *cached = NULL;
  81128. WOLFSSL_CTX *ctx = ssl_c->ctx;
  81129. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  81130. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81131. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  81132. NULL, ssl_c->options.side, 1,NULL), 0);
  81133. ExpectNotNull(cached = wolfSSL_SESSION_new());
  81134. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  81135. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  81136. wolfSSL_SESSION_free(cached);
  81137. wolfSSL_SESSION_free(sess);
  81138. return EXPECT_RESULT();
  81139. }
  81140. static int test_ticket_nonce_malloc(void)
  81141. {
  81142. EXPECT_DECLS;
  81143. struct test_memio_ctx test_ctx;
  81144. WOLFSSL_CTX *ctx_c = NULL;
  81145. WOLFSSL_CTX *ctx_s = NULL;
  81146. WOLFSSL *ssl_c = NULL;
  81147. WOLFSSL *ssl_s = NULL;
  81148. byte small;
  81149. byte medium;
  81150. byte big;
  81151. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81152. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81153. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81154. /* will send ticket manually */
  81155. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  81156. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81157. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81158. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  81159. (ssl_s->options.handShakeDone == 0)) {
  81160. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  81161. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81162. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  81163. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81164. }
  81165. small = TLS13_TICKET_NONCE_STATIC_SZ;
  81166. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  81167. medium = small + 20;
  81168. #else
  81169. medium = 255;
  81170. #endif
  81171. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  81172. big = small + 20;
  81173. #else
  81174. big = 255;
  81175. #endif
  81176. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81177. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  81178. ssl_c->session->ticketNonce.dataStatic);
  81179. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81180. TEST_SUCCESS);
  81181. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  81182. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81183. TEST_SUCCESS);
  81184. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81185. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81186. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81187. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  81188. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81189. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81190. wolfSSL_free(ssl_c);
  81191. wolfSSL_free(ssl_s);
  81192. wolfSSL_CTX_free(ctx_c);
  81193. wolfSSL_CTX_free(ctx_s);
  81194. return EXPECT_RESULT();
  81195. }
  81196. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  81197. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  81198. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  81199. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  81200. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  81201. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81202. static int test_ticket_ret_create(void)
  81203. {
  81204. EXPECT_DECLS;
  81205. WOLFSSL_CTX *ctx_c = NULL;
  81206. WOLFSSL_CTX *ctx_s = NULL;
  81207. WOLFSSL *ssl_c = NULL;
  81208. WOLFSSL *ssl_s = NULL;
  81209. byte ticket[SESSION_TICKET_LEN];
  81210. struct test_memio_ctx test_ctx;
  81211. WOLFSSL_SESSION *sess = NULL;
  81212. word16 ticketLen = 0;
  81213. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81214. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81215. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81216. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81217. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81218. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  81219. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81220. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81221. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  81222. if (sess != NULL) {
  81223. ticketLen = sess->ticketLen;
  81224. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  81225. }
  81226. wolfSSL_free(ssl_c);
  81227. ssl_c = NULL;
  81228. wolfSSL_free(ssl_s);
  81229. ssl_s = NULL;
  81230. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81231. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81232. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81233. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81234. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81235. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81236. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81237. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81238. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  81239. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  81240. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  81241. wolfSSL_SESSION_free(sess);
  81242. wolfSSL_free(ssl_c);
  81243. wolfSSL_free(ssl_s);
  81244. wolfSSL_CTX_free(ctx_c);
  81245. wolfSSL_CTX_free(ctx_s);
  81246. return EXPECT_RESULT();
  81247. }
  81248. #else
  81249. static int test_ticket_ret_create(void)
  81250. {
  81251. return TEST_SKIPPED;
  81252. }
  81253. #endif
  81254. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  81255. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  81256. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81257. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81258. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81259. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  81260. {
  81261. int ret;
  81262. WOLFSSL_SESSION* session = NULL;
  81263. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81264. if (!wolfSSL_is_server(ssl)) {
  81265. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81266. AssertNotNull(session);
  81267. }
  81268. do {
  81269. ret = wolfSSL_shutdown(ssl);
  81270. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81271. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81272. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81273. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81274. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81275. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81276. #endif
  81277. if (!wolfSSL_is_server(ssl)) {
  81278. /* client */
  81279. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81280. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81281. wolfSSL_set_session(ssl, session);
  81282. wolfSSL_SESSION_free(session);
  81283. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81284. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81285. }
  81286. else {
  81287. /* server */
  81288. /* Different ciphersuite so that the ticket will be invalidated based on
  81289. * the ciphersuite */
  81290. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  81291. WOLFSSL_SUCCESS);
  81292. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  81293. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81294. }
  81295. }
  81296. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  81297. {
  81298. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  81299. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81300. WOLFSSL_SUCCESS);
  81301. }
  81302. static int test_ticket_and_psk_mixing(void)
  81303. {
  81304. EXPECT_DECLS;
  81305. /* Test mixing tickets and regular PSK */
  81306. callback_functions client_cbs, server_cbs;
  81307. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81308. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81309. client_cbs.method = wolfTLSv1_3_client_method;
  81310. server_cbs.method = wolfTLSv1_3_server_method;
  81311. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  81312. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81313. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81314. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81315. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81316. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81317. return EXPECT_RESULT();
  81318. }
  81319. #else
  81320. static int test_ticket_and_psk_mixing(void)
  81321. {
  81322. return TEST_SKIPPED;
  81323. }
  81324. #endif
  81325. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  81326. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  81327. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81328. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81329. static int test_prioritize_psk_cb_called = FALSE;
  81330. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  81331. const char* identity, unsigned char* key, unsigned int key_max_len,
  81332. const char** ciphersuite)
  81333. {
  81334. test_prioritize_psk_cb_called = TRUE;
  81335. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  81336. }
  81337. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  81338. {
  81339. int ret;
  81340. WOLFSSL_SESSION* session = NULL;
  81341. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81342. if (!wolfSSL_is_server(ssl)) {
  81343. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81344. AssertNotNull(session);
  81345. }
  81346. do {
  81347. ret = wolfSSL_shutdown(ssl);
  81348. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81349. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81350. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81351. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  81352. * important. */
  81353. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81354. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81355. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81356. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81357. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81358. #endif
  81359. if (!wolfSSL_is_server(ssl)) {
  81360. /* client */
  81361. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81362. wolfSSL_set_session(ssl, session);
  81363. wolfSSL_SESSION_free(session);
  81364. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81365. }
  81366. else {
  81367. /* server */
  81368. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  81369. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81370. #ifdef WOLFSSL_PRIORITIZE_PSK
  81371. /* The ticket should be first tried with all ciphersuites and chosen */
  81372. AssertFalse(test_prioritize_psk_cb_called);
  81373. #else
  81374. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  81375. * callback that sets this var. */
  81376. AssertTrue(test_prioritize_psk_cb_called);
  81377. #endif
  81378. }
  81379. }
  81380. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  81381. {
  81382. if (!wolfSSL_is_server(ssl))
  81383. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81384. WOLFSSL_SUCCESS);
  81385. else
  81386. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81387. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81388. }
  81389. static int test_prioritize_psk(void)
  81390. {
  81391. EXPECT_DECLS;
  81392. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  81393. * of the PSK's will be followed instead of the ciphersuite. */
  81394. callback_functions client_cbs, server_cbs;
  81395. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81396. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81397. client_cbs.method = wolfTLSv1_3_client_method;
  81398. server_cbs.method = wolfTLSv1_3_server_method;
  81399. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81400. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81401. client_cbs.on_result = test_prioritize_psk_on_result;
  81402. server_cbs.on_result = test_prioritize_psk_on_result;
  81403. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81404. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81405. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81406. return EXPECT_RESULT();
  81407. }
  81408. #else
  81409. static int test_prioritize_psk(void)
  81410. {
  81411. return TEST_SKIPPED;
  81412. }
  81413. #endif
  81414. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  81415. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81416. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81417. !defined(WOLFSSL_NO_TLS12)
  81418. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  81419. {
  81420. EXPECT_DECLS;
  81421. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  81422. /* Set TLS 1.3 specific suite */
  81423. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  81424. return EXPECT_RESULT();
  81425. }
  81426. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81427. {
  81428. EXPECT_DECLS;
  81429. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  81430. * do a 1.2 connection. */
  81431. test_ssl_cbf client_cbs, server_cbs;
  81432. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81433. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81434. client_cbs.method = wolfTLSv1_2_client_method;
  81435. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  81436. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  81437. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81438. &server_cbs, NULL), TEST_SUCCESS);
  81439. return EXPECT_RESULT();
  81440. }
  81441. #else
  81442. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81443. {
  81444. return TEST_SKIPPED;
  81445. }
  81446. #endif
  81447. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  81448. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  81449. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  81450. {
  81451. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  81452. return TEST_SUCCESS;
  81453. }
  81454. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  81455. {
  81456. EXPECT_DECLS;
  81457. WOLFSSL_ALERT_HISTORY h;
  81458. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  81459. ExpectIntEQ(h.last_rx.level, alert_fatal);
  81460. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  81461. return EXPECT_RESULT();
  81462. }
  81463. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81464. {
  81465. EXPECT_DECLS;
  81466. test_ssl_cbf client_cbs, server_cbs;
  81467. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81468. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81469. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  81470. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  81471. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  81472. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  81473. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  81474. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81475. &server_cbs, NULL), TEST_FAIL);
  81476. return EXPECT_RESULT();
  81477. }
  81478. #else
  81479. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81480. {
  81481. return TEST_SKIPPED;
  81482. }
  81483. #endif
  81484. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  81485. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81486. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81487. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  81488. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  81489. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81490. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  81491. static int test_TLS_13_ticket_different_ciphers_run = 0;
  81492. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  81493. {
  81494. EXPECT_DECLS;
  81495. switch (test_TLS_13_ticket_different_ciphers_run) {
  81496. case 0:
  81497. /* First run */
  81498. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81499. WOLFSSL_SUCCESS);
  81500. if (wolfSSL_is_server(ssl)) {
  81501. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  81502. wolfSSL_get_SSL_CTX(ssl));
  81503. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  81504. test_TLS_13_ticket_different_ciphers_ctx));
  81505. }
  81506. break;
  81507. case 1:
  81508. /* Second run */
  81509. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81510. "TLS13-AES128-GCM-SHA256"),
  81511. WOLFSSL_SUCCESS);
  81512. if (!wolfSSL_is_server(ssl)) {
  81513. ExpectIntEQ(wolfSSL_set_session(ssl,
  81514. test_TLS_13_ticket_different_ciphers_session),
  81515. WOLFSSL_SUCCESS);
  81516. }
  81517. break;
  81518. default:
  81519. /* Bad state? */
  81520. Fail(("Should not enter here"), ("Should not enter here"));
  81521. }
  81522. return EXPECT_RESULT();
  81523. }
  81524. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  81525. {
  81526. EXPECT_DECLS;
  81527. switch (test_TLS_13_ticket_different_ciphers_run) {
  81528. case 0:
  81529. /* First run */
  81530. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  81531. wolfSSL_get1_session(ssl));
  81532. break;
  81533. case 1:
  81534. /* Second run */
  81535. ExpectTrue(wolfSSL_session_reused(ssl));
  81536. break;
  81537. default:
  81538. /* Bad state? */
  81539. Fail(("Should not enter here"), ("Should not enter here"));
  81540. }
  81541. return EXPECT_RESULT();
  81542. }
  81543. static int test_TLS_13_ticket_different_ciphers(void)
  81544. {
  81545. EXPECT_DECLS;
  81546. /* Check that we handle the connection when the ticket doesn't match
  81547. * the first ciphersuite. */
  81548. test_ssl_cbf client_cbs, server_cbs;
  81549. struct test_params {
  81550. method_provider client_meth;
  81551. method_provider server_meth;
  81552. int doUdp;
  81553. } params[] = {
  81554. #ifdef WOLFSSL_DTLS13
  81555. /* Test that the stateless code handles sessions correctly */
  81556. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  81557. #endif
  81558. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  81559. };
  81560. size_t i;
  81561. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  81562. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81563. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81564. test_TLS_13_ticket_different_ciphers_run = 0;
  81565. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  81566. client_cbs.method = params[i].client_meth;
  81567. server_cbs.method = params[i].server_meth;
  81568. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81569. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81570. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  81571. server_cbs.ticNoInit = 1;
  81572. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81573. &server_cbs, NULL), TEST_SUCCESS);
  81574. test_TLS_13_ticket_different_ciphers_run++;
  81575. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  81576. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81577. &server_cbs, NULL), TEST_SUCCESS);
  81578. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  81579. test_TLS_13_ticket_different_ciphers_session = NULL;
  81580. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  81581. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81582. }
  81583. return EXPECT_RESULT();
  81584. }
  81585. #else
  81586. static int test_TLS_13_ticket_different_ciphers(void)
  81587. {
  81588. return TEST_SKIPPED;
  81589. }
  81590. #endif
  81591. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  81592. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81593. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  81594. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  81595. byte test_extra_alerts_wrong_cs_sh[] = {
  81596. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  81597. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  81598. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  81599. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  81600. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  81601. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  81602. 0xbb, 0x07, 0x54, 0x1c,
  81603. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  81604. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81605. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81606. };
  81607. static int test_extra_alerts_wrong_cs(void)
  81608. {
  81609. EXPECT_DECLS;
  81610. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  81611. struct test_memio_ctx test_ctx;
  81612. WOLFSSL_CTX *ctx_c = NULL;
  81613. WOLFSSL_ALERT_HISTORY h;
  81614. WOLFSSL *ssl_c = NULL;
  81615. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81616. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81617. wolfTLSv1_2_client_method, NULL), 0);
  81618. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  81619. WOLFSSL_SUCCESS);
  81620. /* CH */
  81621. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81622. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81623. WOLFSSL_ERROR_WANT_READ);
  81624. /* consume CH */
  81625. test_ctx.s_len = 0;
  81626. /* inject SH */
  81627. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  81628. sizeof(test_extra_alerts_wrong_cs_sh));
  81629. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  81630. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81631. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81632. WOLFSSL_ERROR_WANT_READ);
  81633. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81634. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81635. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81636. wolfSSL_free(ssl_c);
  81637. wolfSSL_CTX_free(ctx_c);
  81638. #endif
  81639. return EXPECT_RESULT();
  81640. }
  81641. #else
  81642. static int test_extra_alerts_wrong_cs(void)
  81643. {
  81644. return TEST_SKIPPED;
  81645. }
  81646. #endif
  81647. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  81648. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81649. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  81650. byte test_wrong_cs_downgrade_sh[] = {
  81651. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  81652. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  81653. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  81654. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  81655. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  81656. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  81657. 0x85, 0xe5, 0x2f, 0x54,
  81658. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  81659. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81660. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81661. };
  81662. static int test_wrong_cs_downgrade(void)
  81663. {
  81664. EXPECT_DECLS;
  81665. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  81666. struct test_memio_ctx test_ctx;
  81667. WOLFSSL_CTX *ctx_c = NULL;
  81668. WOLFSSL *ssl_c = NULL;
  81669. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81670. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81671. wolfSSLv23_client_method, NULL), 0);
  81672. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  81673. WOLFSSL_SUCCESS);
  81674. /* CH */
  81675. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81676. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81677. WOLFSSL_ERROR_WANT_READ);
  81678. /* consume CH */
  81679. test_ctx.s_len = 0;
  81680. /* inject SH */
  81681. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  81682. sizeof(test_wrong_cs_downgrade_sh));
  81683. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  81684. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81685. #ifdef OPENSSL_EXTRA
  81686. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81687. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  81688. #else
  81689. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81690. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  81691. #endif /* OPENSSL_EXTRA */
  81692. wolfSSL_free(ssl_c);
  81693. wolfSSL_CTX_free(ctx_c);
  81694. #endif
  81695. return EXPECT_RESULT();
  81696. }
  81697. #else
  81698. static int test_wrong_cs_downgrade(void)
  81699. {
  81700. return TEST_SKIPPED;
  81701. }
  81702. #endif
  81703. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  81704. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  81705. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  81706. {
  81707. tail_len -= msg_length;
  81708. XMEMMOVE(msg, msg + msg_length, tail_len);
  81709. *len = *len - msg_length;
  81710. }
  81711. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  81712. byte *found)
  81713. {
  81714. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  81715. const unsigned int _RECORD_HEADER_SZ = 5;
  81716. const int _change_cipher_hs = 55;
  81717. const int _change_cipher = 20;
  81718. const int _handshake = 22;
  81719. unsigned int tail_len;
  81720. byte *idx, *curr;
  81721. word8 currType;
  81722. word16 rLength;
  81723. word32 hLength;
  81724. idx = buf;
  81725. tail_len = (unsigned int)*len;
  81726. *found = 0;
  81727. while (tail_len > _RECORD_HEADER_SZ) {
  81728. curr = idx;
  81729. currType = *idx;
  81730. ato16(idx + 3, &rLength);
  81731. idx += _RECORD_HEADER_SZ;
  81732. tail_len -= _RECORD_HEADER_SZ;
  81733. if (tail_len < rLength)
  81734. return -1;
  81735. if (type == _change_cipher_hs && currType == _change_cipher) {
  81736. if (rLength != 1)
  81737. return -1;
  81738. /* match */
  81739. test_remove_msg(curr, *len - (int)(curr - buf),
  81740. len, _RECORD_HEADER_SZ + 1);
  81741. *found = 1;
  81742. return 0;
  81743. }
  81744. if (currType != _handshake) {
  81745. idx += rLength;
  81746. tail_len -= rLength;
  81747. continue;
  81748. }
  81749. if (rLength < _HANDSHAKE_HEADER_SZ)
  81750. return -1;
  81751. currType = *idx;
  81752. ato24(idx+1, &hLength);
  81753. hLength += _HANDSHAKE_HEADER_SZ;
  81754. if (tail_len < hLength)
  81755. return -1;
  81756. if (currType != type) {
  81757. idx += hLength;
  81758. tail_len -= hLength;
  81759. continue;
  81760. }
  81761. /* match */
  81762. test_remove_msg(curr, *len - (int)(curr - buf), len,
  81763. hLength + _RECORD_HEADER_SZ);
  81764. *found = 1;
  81765. return 0;
  81766. }
  81767. /* not found */
  81768. return 0;
  81769. }
  81770. static int test_remove_hs_message(byte hs_message_type,
  81771. int extra_round, byte alert_type)
  81772. {
  81773. EXPECT_DECLS;
  81774. WOLFSSL_CTX *ctx_c = NULL;
  81775. WOLFSSL_CTX *ctx_s = NULL;
  81776. WOLFSSL *ssl_c = NULL;
  81777. WOLFSSL *ssl_s = NULL;
  81778. struct test_memio_ctx test_ctx;
  81779. WOLFSSL_ALERT_HISTORY h;
  81780. byte found = 0;
  81781. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81782. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81783. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81784. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81785. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81786. WOLFSSL_ERROR_WANT_READ);
  81787. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81788. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81789. WOLFSSL_ERROR_WANT_READ);
  81790. if (extra_round) {
  81791. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81792. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81793. WOLFSSL_ERROR_WANT_READ);
  81794. /* this will complete handshake from server side */
  81795. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81796. }
  81797. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  81798. &test_ctx.c_len, hs_message_type, &found), 0);
  81799. if (!found) {
  81800. wolfSSL_free(ssl_c);
  81801. wolfSSL_CTX_free(ctx_c);
  81802. wolfSSL_free(ssl_s);
  81803. wolfSSL_CTX_free(ctx_s);
  81804. return TEST_SKIPPED;
  81805. }
  81806. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81807. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81808. WOLFSSL_ERROR_WANT_READ);
  81809. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81810. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  81811. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81812. wolfSSL_free(ssl_c);
  81813. wolfSSL_CTX_free(ctx_c);
  81814. wolfSSL_free(ssl_s);
  81815. wolfSSL_CTX_free(ctx_s);
  81816. return EXPECT_RESULT();
  81817. }
  81818. static int test_extra_alerts_skip_hs(void)
  81819. {
  81820. EXPECT_DECLS;
  81821. const byte _server_key_exchange = 12;
  81822. const byte _server_hello = 2;
  81823. const byte _certificate = 11;
  81824. /* server_hello */
  81825. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  81826. unexpected_message), TEST_FAIL);
  81827. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  81828. 0xff), TEST_FAIL);
  81829. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  81830. unexpected_message), TEST_FAIL);
  81831. return EXPECT_RESULT();
  81832. }
  81833. #else
  81834. static int test_extra_alerts_skip_hs(void)
  81835. {
  81836. return TEST_SKIPPED;
  81837. }
  81838. #endif
  81839. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81840. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  81841. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  81842. unsigned char* key, unsigned int key_max_len)
  81843. {
  81844. (void)ssl;
  81845. (void)id;
  81846. (void)key_max_len;
  81847. /* zero means error */
  81848. key[0] = 0x10;
  81849. return 1;
  81850. }
  81851. static int test_extra_alerts_bad_psk(void)
  81852. {
  81853. EXPECT_DECLS;
  81854. WOLFSSL_CTX *ctx_c = NULL;
  81855. WOLFSSL_CTX *ctx_s = NULL;
  81856. WOLFSSL *ssl_c = NULL;
  81857. WOLFSSL *ssl_s = NULL;
  81858. struct test_memio_ctx test_ctx;
  81859. WOLFSSL_ALERT_HISTORY h;
  81860. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81861. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81862. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81863. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  81864. WOLFSSL_SUCCESS);
  81865. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  81866. WOLFSSL_SUCCESS);
  81867. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  81868. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81869. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81870. WOLFSSL_ERROR_WANT_READ);
  81871. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  81872. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81873. WOLFSSL_ERROR_WANT_READ);
  81874. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81875. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81876. WOLFSSL_ERROR_WANT_READ);
  81877. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81878. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81879. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81880. wolfSSL_free(ssl_c);
  81881. wolfSSL_CTX_free(ctx_c);
  81882. wolfSSL_free(ssl_s);
  81883. wolfSSL_CTX_free(ctx_s);
  81884. return EXPECT_RESULT();
  81885. }
  81886. #else
  81887. static int test_extra_alerts_bad_psk(void)
  81888. {
  81889. return TEST_SKIPPED;
  81890. }
  81891. #endif
  81892. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  81893. /*
  81894. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  81895. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  81896. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  81897. int sz, void *ctx)
  81898. {
  81899. (void)ssl;
  81900. (void)buf;
  81901. (void)ctx;
  81902. (void)sz;
  81903. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  81904. }
  81905. static int test_multiple_alerts_EAGAIN(void)
  81906. {
  81907. EXPECT_DECLS;
  81908. size_t size_of_last_packet = 0;
  81909. /* declare wolfSSL objects */
  81910. struct test_memio_ctx test_ctx;
  81911. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  81912. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  81913. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81914. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  81915. #ifdef USE_TLSV13
  81916. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81917. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81918. #else
  81919. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81920. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81921. #endif
  81922. ExpectNotNull(ctx_c);
  81923. ExpectNotNull(ssl_c);
  81924. ExpectNotNull(ctx_s);
  81925. ExpectNotNull(ssl_s);
  81926. /* Load client certificates into WOLFSSL_CTX */
  81927. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  81928. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81929. /*
  81930. * We set the custom callback for the IO to emulate multiple EAGAINs
  81931. * on shutdown, so we can check that we don't send multiple packets.
  81932. * */
  81933. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  81934. /*
  81935. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  81936. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  81937. * on the output buffer.
  81938. * */
  81939. wolfSSL_shutdown(ssl_c);
  81940. wolfSSL_shutdown(ssl_c);
  81941. if (ssl_c != NULL) {
  81942. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  81943. }
  81944. wolfSSL_shutdown(ssl_c);
  81945. /*
  81946. * Finally we check the length of the output buffer.
  81947. * */
  81948. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  81949. /* Cleanup and return */
  81950. wolfSSL_CTX_free(ctx_c);
  81951. wolfSSL_free(ssl_c);
  81952. wolfSSL_CTX_free(ctx_s);
  81953. wolfSSL_free(ssl_s);
  81954. return EXPECT_RESULT();
  81955. }
  81956. #else
  81957. static int test_multiple_alerts_EAGAIN(void)
  81958. {
  81959. return TEST_SKIPPED;
  81960. }
  81961. #endif
  81962. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81963. && !defined(NO_PSK)
  81964. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  81965. const char* hint, char* identity, unsigned int id_max_len,
  81966. unsigned char* key, unsigned int key_max_len)
  81967. {
  81968. (void)ssl;
  81969. (void)hint;
  81970. (void)key_max_len;
  81971. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  81972. XSTRNCPY(identity, "Client_identity", id_max_len);
  81973. key[0] = 0x20;
  81974. return 1;
  81975. }
  81976. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  81977. const char* id, unsigned char* key, unsigned int key_max_len)
  81978. {
  81979. (void)ssl;
  81980. (void)id;
  81981. (void)key_max_len;
  81982. /* zero means error */
  81983. key[0] = 0x10;
  81984. return 1;
  81985. }
  81986. #endif
  81987. static int test_tls13_bad_psk_binder(void)
  81988. {
  81989. EXPECT_DECLS;
  81990. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  81991. && !defined(NO_PSK)
  81992. WOLFSSL_CTX *ctx_c = NULL;
  81993. WOLFSSL_CTX *ctx_s = NULL;
  81994. WOLFSSL *ssl_c = NULL;
  81995. WOLFSSL *ssl_s = NULL;
  81996. struct test_memio_ctx test_ctx;
  81997. WOLFSSL_ALERT_HISTORY h;
  81998. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81999. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82000. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82001. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  82002. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  82003. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82004. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82005. WOLFSSL_ERROR_WANT_READ);
  82006. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82007. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82008. WC_NO_ERR_TRACE(BAD_BINDER));
  82009. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82010. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82011. WC_NO_ERR_TRACE(FATAL_ERROR));
  82012. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82013. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  82014. ExpectIntEQ(h.last_rx.level, alert_fatal);
  82015. wolfSSL_free(ssl_c);
  82016. wolfSSL_CTX_free(ctx_c);
  82017. wolfSSL_free(ssl_s);
  82018. wolfSSL_CTX_free(ctx_s);
  82019. #endif
  82020. return EXPECT_RESULT();
  82021. }
  82022. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  82023. defined(HAVE_IO_TESTS_DEPENDENCIES)
  82024. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  82025. int sz, void *ctx)
  82026. {
  82027. static int sentServerHello = FALSE;
  82028. if (!sentServerHello) {
  82029. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  82030. size_t i;
  82031. if (sz < (int)sizeof(renegExt))
  82032. return WOLFSSL_CBIO_ERR_GENERAL;
  82033. /* Remove SCR from ServerHello */
  82034. for (i = 0; i < sz - sizeof(renegExt); i++) {
  82035. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  82036. /* Found the extension. Change it to something unrecognized. */
  82037. buf[i+1] = 0x11;
  82038. break;
  82039. }
  82040. }
  82041. sentServerHello = TRUE;
  82042. }
  82043. return EmbedSend(ssl, buf, sz, ctx);
  82044. }
  82045. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  82046. {
  82047. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  82048. }
  82049. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  82050. {
  82051. WOLFSSL_ALERT_HISTORY h;
  82052. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  82053. AssertIntEQ(h.last_rx.code, handshake_failure);
  82054. AssertIntEQ(h.last_rx.level, alert_fatal);
  82055. }
  82056. static int test_harden_no_secure_renegotiation(void)
  82057. {
  82058. EXPECT_DECLS;
  82059. callback_functions client_cbs, server_cbs;
  82060. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82061. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82062. client_cbs.method = wolfTLSv1_2_client_method;
  82063. server_cbs.method = wolfTLSv1_2_server_method;
  82064. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  82065. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  82066. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82067. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  82068. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  82069. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  82070. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  82071. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  82072. return EXPECT_RESULT();
  82073. }
  82074. #else
  82075. static int test_harden_no_secure_renegotiation(void)
  82076. {
  82077. return TEST_SKIPPED;
  82078. }
  82079. #endif
  82080. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  82081. static int test_override_alt_cert_chain_cert_cb(int preverify,
  82082. WOLFSSL_X509_STORE_CTX* store)
  82083. {
  82084. fprintf(stderr, "preverify: %d\n", preverify);
  82085. fprintf(stderr, "store->error: %d\n", store->error);
  82086. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  82087. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  82088. fprintf(stderr, "Overriding OCSP error\n");
  82089. return 1;
  82090. }
  82091. #ifndef WOLFSSL_ALT_CERT_CHAINS
  82092. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  82093. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  82094. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  82095. defined(HAVE_WEBSERVER)
  82096. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  82097. #endif
  82098. ) && store->error_depth == store->totalCerts - 1) {
  82099. fprintf(stderr, "Overriding no signer error only for root cert\n");
  82100. return 1;
  82101. }
  82102. #endif
  82103. else
  82104. return preverify;
  82105. }
  82106. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  82107. int urlSz, unsigned char* request, int requestSz,
  82108. unsigned char** response)
  82109. {
  82110. (void)ioCtx;
  82111. (void)url;
  82112. (void)urlSz;
  82113. (void)request;
  82114. (void)requestSz;
  82115. (void)response;
  82116. return -1;
  82117. }
  82118. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  82119. {
  82120. EXPECT_DECLS;
  82121. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  82122. test_override_alt_cert_chain_cert_cb);
  82123. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82124. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82125. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82126. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82127. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82128. WOLFSSL_SUCCESS);
  82129. return EXPECT_RESULT();
  82130. }
  82131. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  82132. {
  82133. EXPECT_DECLS;
  82134. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  82135. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82136. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82137. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82138. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82139. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82140. WOLFSSL_SUCCESS);
  82141. return EXPECT_RESULT();
  82142. }
  82143. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  82144. {
  82145. EXPECT_DECLS;
  82146. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  82147. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  82148. return EXPECT_RESULT();
  82149. }
  82150. static int test_override_alt_cert_chain(void)
  82151. {
  82152. EXPECT_DECLS;
  82153. size_t i;
  82154. struct test_params {
  82155. ctx_cb client_ctx_cb;
  82156. ctx_cb server_ctx_cb;
  82157. int result;
  82158. } params[] = {
  82159. {test_override_alt_cert_chain_client_ctx_ready,
  82160. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  82161. {test_override_alt_cert_chain_client_ctx_ready2,
  82162. test_override_alt_cert_chain_server_ctx_ready, TEST_FAIL},
  82163. };
  82164. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  82165. test_ssl_cbf client_cbs, server_cbs;
  82166. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82167. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82168. fprintf(stderr, "test config: %d\n", (int)i);
  82169. client_cbs.ctx_ready = params[i].client_ctx_cb;
  82170. server_cbs.ctx_ready = params[i].server_ctx_cb;
  82171. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82172. &server_cbs, NULL), params[i].result);
  82173. ExpectIntEQ(client_cbs.return_code, params[i].result);
  82174. ExpectIntEQ(server_cbs.return_code, params[i].result);
  82175. }
  82176. return EXPECT_RESULT();
  82177. }
  82178. #else
  82179. static int test_override_alt_cert_chain(void)
  82180. {
  82181. return TEST_SKIPPED;
  82182. }
  82183. #endif
  82184. #if defined(HAVE_RPK)
  82185. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  82186. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  82187. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82188. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  82189. {
  82190. int ret = WOLFSSL_SUCCESS;
  82191. (void)mode;
  82192. (void)strctx;
  82193. WOLFSSL_ENTER("MyRpkVerifyCb");
  82194. return ret;
  82195. }
  82196. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  82197. static WC_INLINE int test_rpk_memio_setup(
  82198. struct test_memio_ctx *ctx,
  82199. WOLFSSL_CTX **ctx_c,
  82200. WOLFSSL_CTX **ctx_s,
  82201. WOLFSSL **ssl_c,
  82202. WOLFSSL **ssl_s,
  82203. method_provider method_c,
  82204. method_provider method_s,
  82205. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  82206. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  82207. const char* pkey_c, int fmt_kc, /* client private key and format */
  82208. const char* pkey_s, int fmt_ks /* server private key and format */
  82209. )
  82210. {
  82211. int ret;
  82212. if (ctx_c != NULL && *ctx_c == NULL) {
  82213. *ctx_c = wolfSSL_CTX_new(method_c());
  82214. if (*ctx_c == NULL) {
  82215. return -1;
  82216. }
  82217. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  82218. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  82219. if (ret != WOLFSSL_SUCCESS) {
  82220. return -1;
  82221. }
  82222. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  82223. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  82224. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  82225. if (ret != WOLFSSL_SUCCESS) {
  82226. return -1;
  82227. }
  82228. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  82229. if (ret != WOLFSSL_SUCCESS) {
  82230. return -1;
  82231. }
  82232. }
  82233. if (ctx_s != NULL && *ctx_s == NULL) {
  82234. *ctx_s = wolfSSL_CTX_new(method_s());
  82235. if (*ctx_s == NULL) {
  82236. return -1;
  82237. }
  82238. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  82239. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  82240. if (ret != WOLFSSL_SUCCESS) {
  82241. return -1;
  82242. }
  82243. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  82244. if (ret != WOLFSSL_SUCCESS) {
  82245. return -1;
  82246. }
  82247. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  82248. if (ret != WOLFSSL_SUCCESS) {
  82249. return -1;
  82250. }
  82251. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  82252. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  82253. if (ctx->s_ciphers != NULL) {
  82254. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  82255. if (ret != WOLFSSL_SUCCESS) {
  82256. return -1;
  82257. }
  82258. }
  82259. }
  82260. if (ctx_c != NULL && ssl_c != NULL) {
  82261. *ssl_c = wolfSSL_new(*ctx_c);
  82262. if (*ssl_c == NULL) {
  82263. return -1;
  82264. }
  82265. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  82266. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  82267. }
  82268. if (ctx_s != NULL && ssl_s != NULL) {
  82269. *ssl_s = wolfSSL_new(*ctx_s);
  82270. if (*ssl_s == NULL) {
  82271. return -1;
  82272. }
  82273. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  82274. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  82275. #if !defined(NO_DH)
  82276. SetDH(*ssl_s);
  82277. #endif
  82278. }
  82279. return 0;
  82280. }
  82281. #endif /* HAVE_RPK */
  82282. static int test_rpk_set_xxx_cert_type(void)
  82283. {
  82284. EXPECT_DECLS;
  82285. #if defined(HAVE_RPK)
  82286. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  82287. WOLFSSL_CTX* ctx = NULL;
  82288. WOLFSSL* ssl = NULL;
  82289. int tp;
  82290. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  82291. ExpectNotNull(ctx);
  82292. ssl = wolfSSL_new(ctx);
  82293. ExpectNotNull(ssl);
  82294. /*--------------------------------------------*/
  82295. /* tests for wolfSSL_CTX_set_client_cert_type */
  82296. /*--------------------------------------------*/
  82297. /* illegal parameter test caces */
  82298. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  82299. MAX_CLIENT_CERT_TYPE_CNT),
  82300. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82301. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82302. sizeof(ctype)),
  82303. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82304. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82305. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82306. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82307. MAX_CLIENT_CERT_TYPE_CNT),
  82308. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82309. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82310. ctype[1] = 10; /* set unknown cert type */
  82311. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82312. MAX_CLIENT_CERT_TYPE_CNT),
  82313. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82314. /* pass larger type count */
  82315. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82316. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82317. ctype[2] = 1; /* pass unacceptable type count */
  82318. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82319. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82321. /* should accept NULL for type buffer */
  82322. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  82323. MAX_CLIENT_CERT_TYPE_CNT),
  82324. WOLFSSL_SUCCESS);
  82325. /* should accept zero for type count */
  82326. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82327. 0),
  82328. WOLFSSL_SUCCESS);
  82329. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82330. MAX_CLIENT_CERT_TYPE_CNT),
  82331. WOLFSSL_SUCCESS);
  82332. /*--------------------------------------------*/
  82333. /* tests for wolfSSL_CTX_set_server_cert_type */
  82334. /*--------------------------------------------*/
  82335. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  82336. MAX_SERVER_CERT_TYPE_CNT),
  82337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82338. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82339. sizeof(ctype)),
  82340. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82341. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82342. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82343. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82344. MAX_SERVER_CERT_TYPE_CNT),
  82345. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82346. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82347. ctype[1] = 10; /* set unknown cert type */
  82348. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82349. MAX_SERVER_CERT_TYPE_CNT),
  82350. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82351. /* pass larger type count */
  82352. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82353. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82354. ctype[2] = 1; /* pass unacceptable type count */
  82355. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82356. MAX_SERVER_CERT_TYPE_CNT + 1),
  82357. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82358. /* should accept NULL for type buffer */
  82359. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  82360. MAX_SERVER_CERT_TYPE_CNT),
  82361. WOLFSSL_SUCCESS);
  82362. /* should accept zero for type count */
  82363. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82364. 0),
  82365. WOLFSSL_SUCCESS);
  82366. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82367. MAX_CLIENT_CERT_TYPE_CNT),
  82368. WOLFSSL_SUCCESS);
  82369. /*--------------------------------------------*/
  82370. /* tests for wolfSSL_set_client_cert_type */
  82371. /*--------------------------------------------*/
  82372. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  82373. MAX_CLIENT_CERT_TYPE_CNT),
  82374. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82375. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82376. sizeof(ctype)),
  82377. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82378. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82379. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82380. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82381. MAX_CLIENT_CERT_TYPE_CNT),
  82382. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82383. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82384. ctype[1] = 10; /* set unknown cert type */
  82385. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82386. MAX_CLIENT_CERT_TYPE_CNT),
  82387. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82388. /* pass larger type count */
  82389. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82390. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82391. ctype[2] = 1; /* pass unacceptable type count */
  82392. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82393. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82394. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82395. /* should accept NULL for type buffer */
  82396. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  82397. MAX_CLIENT_CERT_TYPE_CNT),
  82398. WOLFSSL_SUCCESS);
  82399. /* should accept zero for type count */
  82400. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82401. 0),
  82402. WOLFSSL_SUCCESS);
  82403. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82404. MAX_CLIENT_CERT_TYPE_CNT),
  82405. WOLFSSL_SUCCESS);
  82406. /*--------------------------------------------*/
  82407. /* tests for wolfSSL_CTX_set_server_cert_type */
  82408. /*--------------------------------------------*/
  82409. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  82410. MAX_SERVER_CERT_TYPE_CNT),
  82411. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82412. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82413. sizeof(ctype)),
  82414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82415. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82416. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82417. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82418. MAX_SERVER_CERT_TYPE_CNT),
  82419. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82420. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82421. ctype[1] = 10; /* set unknown cert type */
  82422. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82423. MAX_SERVER_CERT_TYPE_CNT),
  82424. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82425. /* pass larger type count */
  82426. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82427. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82428. ctype[2] = 1; /* pass unacceptable type count */
  82429. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82430. MAX_SERVER_CERT_TYPE_CNT + 1),
  82431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82432. /* should accept NULL for type buffer */
  82433. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  82434. MAX_SERVER_CERT_TYPE_CNT),
  82435. WOLFSSL_SUCCESS);
  82436. /* should accept zero for type count */
  82437. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82438. 0),
  82439. WOLFSSL_SUCCESS);
  82440. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82441. MAX_SERVER_CERT_TYPE_CNT),
  82442. WOLFSSL_SUCCESS);
  82443. /*------------------------------------------------*/
  82444. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  82445. /*------------------------------------------------*/
  82446. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  82447. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82448. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  82449. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82450. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  82451. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82452. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  82453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82454. /* clean up */
  82455. wolfSSL_free(ssl);
  82456. wolfSSL_CTX_free(ctx);
  82457. #endif
  82458. return EXPECT_RESULT();
  82459. }
  82460. static int test_tls13_rpk_handshake(void)
  82461. {
  82462. EXPECT_DECLS;
  82463. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  82464. #ifdef WOLFSSL_TLS13
  82465. int ret = 0;
  82466. #endif
  82467. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82468. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82469. struct test_memio_ctx test_ctx;
  82470. int err;
  82471. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  82472. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  82473. int typeCnt_c;
  82474. int typeCnt_s;
  82475. int tp = 0;
  82476. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82477. int isServer;
  82478. #endif
  82479. (void)err;
  82480. (void)typeCnt_c;
  82481. (void)typeCnt_s;
  82482. (void)certType_c;
  82483. (void)certType_s;
  82484. #ifndef WOLFSSL_NO_TLS12
  82485. /* TLS1.2
  82486. * Both client and server load x509 cert and start handshaking.
  82487. * Check no negotiation occurred.
  82488. */
  82489. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82490. ExpectIntEQ(
  82491. test_rpk_memio_setup(
  82492. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82493. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82494. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82495. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82496. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82497. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  82498. , 0);
  82499. /* set client certificate type in client end */
  82500. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82501. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82502. typeCnt_c = 2;
  82503. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82504. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82505. typeCnt_s = 2;
  82506. /* both client and server do not call client/server_cert_type APIs,
  82507. * expecting default settings works and no negotiation performed.
  82508. */
  82509. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82510. return TEST_FAIL;
  82511. /* confirm no negotiation occurred */
  82512. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82513. WOLFSSL_SUCCESS);
  82514. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82515. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82516. WOLFSSL_SUCCESS);
  82517. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82518. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82519. WOLFSSL_SUCCESS);
  82520. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82521. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82522. WOLFSSL_SUCCESS);
  82523. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82524. (void)typeCnt_c;
  82525. (void)typeCnt_s;
  82526. wolfSSL_free(ssl_c);
  82527. wolfSSL_CTX_free(ctx_c);
  82528. wolfSSL_free(ssl_s);
  82529. wolfSSL_CTX_free(ctx_s);
  82530. ssl_c = ssl_s = NULL;
  82531. ctx_c = ctx_s = NULL;
  82532. #endif
  82533. #ifdef WOLFSSL_TLS13
  82534. /* Both client and server load x509 cert and start handshaking.
  82535. * Check no negotiation occurred.
  82536. */
  82537. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82538. ExpectIntEQ(
  82539. test_rpk_memio_setup(
  82540. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82541. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82542. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82543. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82544. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82545. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82546. , 0);
  82547. /* set client certificate type in client end */
  82548. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82549. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82550. typeCnt_c = 2;
  82551. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82552. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82553. typeCnt_s = 2;
  82554. /* both client and server do not call client/server_cert_type APIs,
  82555. * expecting default settings works and no negotiation performed.
  82556. */
  82557. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82558. return TEST_FAIL;
  82559. /* confirm no negotiation occurred */
  82560. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82561. WOLFSSL_SUCCESS);
  82562. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82563. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82564. WOLFSSL_SUCCESS);
  82565. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82566. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82567. WOLFSSL_SUCCESS);
  82568. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82569. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82570. WOLFSSL_SUCCESS);
  82571. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82572. (void)typeCnt_c;
  82573. (void)typeCnt_s;
  82574. wolfSSL_free(ssl_c);
  82575. wolfSSL_CTX_free(ctx_c);
  82576. wolfSSL_free(ssl_s);
  82577. wolfSSL_CTX_free(ctx_s);
  82578. ssl_c = ssl_s = NULL;
  82579. ctx_c = ctx_s = NULL;
  82580. /* Both client and server load RPK cert and start handshaking.
  82581. * Confirm negotiated cert types match as expected.
  82582. */
  82583. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82584. ExpectIntEQ(
  82585. test_rpk_memio_setup(
  82586. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82587. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82588. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82589. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82590. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82591. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82592. , 0);
  82593. /* set client certificate type in client end */
  82594. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82595. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82596. typeCnt_c = 2;
  82597. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82598. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82599. typeCnt_s = 2;
  82600. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82601. WOLFSSL_SUCCESS);
  82602. /* set server certificate type in client end */
  82603. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82604. WOLFSSL_SUCCESS);
  82605. /* set client certificate type in server end */
  82606. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82607. WOLFSSL_SUCCESS);
  82608. /* set server certificate type in server end */
  82609. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82610. WOLFSSL_SUCCESS);
  82611. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82612. return TEST_FAIL;
  82613. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82614. WOLFSSL_SUCCESS);
  82615. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82616. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82617. WOLFSSL_SUCCESS);
  82618. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82619. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82620. WOLFSSL_SUCCESS);
  82621. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82622. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82623. WOLFSSL_SUCCESS);
  82624. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82625. wolfSSL_free(ssl_c);
  82626. wolfSSL_CTX_free(ctx_c);
  82627. wolfSSL_free(ssl_s);
  82628. wolfSSL_CTX_free(ctx_s);
  82629. ssl_c = ssl_s = NULL;
  82630. ctx_c = ctx_s = NULL;
  82631. #endif
  82632. #ifndef WOLFSSL_NO_TLS12
  82633. /* TLS1.2
  82634. * Both client and server load RPK cert and start handshaking.
  82635. * Confirm negotiated cert types match as expected.
  82636. */
  82637. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82638. ExpectIntEQ(
  82639. test_rpk_memio_setup(
  82640. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82641. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82642. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82643. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82644. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82645. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82646. , 0);
  82647. /* set client certificate type in client end */
  82648. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82649. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82650. typeCnt_c = 2;
  82651. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82652. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82653. typeCnt_s = 2;
  82654. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82655. WOLFSSL_SUCCESS);
  82656. /* set server certificate type in client end */
  82657. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82658. WOLFSSL_SUCCESS);
  82659. /* set client certificate type in server end */
  82660. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82661. WOLFSSL_SUCCESS);
  82662. /* set server certificate type in server end */
  82663. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82664. WOLFSSL_SUCCESS);
  82665. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82666. return TEST_FAIL;
  82667. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82668. WOLFSSL_SUCCESS);
  82669. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82670. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82671. WOLFSSL_SUCCESS);
  82672. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82673. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82674. WOLFSSL_SUCCESS);
  82675. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82676. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82677. WOLFSSL_SUCCESS);
  82678. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82679. wolfSSL_free(ssl_c);
  82680. wolfSSL_CTX_free(ctx_c);
  82681. wolfSSL_free(ssl_s);
  82682. wolfSSL_CTX_free(ctx_s);
  82683. ssl_c = ssl_s = NULL;
  82684. ctx_c = ctx_s = NULL;
  82685. #endif
  82686. #ifdef WOLFSSL_TLS13
  82687. /* Both client and server load x509 cert.
  82688. * Have client call set_client_cert_type with both RPK and x509.
  82689. * This doesn't makes client add client cert type extension to ClientHello,
  82690. * since it does not load RPK cert actually.
  82691. */
  82692. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82693. ExpectIntEQ(
  82694. test_rpk_memio_setup(
  82695. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82696. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82697. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82698. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82699. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82700. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82701. , 0);
  82702. /* set client certificate type in client end
  82703. *
  82704. * client indicates both RPK and x509 certs are available but loaded RPK
  82705. * cert only. It does not have client add client-cert-type extension in CH.
  82706. */
  82707. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82708. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82709. typeCnt_c = 2;
  82710. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82711. WOLFSSL_SUCCESS);
  82712. /* client indicates both RPK and x509 certs are acceptable */
  82713. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82714. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82715. typeCnt_s = 2;
  82716. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82717. WOLFSSL_SUCCESS);
  82718. /* server indicates both RPK and x509 certs are acceptable */
  82719. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82720. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82721. typeCnt_c = 2;
  82722. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82723. WOLFSSL_SUCCESS);
  82724. /* server should indicate only RPK cert is available */
  82725. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82726. certType_s[1] = -1;
  82727. typeCnt_s = 1;
  82728. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82729. WOLFSSL_SUCCESS);
  82730. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82731. return TEST_FAIL;
  82732. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  82733. * be returned as cert type.
  82734. */
  82735. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82736. WOLFSSL_SUCCESS);
  82737. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82738. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82739. WOLFSSL_SUCCESS);
  82740. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82741. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82742. WOLFSSL_SUCCESS);
  82743. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82744. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82745. WOLFSSL_SUCCESS);
  82746. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82747. wolfSSL_free(ssl_c);
  82748. wolfSSL_CTX_free(ctx_c);
  82749. wolfSSL_free(ssl_s);
  82750. wolfSSL_CTX_free(ctx_s);
  82751. ssl_c = ssl_s = NULL;
  82752. ctx_c = ctx_s = NULL;
  82753. /* Have client load RPK cert and have server load x509 cert.
  82754. * Check the negotiation result from both ends.
  82755. */
  82756. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82757. ExpectIntEQ(
  82758. test_rpk_memio_setup(
  82759. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82760. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82761. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82762. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82763. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82764. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82765. , 0);
  82766. /* have client tell to use RPK cert */
  82767. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82768. certType_c[1] = -1;
  82769. typeCnt_c = 1;
  82770. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82771. WOLFSSL_SUCCESS);
  82772. /* have client tell to accept both RPK and x509 cert */
  82773. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82774. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82775. typeCnt_s = 2;
  82776. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82777. WOLFSSL_SUCCESS);
  82778. /* have server accept to both RPK and x509 cert */
  82779. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82780. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82781. typeCnt_c = 2;
  82782. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82783. WOLFSSL_SUCCESS);
  82784. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  82785. * end, expecting the default setting works.
  82786. */
  82787. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82788. return TEST_FAIL;
  82789. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82790. WOLFSSL_SUCCESS);
  82791. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82792. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82793. WOLFSSL_SUCCESS);
  82794. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82795. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82796. WOLFSSL_SUCCESS);
  82797. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82798. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82799. WOLFSSL_SUCCESS);
  82800. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82801. wolfSSL_free(ssl_c);
  82802. wolfSSL_CTX_free(ctx_c);
  82803. wolfSSL_free(ssl_s);
  82804. wolfSSL_CTX_free(ctx_s);
  82805. ssl_c = ssl_s = NULL;
  82806. ctx_c = ctx_s = NULL;
  82807. /* Have both client and server load RPK cert, however, have server
  82808. * indicate its cert type x509.
  82809. * Client is expected to detect the cert type mismatch then to send alert
  82810. * with "unsupported_certificate".
  82811. */
  82812. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82813. ExpectIntEQ(
  82814. test_rpk_memio_setup(
  82815. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82816. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82817. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82818. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  82819. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82820. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82821. , 0);
  82822. /* have client tell to use RPK cert */
  82823. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82824. certType_c[1] = -1;
  82825. typeCnt_c = 1;
  82826. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82827. WOLFSSL_SUCCESS);
  82828. /* have client tell to accept both RPK and x509 cert */
  82829. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82830. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82831. typeCnt_s = 2;
  82832. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82833. WOLFSSL_SUCCESS);
  82834. /* have server accept to both RPK and x509 cert */
  82835. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82836. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82837. typeCnt_c = 2;
  82838. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82839. WOLFSSL_SUCCESS);
  82840. /* have server tell to use x509 cert intentionally. This will bring
  82841. * certificate type mismatch in client side.
  82842. */
  82843. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82844. certType_s[1] = -1;
  82845. typeCnt_s = 1;
  82846. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82847. WOLFSSL_SUCCESS);
  82848. /* expect client detect cert type mismatch then send Alert */
  82849. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82850. if (ret != -1)
  82851. return TEST_FAIL;
  82852. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  82853. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82854. WOLFSSL_SUCCESS);
  82855. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82856. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82857. WOLFSSL_SUCCESS);
  82858. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82859. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82860. WOLFSSL_SUCCESS);
  82861. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82862. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82863. WOLFSSL_SUCCESS);
  82864. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82865. wolfSSL_free(ssl_c);
  82866. wolfSSL_CTX_free(ctx_c);
  82867. wolfSSL_free(ssl_s);
  82868. wolfSSL_CTX_free(ctx_s);
  82869. ssl_c = ssl_s = NULL;
  82870. ctx_c = ctx_s = NULL;
  82871. /* Have client load x509 cert and server load RPK cert,
  82872. * however, have client indicate its cert type RPK.
  82873. * Server is expected to detect the cert type mismatch then to send alert
  82874. * with "unsupported_certificate".
  82875. */
  82876. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82877. ExpectIntEQ(
  82878. test_rpk_memio_setup(
  82879. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82880. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82881. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82882. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82883. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82884. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82885. , 0);
  82886. /* have client tell to use RPK cert intentionally */
  82887. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82888. certType_c[1] = -1;
  82889. typeCnt_c = 1;
  82890. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82891. WOLFSSL_SUCCESS);
  82892. /* have client tell to accept both RPK and x509 cert */
  82893. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82894. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  82895. typeCnt_s = 2;
  82896. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82897. WOLFSSL_SUCCESS);
  82898. /* have server accept to both RPK and x509 cert */
  82899. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  82900. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  82901. typeCnt_c = 2;
  82902. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82903. WOLFSSL_SUCCESS);
  82904. /* have server tell to use x509 cert intentionally. This will bring
  82905. * certificate type mismatch in client side.
  82906. */
  82907. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82908. certType_s[1] = -1;
  82909. typeCnt_s = 1;
  82910. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82911. WOLFSSL_SUCCESS);
  82912. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82913. /* expect server detect cert type mismatch then send Alert */
  82914. ExpectIntNE(ret, 0);
  82915. err = wolfSSL_get_error(ssl_c, ret);
  82916. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  82917. /* client did not load RPK cert actually, so negotiation did not happen */
  82918. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82919. WOLFSSL_SUCCESS);
  82920. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82921. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82922. WOLFSSL_SUCCESS);
  82923. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82924. /* client did not load RPK cert actually, so negotiation did not happen */
  82925. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82926. WOLFSSL_SUCCESS);
  82927. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82928. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82929. WOLFSSL_SUCCESS);
  82930. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  82931. wolfSSL_free(ssl_c);
  82932. wolfSSL_CTX_free(ctx_c);
  82933. wolfSSL_free(ssl_s);
  82934. wolfSSL_CTX_free(ctx_s);
  82935. ssl_c = ssl_s = NULL;
  82936. ctx_c = ctx_s = NULL;
  82937. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  82938. /* Both client and server load RPK cert and set certificate verify
  82939. * callbacks then start handshaking.
  82940. * Confirm both side can refer the peer's cert.
  82941. */
  82942. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82943. ExpectIntEQ(
  82944. test_rpk_memio_setup(
  82945. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82946. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82947. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82948. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82949. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82950. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82951. , 0);
  82952. /* set client certificate type in client end */
  82953. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82954. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82955. typeCnt_c = 2;
  82956. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82957. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82958. typeCnt_s = 2;
  82959. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82960. WOLFSSL_SUCCESS);
  82961. /* set server certificate type in client end */
  82962. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82963. WOLFSSL_SUCCESS);
  82964. /* set client certificate type in server end */
  82965. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82966. WOLFSSL_SUCCESS);
  82967. /* set server certificate type in server end */
  82968. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82969. WOLFSSL_SUCCESS);
  82970. /* set certificate verify callback to both client and server */
  82971. isServer = 0;
  82972. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  82973. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  82974. isServer = 1;
  82975. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  82976. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  82977. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  82978. if (ret != 0)
  82979. return TEST_FAIL;
  82980. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82981. WOLFSSL_SUCCESS);
  82982. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82983. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82984. WOLFSSL_SUCCESS);
  82985. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82986. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82987. WOLFSSL_SUCCESS);
  82988. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82989. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82990. WOLFSSL_SUCCESS);
  82991. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82992. wolfSSL_free(ssl_c);
  82993. wolfSSL_CTX_free(ctx_c);
  82994. wolfSSL_free(ssl_s);
  82995. wolfSSL_CTX_free(ctx_s);
  82996. ssl_c = ssl_s = NULL;
  82997. ctx_c = ctx_s = NULL;
  82998. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  82999. #endif /* WOLFSSL_TLS13 */
  83000. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  83001. return EXPECT_RESULT();
  83002. }
  83003. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83004. static int test_dtls13_bad_epoch_ch(void)
  83005. {
  83006. EXPECT_DECLS;
  83007. WOLFSSL_CTX *ctx_c = NULL;
  83008. WOLFSSL_CTX *ctx_s = NULL;
  83009. WOLFSSL *ssl_c = NULL;
  83010. WOLFSSL *ssl_s = NULL;
  83011. struct test_memio_ctx test_ctx;
  83012. const int EPOCH_OFF = 3;
  83013. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83014. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83015. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83016. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  83017. * with just one message */
  83018. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  83019. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83020. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83021. WOLFSSL_ERROR_WANT_READ);
  83022. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  83023. /* first CH should use epoch 0x0 */
  83024. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  83025. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  83026. /* change epoch to 2 */
  83027. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  83028. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83029. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83030. WOLFSSL_ERROR_WANT_READ);
  83031. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  83032. /* resend the CH */
  83033. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83034. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83035. wolfSSL_free(ssl_c);
  83036. wolfSSL_CTX_free(ctx_c);
  83037. wolfSSL_free(ssl_s);
  83038. wolfSSL_CTX_free(ctx_s);
  83039. return EXPECT_RESULT();
  83040. }
  83041. #else
  83042. static int test_dtls13_bad_epoch_ch(void)
  83043. {
  83044. return TEST_SKIPPED;
  83045. }
  83046. #endif
  83047. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83048. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83049. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  83050. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83051. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  83052. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83053. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  83054. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  83055. {
  83056. EXPECT_DECLS;
  83057. WOLFSSL_SESSION *sess = NULL;
  83058. /* Setup the session to avoid errors */
  83059. ssl->session->timeout = -1;
  83060. ssl->session->side = WOLFSSL_CLIENT_END;
  83061. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  83062. defined(HAVE_SESSION_TICKET))
  83063. ssl->session->version = ssl->version;
  83064. #endif
  83065. /* Force a short session ID to be sent */
  83066. ssl->session->sessionIDSz = 4;
  83067. #ifndef NO_SESSION_CACHE_REF
  83068. /* Allow the client cache to be used */
  83069. ssl->session->idLen = 4;
  83070. #endif
  83071. ssl->session->isSetup = 1;
  83072. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  83073. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  83074. return EXPECT_RESULT();
  83075. }
  83076. static int test_short_session_id(void)
  83077. {
  83078. EXPECT_DECLS;
  83079. test_ssl_cbf client_cbf;
  83080. test_ssl_cbf server_cbf;
  83081. size_t i;
  83082. struct {
  83083. method_provider client_meth;
  83084. method_provider server_meth;
  83085. const char* tls_version;
  83086. } params[] = {
  83087. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83088. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83089. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  83090. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  83091. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  83092. #ifdef WOLFSSL_DTLS13
  83093. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  83094. #endif
  83095. #endif
  83096. #ifndef WOLFSSL_NO_TLS12
  83097. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  83098. #ifdef WOLFSSL_DTLS
  83099. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  83100. #endif
  83101. #endif
  83102. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83103. !defined(NO_DES3))
  83104. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  83105. #ifdef WOLFSSL_DTLS
  83106. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  83107. #endif
  83108. #endif
  83109. };
  83110. fprintf(stderr, "\n");
  83111. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  83112. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  83113. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  83114. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  83115. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  83116. client_cbf.method = params[i].client_meth;
  83117. server_cbf.method = params[i].server_meth;
  83118. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  83119. &server_cbf, NULL), TEST_SUCCESS);
  83120. }
  83121. return EXPECT_RESULT();
  83122. }
  83123. #else
  83124. static int test_short_session_id(void)
  83125. {
  83126. return TEST_SKIPPED;
  83127. }
  83128. #endif
  83129. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  83130. && defined(WOLFSSL_DTLS13)
  83131. static byte* test_find_string(const char *string,
  83132. byte *buf, int buf_size)
  83133. {
  83134. int string_size, i;
  83135. string_size = (int)XSTRLEN(string);
  83136. for (i = 0; i < buf_size - string_size - 1; i++) {
  83137. if (XSTRCMP((char*)&buf[i], string) == 0)
  83138. return &buf[i];
  83139. }
  83140. return NULL;
  83141. }
  83142. static int test_wolfSSL_dtls13_null_cipher(void)
  83143. {
  83144. EXPECT_DECLS;
  83145. WOLFSSL_CTX *ctx_c = NULL;
  83146. WOLFSSL_CTX *ctx_s = NULL;
  83147. WOLFSSL *ssl_c = NULL;
  83148. WOLFSSL *ssl_s = NULL;
  83149. struct test_memio_ctx test_ctx;
  83150. const char *test_str = "test";
  83151. int test_str_size;
  83152. byte buf[255], *ptr = NULL;
  83153. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83154. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  83155. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83156. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83157. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83158. test_str_size = XSTRLEN("test") + 1;
  83159. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83160. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  83161. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  83162. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83163. /* check that the packet was sent cleartext */
  83164. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  83165. test_ctx.s_len));
  83166. if (ptr != NULL) {
  83167. /* modify the message */
  83168. *ptr = 'H';
  83169. /* bad messages should be ignored in DTLS */
  83170. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  83171. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  83172. }
  83173. wolfSSL_free(ssl_c);
  83174. wolfSSL_free(ssl_s);
  83175. wolfSSL_CTX_free(ctx_c);
  83176. wolfSSL_CTX_free(ctx_s);
  83177. return TEST_SUCCESS;
  83178. }
  83179. #else
  83180. static int test_wolfSSL_dtls13_null_cipher(void)
  83181. {
  83182. return TEST_SKIPPED;
  83183. }
  83184. #endif
  83185. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83186. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83187. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  83188. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  83189. {
  83190. SOCKADDR_S peer;
  83191. XSOCKLENT len;
  83192. int ret;
  83193. XMEMSET((byte*)&peer, 0, sizeof(peer));
  83194. len = sizeof(peer);
  83195. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  83196. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  83197. return -1;
  83198. switch (peer.ss_family) {
  83199. #ifdef WOLFSSL_IPV6
  83200. case WOLFSSL_IP6: {
  83201. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  83202. break;
  83203. }
  83204. #endif /* WOLFSSL_IPV6 */
  83205. case WOLFSSL_IP4:
  83206. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  83207. break;
  83208. default:
  83209. return -1;
  83210. }
  83211. return 0;
  83212. }
  83213. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  83214. {
  83215. char buf[1] = {'t'};
  83216. SOCKADDR_IN_T addr;
  83217. int sock_fd;
  83218. word16 port;
  83219. int err;
  83220. (void)ssl;
  83221. (void)ctx;
  83222. if (ssl == NULL)
  83223. return -1;
  83224. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  83225. if (err != 0)
  83226. return -1;
  83227. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  83228. if (sock_fd == -1)
  83229. return -1;
  83230. build_addr(&addr, wolfSSLIP, port, 1, 0);
  83231. /* send a packet to the server. Being another socket, the kernel will ensure
  83232. * the source port will be different. */
  83233. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  83234. sizeof(addr));
  83235. close(sock_fd);
  83236. if (err == -1)
  83237. return -1;
  83238. return 0;
  83239. }
  83240. /* setup a SSL session but just after the handshake send a packet to the server
  83241. * with a source address different than the one of the connected client. The I/O
  83242. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  83243. * is done in test_dtls_msg_from_other_peer_cb */
  83244. static int test_dtls_msg_from_other_peer(void)
  83245. {
  83246. EXPECT_DECLS;
  83247. callback_functions client_cbs;
  83248. callback_functions server_cbs;
  83249. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  83250. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  83251. client_cbs.method = wolfDTLSv1_2_client_method;
  83252. server_cbs.method = wolfDTLSv1_2_server_method;
  83253. client_cbs.doUdp = 1;
  83254. server_cbs.doUdp = 1;
  83255. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  83256. test_dtls_msg_from_other_peer_cb);
  83257. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  83258. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  83259. return EXPECT_RESULT();
  83260. }
  83261. #else
  83262. static int test_dtls_msg_from_other_peer(void)
  83263. {
  83264. return TEST_SKIPPED;
  83265. }
  83266. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83267. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83268. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  83269. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  83270. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83271. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83272. static int test_dtls_ipv6_check(void)
  83273. {
  83274. EXPECT_DECLS;
  83275. WOLFSSL_CTX *ctx_c = NULL;
  83276. WOLFSSL_CTX *ctx_s = NULL;
  83277. WOLFSSL *ssl_c = NULL;
  83278. WOLFSSL *ssl_s = NULL;
  83279. SOCKADDR_IN fake_addr6;
  83280. int sockfd = -1;
  83281. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  83282. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  83283. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  83284. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  83285. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83286. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  83287. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83288. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  83289. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  83290. /* mimic a sockaddr_in6 struct, this way we can't test without
  83291. * WOLFSSL_IPV6 */
  83292. fake_addr6.sin_family = WOLFSSL_IP6;
  83293. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  83294. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83295. /* can't return error here, as the peer is opaque for wolfssl library at
  83296. * this point */
  83297. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  83298. WOLFSSL_SUCCESS);
  83299. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  83300. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  83301. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83302. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83303. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  83304. WOLFSSL_SUCCESS);
  83305. /* reuse the socket */
  83306. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83307. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  83308. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83309. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83310. if (sockfd != -1)
  83311. close(sockfd);
  83312. wolfSSL_free(ssl_c);
  83313. wolfSSL_CTX_free(ctx_c);
  83314. wolfSSL_free(ssl_s);
  83315. wolfSSL_CTX_free(ctx_s);
  83316. return EXPECT_RESULT();
  83317. }
  83318. #else
  83319. static int test_dtls_ipv6_check(void)
  83320. {
  83321. return TEST_SKIPPED;
  83322. }
  83323. #endif
  83324. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83325. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83326. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  83327. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  83328. {
  83329. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83330. }
  83331. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  83332. {
  83333. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  83334. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  83335. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  83336. }
  83337. else {
  83338. char testMsg[] = "Message after SCR";
  83339. char msgBuf[sizeof(testMsg)];
  83340. int ret;
  83341. if (!wolfSSL_is_server(ssl)) {
  83342. AssertIntEQ(WOLFSSL_SUCCESS,
  83343. wolfSSL_set_session(ssl,
  83344. test_wolfSSL_SCR_after_resumption_session));
  83345. }
  83346. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83347. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83348. sizeof(testMsg));
  83349. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83350. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  83351. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83352. AssertIntEQ(ret, sizeof(msgBuf));
  83353. }
  83354. }
  83355. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  83356. {
  83357. AssertIntEQ(WOLFSSL_SUCCESS,
  83358. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  83359. }
  83360. static int test_wolfSSL_SCR_after_resumption(void)
  83361. {
  83362. EXPECT_DECLS;
  83363. callback_functions func_cb_client;
  83364. callback_functions func_cb_server;
  83365. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83366. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83367. func_cb_client.method = wolfTLSv1_2_client_method;
  83368. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83369. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83370. func_cb_server.method = wolfTLSv1_2_server_method;
  83371. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83372. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83373. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83374. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83375. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  83376. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83377. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83378. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83379. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83380. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  83381. return EXPECT_RESULT();
  83382. }
  83383. #else
  83384. static int test_wolfSSL_SCR_after_resumption(void)
  83385. {
  83386. return TEST_SKIPPED;
  83387. }
  83388. #endif
  83389. static int test_wolfSSL_configure_args(void)
  83390. {
  83391. EXPECT_DECLS;
  83392. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  83393. ExpectNotNull(wolfSSL_configure_args());
  83394. #endif
  83395. return EXPECT_RESULT();
  83396. }
  83397. static int test_dtls_no_extensions(void)
  83398. {
  83399. EXPECT_DECLS;
  83400. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  83401. !defined(WOLFSSL_NO_TLS12)
  83402. WOLFSSL *ssl_s = NULL;
  83403. WOLFSSL_CTX *ctx_s = NULL;
  83404. struct test_memio_ctx test_ctx;
  83405. const byte chNoExtensions[] = {
  83406. /* Handshake type */
  83407. 0x16,
  83408. /* Version */
  83409. 0xfe, 0xff,
  83410. /* Epoch */
  83411. 0x00, 0x00,
  83412. /* Seq number */
  83413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83414. /* Length */
  83415. 0x00, 0x40,
  83416. /* CH type */
  83417. 0x01,
  83418. /* Length */
  83419. 0x00, 0x00, 0x34,
  83420. /* Msg Seq */
  83421. 0x00, 0x00,
  83422. /* Frag offset */
  83423. 0x00, 0x00, 0x00,
  83424. /* Frag length */
  83425. 0x00, 0x00, 0x34,
  83426. /* Version */
  83427. 0xfe, 0xff,
  83428. /* Random */
  83429. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  83430. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  83431. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  83432. /* Session Length */
  83433. 0x00,
  83434. /* Cookie Length */
  83435. 0x00,
  83436. /* CS Length */
  83437. 0x00, 0x0c,
  83438. /* CS */
  83439. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  83440. /* Comp Meths Length */
  83441. 0x01,
  83442. /* Comp Meths */
  83443. 0x00
  83444. /* And finally... no extensions */
  83445. };
  83446. int i;
  83447. #ifdef OPENSSL_EXTRA
  83448. int repeats = 2;
  83449. #else
  83450. int repeats = 1;
  83451. #endif
  83452. for (i = 0; i < repeats; i++) {
  83453. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83454. ssl_s = NULL;
  83455. ctx_s = NULL;
  83456. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  83457. NULL, wolfDTLS_server_method), 0);
  83458. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  83459. test_ctx.s_len = sizeof(chNoExtensions);
  83460. #ifdef OPENSSL_EXTRA
  83461. if (i > 0) {
  83462. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  83463. WOLFSSL_SUCCESS);
  83464. }
  83465. #endif
  83466. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  83467. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83468. /* Expecting a handshake msg. Either HVR or SH. */
  83469. ExpectIntGT(test_ctx.c_len, 0);
  83470. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  83471. wolfSSL_free(ssl_s);
  83472. wolfSSL_CTX_free(ctx_s);
  83473. }
  83474. #endif
  83475. return EXPECT_RESULT();
  83476. }
  83477. static int test_tls_alert_no_server_hello(void)
  83478. {
  83479. EXPECT_DECLS;
  83480. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83481. WOLFSSL *ssl_c = NULL;
  83482. WOLFSSL_CTX *ctx_c = NULL;
  83483. struct test_memio_ctx test_ctx;
  83484. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  83485. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83486. ssl_c = NULL;
  83487. ctx_c = NULL;
  83488. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83489. wolfTLSv1_2_client_method, NULL), 0);
  83490. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  83491. test_ctx.c_len = sizeof(alert_msg);
  83492. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83493. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  83494. wolfSSL_free(ssl_c);
  83495. wolfSSL_CTX_free(ctx_c);
  83496. #endif
  83497. return EXPECT_RESULT();
  83498. }
  83499. static int test_TLSX_CA_NAMES_bad_extension(void)
  83500. {
  83501. EXPECT_DECLS;
  83502. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83503. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  83504. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  83505. defined(HAVE_NULL_CIPHER)
  83506. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  83507. * parse the CA Names extension. Otherwise it will return other non-related
  83508. * errors. If CA Names will be parsed in more configurations, that should
  83509. * be reflected in the macro guard above. */
  83510. WOLFSSL *ssl_c = NULL;
  83511. WOLFSSL_CTX *ctx_c = NULL;
  83512. struct test_memio_ctx test_ctx;
  83513. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  83514. const byte shBadCaNamesExt[] = {
  83515. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83516. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83517. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83518. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83519. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83520. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83521. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  83522. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  83523. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  83524. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83525. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  83526. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  83527. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  83528. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  83529. };
  83530. const byte shBadCaNamesExt2[] = {
  83531. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83532. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83533. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83534. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83535. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83536. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83537. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  83538. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  83539. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  83540. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83541. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  83542. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  83543. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  83544. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  83545. };
  83546. int i = 0;
  83547. for (i = 0; i < 2; i++) {
  83548. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83549. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83550. wolfTLSv1_3_client_method, NULL), 0);
  83551. switch (i) {
  83552. case 0:
  83553. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  83554. sizeof(shBadCaNamesExt));
  83555. test_ctx.c_len = sizeof(shBadCaNamesExt);
  83556. break;
  83557. case 1:
  83558. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  83559. sizeof(shBadCaNamesExt2));
  83560. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  83561. break;
  83562. }
  83563. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83564. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  83565. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  83566. #else
  83567. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  83568. #endif
  83569. wolfSSL_free(ssl_c);
  83570. ssl_c = NULL;
  83571. wolfSSL_CTX_free(ctx_c);
  83572. ctx_c = NULL;
  83573. }
  83574. #endif
  83575. return EXPECT_RESULT();
  83576. }
  83577. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83578. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83579. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  83580. {
  83581. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83582. WOLFSSL_SUCCESS);
  83583. }
  83584. static int test_dtls_1_0_hvr_downgrade(void)
  83585. {
  83586. EXPECT_DECLS;
  83587. callback_functions func_cb_client;
  83588. callback_functions func_cb_server;
  83589. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83590. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83591. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83592. func_cb_client.method = wolfDTLS_client_method;
  83593. func_cb_server.method = wolfDTLSv1_2_server_method;
  83594. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  83595. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83596. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83597. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83598. return EXPECT_RESULT();
  83599. }
  83600. #else
  83601. static int test_dtls_1_0_hvr_downgrade(void)
  83602. {
  83603. EXPECT_DECLS;
  83604. return EXPECT_RESULT();
  83605. }
  83606. #endif
  83607. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  83608. defined(HAVE_SESSION_TICKET)
  83609. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  83610. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  83611. {
  83612. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  83613. AssertNotNull(test_session_ticket_no_id_session);
  83614. }
  83615. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  83616. {
  83617. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  83618. }
  83619. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  83620. {
  83621. test_session_ticket_no_id_session->sessionIDSz = 0;
  83622. AssertIntEQ(WOLFSSL_SUCCESS,
  83623. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  83624. }
  83625. static int test_session_ticket_no_id(void)
  83626. {
  83627. /* We are testing an expired (invalid crypto context in out case since the
  83628. * ctx changes) session ticket being sent with the session ID being 0
  83629. * length. */
  83630. EXPECT_DECLS;
  83631. callback_functions func_cb_client;
  83632. callback_functions func_cb_server;
  83633. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83634. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83635. func_cb_client.method = wolfTLSv1_2_client_method;
  83636. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83637. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  83638. func_cb_server.method = wolfTLSv1_2_server_method;
  83639. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83640. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83641. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83642. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83643. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83644. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83645. func_cb_client.method = wolfTLSv1_2_client_method;
  83646. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83647. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  83648. func_cb_server.method = wolfTLSv1_2_server_method;
  83649. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83650. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83651. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83652. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83653. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  83654. return EXPECT_RESULT();
  83655. }
  83656. #else
  83657. static int test_session_ticket_no_id(void)
  83658. {
  83659. EXPECT_DECLS;
  83660. return EXPECT_RESULT();
  83661. }
  83662. #endif
  83663. static int test_session_ticket_hs_update(void)
  83664. {
  83665. EXPECT_DECLS;
  83666. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83667. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  83668. struct test_memio_ctx test_ctx;
  83669. struct test_memio_ctx test_ctx2;
  83670. struct test_memio_ctx test_ctx3;
  83671. WOLFSSL_CTX *ctx_c = NULL;
  83672. WOLFSSL_CTX *ctx_s = NULL;
  83673. WOLFSSL *ssl_c = NULL;
  83674. WOLFSSL *ssl_c2 = NULL;
  83675. WOLFSSL *ssl_c3 = NULL;
  83676. WOLFSSL *ssl_s = NULL;
  83677. WOLFSSL *ssl_s2 = NULL;
  83678. WOLFSSL *ssl_s3 = NULL;
  83679. WOLFSSL_SESSION *sess = NULL;
  83680. byte read_data[1];
  83681. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83682. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  83683. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  83684. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83685. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83686. /* Generate tickets */
  83687. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83688. wolfSSL_SetLoggingPrefix("client");
  83689. /* Read the ticket msg */
  83690. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  83691. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83692. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83693. WOLFSSL_ERROR_WANT_READ);
  83694. wolfSSL_SetLoggingPrefix(NULL);
  83695. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  83696. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83697. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  83698. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83699. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  83700. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  83701. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  83702. wolfSSL_SetLoggingPrefix("client");
  83703. /* Exchange initial flights for the second connection */
  83704. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83705. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83706. WOLFSSL_ERROR_WANT_READ);
  83707. wolfSSL_SetLoggingPrefix(NULL);
  83708. wolfSSL_SetLoggingPrefix("server");
  83709. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83710. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83711. WOLFSSL_ERROR_WANT_READ);
  83712. wolfSSL_SetLoggingPrefix(NULL);
  83713. /* Complete third connection so that new tickets are exchanged */
  83714. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  83715. /* Read the ticket msg */
  83716. wolfSSL_SetLoggingPrefix("client");
  83717. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  83718. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83719. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83720. WOLFSSL_ERROR_WANT_READ);
  83721. wolfSSL_SetLoggingPrefix(NULL);
  83722. /* Complete second connection */
  83723. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  83724. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  83725. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  83726. wolfSSL_free(ssl_c);
  83727. wolfSSL_free(ssl_c2);
  83728. wolfSSL_free(ssl_c3);
  83729. wolfSSL_free(ssl_s);
  83730. wolfSSL_free(ssl_s2);
  83731. wolfSSL_free(ssl_s3);
  83732. wolfSSL_CTX_free(ctx_c);
  83733. wolfSSL_CTX_free(ctx_s);
  83734. wolfSSL_SESSION_free(sess);
  83735. #endif
  83736. return EXPECT_RESULT();
  83737. }
  83738. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83739. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83740. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  83741. {
  83742. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83743. WOLFSSL_SUCCESS);
  83744. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83745. }
  83746. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  83747. {
  83748. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83749. }
  83750. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  83751. {
  83752. char testMsg[] = "Message after SCR";
  83753. char msgBuf[sizeof(testMsg)];
  83754. if (wolfSSL_is_server(ssl)) {
  83755. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83756. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  83757. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83758. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83759. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83760. sizeof(testMsg));
  83761. }
  83762. else {
  83763. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83764. sizeof(testMsg));
  83765. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83766. }
  83767. }
  83768. static int test_dtls_downgrade_scr_server(void)
  83769. {
  83770. EXPECT_DECLS;
  83771. callback_functions func_cb_client;
  83772. callback_functions func_cb_server;
  83773. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83774. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83775. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83776. func_cb_client.method = wolfDTLSv1_2_client_method;
  83777. func_cb_server.method = wolfDTLS_server_method;
  83778. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  83779. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  83780. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  83781. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  83782. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83783. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83784. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83785. return EXPECT_RESULT();
  83786. }
  83787. #else
  83788. static int test_dtls_downgrade_scr_server(void)
  83789. {
  83790. EXPECT_DECLS;
  83791. return EXPECT_RESULT();
  83792. }
  83793. #endif
  83794. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83795. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83796. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  83797. {
  83798. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83799. WOLFSSL_SUCCESS);
  83800. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83801. }
  83802. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  83803. {
  83804. char testMsg[] = "Message after SCR";
  83805. char msgBuf[sizeof(testMsg)];
  83806. if (wolfSSL_is_server(ssl)) {
  83807. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83808. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  83809. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83810. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83811. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83812. sizeof(testMsg));
  83813. }
  83814. else {
  83815. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83816. sizeof(testMsg));
  83817. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  83818. }
  83819. }
  83820. static int test_dtls_downgrade_scr(void)
  83821. {
  83822. EXPECT_DECLS;
  83823. callback_functions func_cb_client;
  83824. callback_functions func_cb_server;
  83825. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83826. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83827. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83828. func_cb_client.method = wolfDTLS_client_method;
  83829. func_cb_server.method = wolfDTLSv1_2_server_method;
  83830. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  83831. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  83832. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  83833. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83834. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83835. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83836. return EXPECT_RESULT();
  83837. }
  83838. #else
  83839. static int test_dtls_downgrade_scr(void)
  83840. {
  83841. EXPECT_DECLS;
  83842. return EXPECT_RESULT();
  83843. }
  83844. #endif
  83845. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  83846. && !defined(WOLFSSL_NO_TLS12)
  83847. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  83848. char *data, int sz, void *ctx)
  83849. {
  83850. static int call_counter = 0;
  83851. call_counter++;
  83852. (void)ssl;
  83853. (void)data;
  83854. (void)sz;
  83855. (void)ctx;
  83856. switch (call_counter) {
  83857. case 1:
  83858. case 2:
  83859. return WOLFSSL_CBIO_ERR_TIMEOUT;
  83860. case 3:
  83861. return WOLFSSL_CBIO_ERR_WANT_READ;
  83862. default:
  83863. AssertIntLE(call_counter, 3);
  83864. return -1;
  83865. }
  83866. }
  83867. #endif
  83868. /* Make sure we don't send acks before getting a server hello */
  83869. static int test_dtls_client_hello_timeout_downgrade(void)
  83870. {
  83871. EXPECT_DECLS;
  83872. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  83873. && !defined(WOLFSSL_NO_TLS12)
  83874. WOLFSSL_CTX *ctx_c = NULL;
  83875. WOLFSSL_CTX *ctx_s = NULL;
  83876. WOLFSSL *ssl_c = NULL;
  83877. WOLFSSL *ssl_s = NULL;
  83878. struct test_memio_ctx test_ctx;
  83879. DtlsRecordLayerHeader* dtlsRH;
  83880. size_t len;
  83881. byte sequence_number[8];
  83882. int i;
  83883. for (i = 0; i < 2; i++) {
  83884. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83885. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83886. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  83887. if (i == 0) {
  83888. /* First time simulate timeout in IO layer */
  83889. /* CH1 */
  83890. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83891. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83892. /* HVR */
  83893. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83894. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83895. /* CH2 */
  83896. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83897. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83898. /* SH flight */
  83899. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83900. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83901. /* Drop the SH */
  83902. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  83903. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83904. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  83905. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  83906. (sizeof(DtlsRecordLayerHeader) + len));
  83907. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  83908. /* Read the remainder of the flight */
  83909. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83910. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83911. wolfSSL_SSLSetIORecv(ssl_c,
  83912. test_dtls_client_hello_timeout_downgrade_read_cb);
  83913. /* CH3 */
  83914. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83915. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83916. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  83917. }
  83918. else {
  83919. /* Second time call wolfSSL_dtls_got_timeout */
  83920. /* CH1 */
  83921. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83922. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83923. /* HVR */
  83924. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83925. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83926. /* CH2 */
  83927. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83928. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83929. /* SH flight */
  83930. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  83931. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83932. /* Drop the SH */
  83933. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  83934. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83935. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  83936. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  83937. (sizeof(DtlsRecordLayerHeader) + len));
  83938. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  83939. /* Read the remainder of the flight */
  83940. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  83941. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  83942. /* Quick timeout should be set as we received at least one msg */
  83943. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  83944. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83945. /* Quick timeout should be cleared after a quick timeout */
  83946. /* CH3 */
  83947. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  83948. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83949. }
  83950. /* Parse out to make sure we got exactly one ClientHello message */
  83951. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  83952. /* Second ClientHello after HVR */
  83953. sequence_number[7] = 2;
  83954. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  83955. ExpectIntEQ(dtlsRH->type, handshake);
  83956. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  83957. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  83958. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  83959. sizeof(sequence_number)), 0);
  83960. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  83961. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  83962. /* Connection should be able to continue */
  83963. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83964. wolfSSL_free(ssl_c);
  83965. wolfSSL_free(ssl_s);
  83966. wolfSSL_CTX_free(ctx_c);
  83967. wolfSSL_CTX_free(ctx_s);
  83968. ssl_c = NULL;
  83969. ssl_s = NULL;
  83970. ctx_c = NULL;
  83971. ctx_s = NULL;
  83972. if (!EXPECT_SUCCESS())
  83973. break;
  83974. }
  83975. #endif
  83976. return EXPECT_RESULT();
  83977. }
  83978. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83979. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  83980. int sz, void *ctx)
  83981. {
  83982. static int call_counter = 0;
  83983. call_counter++;
  83984. (void)ssl;
  83985. (void)data;
  83986. (void)sz;
  83987. (void)ctx;
  83988. switch (call_counter) {
  83989. case 1:
  83990. return WOLFSSL_CBIO_ERR_TIMEOUT;
  83991. case 2:
  83992. return WOLFSSL_CBIO_ERR_WANT_READ;
  83993. default:
  83994. AssertIntLE(call_counter, 2);
  83995. return -1;
  83996. }
  83997. }
  83998. #endif
  83999. /* Make sure we don't send acks before getting a server hello */
  84000. static int test_dtls_client_hello_timeout(void)
  84001. {
  84002. EXPECT_DECLS;
  84003. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84004. WOLFSSL *ssl_c = NULL;
  84005. WOLFSSL_CTX *ctx_c = NULL;
  84006. struct test_memio_ctx test_ctx;
  84007. DtlsRecordLayerHeader* dtlsRH;
  84008. size_t idx;
  84009. size_t len;
  84010. byte sequence_number[8];
  84011. int i;
  84012. for (i = 0; i < 2; i++) {
  84013. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84014. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84015. wolfDTLSv1_3_client_method, NULL), 0);
  84016. if (i == 0) {
  84017. /* First time simulate timeout in IO layer */
  84018. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  84019. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84020. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84021. }
  84022. else {
  84023. /* Second time call wolfSSL_dtls_got_timeout */
  84024. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84025. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84026. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84027. }
  84028. /* Parse out to make sure we got exactly two ClientHello messages */
  84029. idx = 0;
  84030. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84031. /* First ClientHello */
  84032. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84033. ExpectIntEQ(dtlsRH->type, handshake);
  84034. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84035. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84036. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84037. sizeof(sequence_number)), 0);
  84038. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84039. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84040. idx += sizeof(DtlsRecordLayerHeader) + len;
  84041. /* Second ClientHello */
  84042. sequence_number[7] = 1;
  84043. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84044. ExpectIntEQ(dtlsRH->type, handshake);
  84045. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84046. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84047. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84048. sizeof(sequence_number)), 0);
  84049. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84050. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84051. wolfSSL_free(ssl_c);
  84052. wolfSSL_CTX_free(ctx_c);
  84053. ssl_c = NULL;
  84054. ctx_c = NULL;
  84055. if (!EXPECT_SUCCESS())
  84056. break;
  84057. }
  84058. #endif
  84059. return EXPECT_RESULT();
  84060. }
  84061. /* DTLS test when dropping the changed cipher spec message */
  84062. static int test_dtls_dropped_ccs(void)
  84063. {
  84064. EXPECT_DECLS;
  84065. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84066. && !defined(WOLFSSL_NO_TLS12)
  84067. WOLFSSL_CTX *ctx_c = NULL;
  84068. WOLFSSL_CTX *ctx_s = NULL;
  84069. WOLFSSL *ssl_c = NULL;
  84070. WOLFSSL *ssl_s = NULL;
  84071. struct test_memio_ctx test_ctx;
  84072. DtlsRecordLayerHeader* dtlsRH;
  84073. size_t len;
  84074. byte data[1];
  84075. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84076. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84077. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84078. /* CH1 */
  84079. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84080. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84081. /* HVR */
  84082. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84083. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84084. /* CH2 */
  84085. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84086. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84087. /* Server first flight */
  84088. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84089. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84090. /* Client flight */
  84091. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84092. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84093. /* Server ccs + finished */
  84094. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  84095. /* Drop the ccs */
  84096. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84097. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84098. ExpectIntEQ(len, 1);
  84099. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  84100. if (EXPECT_SUCCESS()) {
  84101. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84102. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84103. (sizeof(DtlsRecordLayerHeader) + len));
  84104. }
  84105. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84106. /* Client rtx flight */
  84107. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84108. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84109. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84110. /* Server ccs + finished rtx */
  84111. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  84112. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84113. /* Client processes finished */
  84114. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  84115. wolfSSL_free(ssl_c);
  84116. wolfSSL_free(ssl_s);
  84117. wolfSSL_CTX_free(ctx_c);
  84118. wolfSSL_CTX_free(ctx_s);
  84119. #endif
  84120. return EXPECT_RESULT();
  84121. }
  84122. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84123. && !defined(WOLFSSL_NO_TLS12)
  84124. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  84125. byte seq_num)
  84126. {
  84127. EXPECT_DECLS;
  84128. DtlsRecordLayerHeader* dtlsRH;
  84129. byte sequence_number[8];
  84130. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84131. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  84132. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  84133. ExpectIntEQ(dtlsRH->type, handshake);
  84134. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84135. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84136. sequence_number[7] = seq_num;
  84137. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84138. sizeof(sequence_number)), 0);
  84139. return EXPECT_RESULT();
  84140. }
  84141. #endif
  84142. /*
  84143. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  84144. * and after a HelloRetryRequest. This is testing the server side as it is
  84145. * operating statelessly and should copy the sequence number of the ClientHello.
  84146. */
  84147. static int test_dtls_seq_num_downgrade(void)
  84148. {
  84149. EXPECT_DECLS;
  84150. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84151. && !defined(WOLFSSL_NO_TLS12)
  84152. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84153. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84154. struct test_memio_ctx test_ctx;
  84155. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84156. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84157. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  84158. /* CH1 */
  84159. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84160. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84161. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84162. test_ctx.s_len, 0), TEST_SUCCESS);
  84163. /* HVR */
  84164. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84165. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84166. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84167. test_ctx.c_len, 0), TEST_SUCCESS);
  84168. /* CH2 */
  84169. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84170. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84171. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84172. test_ctx.s_len, 1), TEST_SUCCESS);
  84173. /* Server first flight */
  84174. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84175. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84176. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84177. test_ctx.c_len, 1), TEST_SUCCESS);
  84178. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84179. wolfSSL_free(ssl_c);
  84180. wolfSSL_CTX_free(ctx_c);
  84181. wolfSSL_free(ssl_s);
  84182. wolfSSL_CTX_free(ctx_s);
  84183. #endif
  84184. return EXPECT_RESULT();
  84185. }
  84186. /**
  84187. * Make sure we don't send RSA Signature Hash Algorithms in the
  84188. * CertificateRequest when we don't have any such ciphers set.
  84189. * @return EXPECT_RESULT()
  84190. */
  84191. static int test_certreq_sighash_algos(void)
  84192. {
  84193. EXPECT_DECLS;
  84194. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84195. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  84196. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  84197. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  84198. WOLFSSL_CTX *ctx_c = NULL;
  84199. WOLFSSL_CTX *ctx_s = NULL;
  84200. WOLFSSL *ssl_c = NULL;
  84201. WOLFSSL *ssl_s = NULL;
  84202. struct test_memio_ctx test_ctx;
  84203. int idx = 0;
  84204. int maxIdx = 0;
  84205. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84206. test_ctx.c_ciphers = test_ctx.s_ciphers =
  84207. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  84208. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84209. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  84210. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  84211. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  84212. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  84213. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  84214. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84215. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  84216. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84217. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84218. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84219. WOLFSSL_ERROR_WANT_READ);
  84220. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84221. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84222. WOLFSSL_ERROR_WANT_READ);
  84223. /* Find the CertificateRequest message */
  84224. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  84225. word16 len;
  84226. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  84227. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  84228. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  84229. ato16(test_ctx.c_buff + idx, &len);
  84230. idx += OPAQUE16_LEN;
  84231. if (test_ctx.c_buff[idx] == certificate_request) {
  84232. idx++;
  84233. /* length */
  84234. idx += OPAQUE24_LEN;
  84235. /* cert types */
  84236. idx += 1 + test_ctx.c_buff[idx];
  84237. /* Sig algos */
  84238. ato16(test_ctx.c_buff + idx, &len);
  84239. idx += OPAQUE16_LEN;
  84240. maxIdx = idx + (int)len;
  84241. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  84242. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  84243. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  84244. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  84245. else
  84246. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  84247. }
  84248. break;
  84249. }
  84250. else {
  84251. idx += (int)len;
  84252. }
  84253. }
  84254. ExpectIntLT(idx, test_ctx.c_len);
  84255. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84256. wolfSSL_free(ssl_c);
  84257. wolfSSL_free(ssl_s);
  84258. wolfSSL_CTX_free(ctx_c);
  84259. wolfSSL_CTX_free(ctx_s);
  84260. #endif
  84261. return EXPECT_RESULT();
  84262. }
  84263. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84264. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84265. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  84266. {
  84267. EXPECT_DECLS;
  84268. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84269. myVerifyAction = VERIFY_USE_PREVERFIY;
  84270. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84271. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84272. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84273. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84274. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84275. WOLFSSL_SUCCESS);
  84276. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84277. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84278. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84279. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84280. "./certs/crl/ca-int.pem",
  84281. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84282. return EXPECT_RESULT();
  84283. }
  84284. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  84285. {
  84286. EXPECT_DECLS;
  84287. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84288. myVerifyAction = VERIFY_USE_PREVERFIY;
  84289. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84290. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84291. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84292. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84293. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84294. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84295. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84296. WOLFSSL_SUCCESS);
  84297. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84298. "./certs/crl/ca-int2.pem",
  84299. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84300. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84301. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84302. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84303. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84304. "./certs/crl/ca-int.pem",
  84305. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84306. return EXPECT_RESULT();
  84307. }
  84308. #endif
  84309. static int test_revoked_loaded_int_cert(void)
  84310. {
  84311. EXPECT_DECLS;
  84312. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84313. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84314. test_ssl_cbf client_cbf;
  84315. test_ssl_cbf server_cbf;
  84316. struct {
  84317. const char* certPemFile;
  84318. const char* keyPemFile;
  84319. ctx_cb client_ctx_ready;
  84320. } test_params[] = {
  84321. {"./certs/intermediate/ca-int2-cert.pem",
  84322. "./certs/intermediate/ca-int2-key.pem",
  84323. test_revoked_loaded_int_cert_ctx_ready1},
  84324. {"./certs/intermediate/server-chain.pem",
  84325. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84326. {"./certs/intermediate/server-chain-short.pem",
  84327. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84328. };
  84329. size_t i;
  84330. printf("\n");
  84331. for (i = 0; i < XELEM_CNT(test_params); i++) {
  84332. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84333. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84334. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  84335. server_cbf.certPemFile = test_params[i].certPemFile;
  84336. server_cbf.keyPemFile = test_params[i].keyPemFile;
  84337. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  84338. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84339. &server_cbf, NULL), TEST_FAIL);
  84340. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  84341. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  84342. if (!EXPECT_SUCCESS())
  84343. break;
  84344. printf("\t%s passed\n", test_params[i].certPemFile);
  84345. }
  84346. #endif
  84347. return EXPECT_RESULT();
  84348. }
  84349. static int test_dtls13_frag_ch_pq(void)
  84350. {
  84351. EXPECT_DECLS;
  84352. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84353. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  84354. WOLFSSL_CTX *ctx_c = NULL;
  84355. WOLFSSL_CTX *ctx_s = NULL;
  84356. WOLFSSL *ssl_c = NULL;
  84357. WOLFSSL *ssl_s = NULL;
  84358. struct test_memio_ctx test_ctx;
  84359. const char *test_str = "test";
  84360. int test_str_size;
  84361. byte buf[255];
  84362. int group = WOLFSSL_KYBER_LEVEL5;
  84363. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84364. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84365. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84366. /* Add in a large post-quantum key share to make the CH long. */
  84367. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  84368. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  84369. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84370. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84371. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  84372. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  84373. test_str_size = XSTRLEN("test") + 1;
  84374. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84375. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84376. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84377. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84378. wolfSSL_free(ssl_c);
  84379. wolfSSL_free(ssl_s);
  84380. wolfSSL_CTX_free(ctx_c);
  84381. wolfSSL_CTX_free(ctx_s);
  84382. #endif
  84383. return EXPECT_RESULT();
  84384. }
  84385. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84386. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84387. static int test_dtls_frag_ch_count_records(byte* b, int len)
  84388. {
  84389. DtlsRecordLayerHeader* dtlsRH;
  84390. int records = 0;
  84391. size_t recordLen;
  84392. while (len > 0) {
  84393. records++;
  84394. dtlsRH = (DtlsRecordLayerHeader*)b;
  84395. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  84396. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  84397. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  84398. }
  84399. return records;
  84400. }
  84401. #endif
  84402. static int test_dtls_frag_ch(void)
  84403. {
  84404. EXPECT_DECLS;
  84405. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84406. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84407. WOLFSSL_CTX *ctx_c = NULL;
  84408. WOLFSSL_CTX *ctx_s = NULL;
  84409. WOLFSSL *ssl_c = NULL;
  84410. WOLFSSL *ssl_s = NULL;
  84411. struct test_memio_ctx test_ctx;
  84412. static unsigned int DUMMY_MTU = 256;
  84413. unsigned char four_frag_CH[] = {
  84414. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84415. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84416. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  84417. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  84418. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  84419. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84420. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84421. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84422. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84423. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  84424. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  84425. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  84426. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  84427. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  84428. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  84429. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  84430. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  84431. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  84432. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  84433. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84434. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  84435. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  84436. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  84437. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  84438. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  84439. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  84440. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  84441. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  84442. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  84443. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  84444. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  84445. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  84446. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  84447. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  84448. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  84449. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  84450. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  84451. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  84452. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  84453. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  84454. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  84455. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  84456. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  84457. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  84458. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  84459. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  84460. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  84461. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  84462. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  84463. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  84464. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  84465. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  84466. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  84467. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  84468. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  84469. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  84470. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  84471. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  84472. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  84473. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  84474. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  84475. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  84476. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  84477. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  84478. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  84479. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  84480. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  84481. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  84482. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  84483. 0xa5, 0xcb, 0x68, 0xf3
  84484. };
  84485. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84486. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84487. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84488. /* Fragment msgs */
  84489. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  84490. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  84491. /* Add in some key shares to make the CH long */
  84492. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  84493. WOLFSSL_SUCCESS);
  84494. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  84495. WOLFSSL_SUCCESS);
  84496. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  84497. WOLFSSL_SUCCESS);
  84498. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  84499. WOLFSSL_SUCCESS);
  84500. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84501. /* Reject fragmented first CH */
  84502. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  84503. sizeof(four_frag_CH)), 4);
  84504. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  84505. test_ctx.s_len = sizeof(four_frag_CH);
  84506. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  84507. int s_len = test_ctx.s_len;
  84508. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84509. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84510. /* Fail if we didn't advance the buffer to avoid infinite loops */
  84511. ExpectIntLT(test_ctx.s_len, s_len);
  84512. }
  84513. /* Expect all fragments read */
  84514. ExpectIntEQ(test_ctx.s_len, 0);
  84515. /* Expect quietly dropping fragmented first CH */
  84516. ExpectIntEQ(test_ctx.c_len, 0);
  84517. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  84518. /* Disable ECH as it pushes it over our MTU */
  84519. wolfSSL_SetEchEnable(ssl_c, 0);
  84520. #endif
  84521. /* Limit options to make the CH a fixed length */
  84522. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  84523. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  84524. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  84525. #ifdef OPENSSL_EXTRA
  84526. ":DHE-RSA-AES256-GCM-SHA384"
  84527. #endif
  84528. ));
  84529. /* CH1 */
  84530. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84531. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84532. /* Count records. Expect 1 unfragmented CH */
  84533. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84534. test_ctx.s_len), 1);
  84535. /* HRR */
  84536. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84537. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84538. /* CH2 */
  84539. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84540. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84541. /* Count records. Expect fragmented CH */
  84542. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84543. test_ctx.s_len), 1);
  84544. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84545. wolfSSL_free(ssl_c);
  84546. wolfSSL_free(ssl_s);
  84547. wolfSSL_CTX_free(ctx_c);
  84548. wolfSSL_CTX_free(ctx_s);
  84549. ssl_c = ssl_s = NULL;
  84550. ctx_c = ctx_s = NULL;
  84551. #endif
  84552. return EXPECT_RESULT();
  84553. }
  84554. static int test_dtls_empty_keyshare_with_cookie(void)
  84555. {
  84556. EXPECT_DECLS;
  84557. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84558. WOLFSSL_CTX *ctx_s = NULL;
  84559. WOLFSSL *ssl_s = NULL;
  84560. struct test_memio_ctx test_ctx;
  84561. unsigned char ch_empty_keyshare_with_cookie[] = {
  84562. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  84563. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  84564. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  84565. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  84566. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  84567. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84568. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84569. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84570. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84571. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  84572. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  84573. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  84574. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  84575. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  84576. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  84577. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  84578. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  84579. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  84580. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  84581. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  84582. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  84583. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  84584. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  84585. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  84586. };
  84587. DtlsRecordLayerHeader* dtlsRH;
  84588. byte sequence_number[8];
  84589. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84590. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84591. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  84592. sizeof(ch_empty_keyshare_with_cookie));
  84593. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  84594. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84595. NULL, wolfDTLSv1_3_server_method), 0);
  84596. /* CH1 */
  84597. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84598. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84599. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  84600. ExpectIntEQ(test_ctx.c_len, 15);
  84601. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84602. ExpectIntEQ(dtlsRH->type, alert);
  84603. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84604. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84605. sequence_number[7] = 1;
  84606. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84607. sizeof(sequence_number)), 0);
  84608. ExpectIntEQ(dtlsRH->length[0], 0);
  84609. ExpectIntEQ(dtlsRH->length[1], 2);
  84610. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  84611. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  84612. wolfSSL_free(ssl_s);
  84613. wolfSSL_CTX_free(ctx_s);
  84614. #endif
  84615. return EXPECT_RESULT();
  84616. }
  84617. static int test_dtls_old_seq_number(void)
  84618. {
  84619. EXPECT_DECLS;
  84620. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  84621. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84622. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84623. struct test_memio_ctx test_ctx;
  84624. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84625. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84626. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84627. /* CH1 */
  84628. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84629. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84630. /* HVR */
  84631. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84632. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84633. /* CH2 */
  84634. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84635. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84636. /* Server first flight */
  84637. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84638. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84639. /* Client second flight */
  84640. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84641. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84642. /* Modify the sequence number */
  84643. {
  84644. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84645. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  84646. }
  84647. /* Server second flight */
  84648. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84649. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84650. /* Server should not do anything as a pkt was dropped */
  84651. ExpectIntEQ(test_ctx.c_len, 0);
  84652. ExpectIntEQ(test_ctx.s_len, 0);
  84653. /* Trigger rtx */
  84654. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84655. /* Complete connection */
  84656. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84657. wolfSSL_free(ssl_c);
  84658. wolfSSL_CTX_free(ctx_c);
  84659. wolfSSL_free(ssl_s);
  84660. wolfSSL_CTX_free(ctx_s);
  84661. #endif
  84662. return EXPECT_RESULT();
  84663. }
  84664. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84665. defined(HAVE_LIBOQS)
  84666. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  84667. {
  84668. int group = WOLFSSL_KYBER_LEVEL5;
  84669. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  84670. }
  84671. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  84672. {
  84673. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  84674. }
  84675. #endif
  84676. static int test_tls13_pq_groups(void)
  84677. {
  84678. EXPECT_DECLS;
  84679. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84680. defined(HAVE_LIBOQS)
  84681. callback_functions func_cb_client;
  84682. callback_functions func_cb_server;
  84683. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84684. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84685. func_cb_client.method = wolfTLSv1_3_client_method;
  84686. func_cb_server.method = wolfTLSv1_3_server_method;
  84687. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  84688. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  84689. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  84690. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84691. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84692. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84693. #endif
  84694. return EXPECT_RESULT();
  84695. }
  84696. static int test_tls13_early_data(void)
  84697. {
  84698. EXPECT_DECLS;
  84699. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84700. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  84701. int written = 0;
  84702. int read = 0;
  84703. size_t i;
  84704. int splitEarlyData;
  84705. char msg[] = "This is early data";
  84706. char msg2[] = "This is client data";
  84707. char msg3[] = "This is server data";
  84708. char msg4[] = "This is server immediate data";
  84709. char msgBuf[50];
  84710. struct {
  84711. method_provider client_meth;
  84712. method_provider server_meth;
  84713. const char* tls_version;
  84714. int isUdp;
  84715. } params[] = {
  84716. #ifdef WOLFSSL_TLS13
  84717. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84718. "TLS 1.3", 0 },
  84719. #endif
  84720. #ifdef WOLFSSL_DTLS13
  84721. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  84722. "DTLS 1.3", 1 },
  84723. #endif
  84724. };
  84725. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84726. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  84727. struct test_memio_ctx test_ctx;
  84728. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84729. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84730. WOLFSSL_SESSION *sess = NULL;
  84731. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84732. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  84733. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  84734. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  84735. /* Get a ticket so that we can do 0-RTT on the next connection */
  84736. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84737. /* Make sure we read the ticket */
  84738. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  84739. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84740. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  84741. wolfSSL_free(ssl_c);
  84742. ssl_c = NULL;
  84743. wolfSSL_free(ssl_s);
  84744. ssl_s = NULL;
  84745. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84746. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84747. params[i].client_meth, params[i].server_meth), 0);
  84748. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  84749. #ifdef WOLFSSL_DTLS13
  84750. if (params[i].isUdp) {
  84751. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  84752. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  84753. #else
  84754. /* Let's test this but we generally don't recommend turning off the
  84755. * cookie exchange */
  84756. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  84757. #endif
  84758. }
  84759. #endif
  84760. /* Test 0-RTT data */
  84761. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  84762. &written), sizeof(msg));
  84763. ExpectIntEQ(written, sizeof(msg));
  84764. if (splitEarlyData) {
  84765. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  84766. &written), sizeof(msg));
  84767. ExpectIntEQ(written, sizeof(msg));
  84768. }
  84769. /* Read first 0-RTT data (if split otherwise entire data) */
  84770. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84771. &read), sizeof(msg));
  84772. ExpectIntEQ(read, sizeof(msg));
  84773. ExpectStrEQ(msg, msgBuf);
  84774. /* Test 0.5-RTT data */
  84775. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  84776. if (splitEarlyData) {
  84777. /* Read second 0-RTT data */
  84778. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84779. &read), sizeof(msg));
  84780. ExpectIntEQ(read, sizeof(msg));
  84781. ExpectStrEQ(msg, msgBuf);
  84782. }
  84783. if (params[i].isUdp) {
  84784. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84785. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84786. /* Read server 0.5-RTT data */
  84787. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  84788. ExpectStrEQ(msg4, msgBuf);
  84789. /* Complete handshake */
  84790. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84791. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84792. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  84793. * a user would loop until it is true but here we control both sides so we
  84794. * just assert the expected value. wolfSSL_read_early_data does not provide
  84795. * handshake status to us with non-blocking IO and we can't use
  84796. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  84797. * parsing logic. */
  84798. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  84799. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84800. &read), 0);
  84801. ExpectIntEQ(read, 0);
  84802. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  84803. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84804. }
  84805. else {
  84806. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84807. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  84808. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  84809. &read), 0);
  84810. ExpectIntEQ(read, 0);
  84811. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  84812. /* Read server 0.5-RTT data */
  84813. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  84814. ExpectStrEQ(msg4, msgBuf);
  84815. }
  84816. /* Test bi-directional write */
  84817. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  84818. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  84819. ExpectStrEQ(msg2, msgBuf);
  84820. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  84821. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  84822. ExpectStrEQ(msg3, msgBuf);
  84823. ExpectTrue(wolfSSL_session_reused(ssl_c));
  84824. ExpectTrue(wolfSSL_session_reused(ssl_s));
  84825. wolfSSL_SESSION_free(sess);
  84826. wolfSSL_free(ssl_c);
  84827. wolfSSL_free(ssl_s);
  84828. wolfSSL_CTX_free(ctx_c);
  84829. wolfSSL_CTX_free(ctx_s);
  84830. }
  84831. }
  84832. #endif
  84833. return EXPECT_RESULT();
  84834. }
  84835. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  84836. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  84837. {
  84838. EXPECT_DECLS;
  84839. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84840. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  84841. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  84842. return EXPECT_RESULT();
  84843. }
  84844. #endif
  84845. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  84846. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  84847. {
  84848. EXPECT_DECLS;
  84849. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84850. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  84851. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  84852. return EXPECT_RESULT();
  84853. }
  84854. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  84855. {
  84856. EXPECT_DECLS;
  84857. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84858. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  84859. 0), 1);
  84860. return EXPECT_RESULT();
  84861. }
  84862. #endif
  84863. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  84864. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  84865. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  84866. {
  84867. EXPECT_DECLS;
  84868. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  84869. return EXPECT_RESULT();
  84870. }
  84871. #endif
  84872. static int test_self_signed_stapling(void)
  84873. {
  84874. EXPECT_DECLS;
  84875. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  84876. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  84877. test_ssl_cbf client_cbf;
  84878. test_ssl_cbf server_cbf;
  84879. size_t i;
  84880. struct {
  84881. method_provider client_meth;
  84882. method_provider server_meth;
  84883. ctx_cb client_ctx;
  84884. const char* tls_version;
  84885. } params[] = {
  84886. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  84887. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84888. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  84889. #endif
  84890. #ifndef WOLFSSL_NO_TLS12
  84891. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  84892. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84893. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  84894. #endif
  84895. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  84896. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84897. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  84898. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  84899. test_self_signed_stapling_client_v2_multi_ctx_ready,
  84900. "TLSv1_2 v2 multi" },
  84901. #endif
  84902. #endif
  84903. };
  84904. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84905. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84906. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84907. printf("\nTesting self-signed cert with status request: %s\n",
  84908. params[i].tls_version);
  84909. client_cbf.method = params[i].client_meth;
  84910. client_cbf.ctx_ready = params[i].client_ctx;
  84911. server_cbf.method = params[i].server_meth;
  84912. server_cbf.certPemFile = "certs/ca-cert.pem";
  84913. server_cbf.keyPemFile = "certs/ca-key.pem";
  84914. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  84915. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84916. &server_cbf, NULL), TEST_SUCCESS);
  84917. }
  84918. #endif
  84919. return EXPECT_RESULT();
  84920. }
  84921. static int test_tls_multi_handshakes_one_record(void)
  84922. {
  84923. EXPECT_DECLS;
  84924. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84925. struct test_memio_ctx test_ctx;
  84926. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84927. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84928. RecordLayerHeader* rh = NULL;
  84929. byte *len ;
  84930. int newRecIdx = RECORD_HEADER_SZ;
  84931. int idx = 0;
  84932. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84933. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84934. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  84935. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84936. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84937. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  84938. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84939. /* Combine server handshake msgs into one record */
  84940. while (idx < test_ctx.c_len) {
  84941. word16 recLen;
  84942. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  84943. len = &rh->length[0];
  84944. ato16((const byte*)len, &recLen);
  84945. idx += RECORD_HEADER_SZ;
  84946. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  84947. (size_t)recLen);
  84948. newRecIdx += recLen;
  84949. idx += recLen;
  84950. }
  84951. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  84952. len = &rh->length[0];
  84953. c16toa(newRecIdx - RECORD_HEADER_SZ, len);
  84954. test_ctx.c_len = newRecIdx;
  84955. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84956. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84957. wolfSSL_free(ssl_c);
  84958. wolfSSL_free(ssl_s);
  84959. wolfSSL_CTX_free(ctx_c);
  84960. wolfSSL_CTX_free(ctx_s);
  84961. #endif
  84962. return EXPECT_RESULT();
  84963. }
  84964. static int test_write_dup(void)
  84965. {
  84966. EXPECT_DECLS;
  84967. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  84968. size_t i, j;
  84969. char hiWorld[] = "dup message";
  84970. char readData[sizeof(hiWorld) + 5];
  84971. struct {
  84972. method_provider client_meth;
  84973. method_provider server_meth;
  84974. const char* version_name;
  84975. int version;
  84976. } methods[] = {
  84977. #ifndef WOLFSSL_NO_TLS12
  84978. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  84979. #endif
  84980. #ifdef WOLFSSL_TLS13
  84981. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  84982. #endif
  84983. };
  84984. struct {
  84985. const char* cipher;
  84986. int version;
  84987. } ciphers[] = {
  84988. /* For simplicity the macros are copied from internal.h */
  84989. /* TLS 1.2 */
  84990. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  84991. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  84992. #ifndef NO_RSA
  84993. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  84994. #endif
  84995. #endif
  84996. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  84997. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  84998. #endif
  84999. #endif
  85000. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  85001. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  85002. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85003. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85004. #endif
  85005. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85006. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85007. #endif
  85008. #endif
  85009. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  85010. && !defined(NO_TLS) && !defined(NO_AES)
  85011. #ifdef HAVE_AESGCM
  85012. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85013. #ifndef NO_RSA
  85014. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85015. #endif
  85016. #endif
  85017. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85018. #ifndef NO_RSA
  85019. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85020. #endif
  85021. #endif
  85022. #endif
  85023. #endif
  85024. /* TLS 1.3 */
  85025. #ifdef WOLFSSL_TLS13
  85026. #ifdef HAVE_AESGCM
  85027. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85028. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  85029. #endif
  85030. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85031. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  85032. #endif
  85033. #endif
  85034. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85035. #ifndef NO_SHA256
  85036. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  85037. #endif
  85038. #endif
  85039. #ifdef HAVE_AESCCM
  85040. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85041. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  85042. #endif
  85043. #endif
  85044. #endif
  85045. };
  85046. for (i = 0; i < XELEM_CNT(methods); i++) {
  85047. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  85048. struct test_memio_ctx test_ctx;
  85049. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85050. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85051. WOLFSSL *ssl_c2 = NULL;
  85052. if (methods[i].version != ciphers[j].version)
  85053. continue;
  85054. if (i == 0 && j == 0)
  85055. printf("\n");
  85056. printf("Testing %s with %s... ", methods[i].version_name,
  85057. ciphers[j].cipher);
  85058. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85059. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  85060. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85061. methods[i].client_meth, methods[i].server_meth), 0);
  85062. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85063. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  85064. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  85065. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  85066. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  85067. sizeof(hiWorld));
  85068. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  85069. sizeof(hiWorld));
  85070. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  85071. sizeof(hiWorld));
  85072. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  85073. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  85074. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  85075. sizeof(hiWorld));
  85076. if (EXPECT_SUCCESS())
  85077. printf("ok\n");
  85078. else
  85079. printf("failed\n");
  85080. wolfSSL_free(ssl_c);
  85081. wolfSSL_free(ssl_c2);
  85082. wolfSSL_free(ssl_s);
  85083. wolfSSL_CTX_free(ctx_c);
  85084. wolfSSL_CTX_free(ctx_s);
  85085. }
  85086. }
  85087. #endif
  85088. return EXPECT_RESULT();
  85089. }
  85090. static int test_read_write_hs(void)
  85091. {
  85092. EXPECT_DECLS;
  85093. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  85094. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  85095. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  85096. struct test_memio_ctx test_ctx;
  85097. byte test_buffer[16];
  85098. unsigned int test;
  85099. /* test == 0 : client writes, server reads */
  85100. /* test == 1 : server writes, client reads */
  85101. for (test = 0; test < 2; test++) {
  85102. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85103. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85104. wolfTLSv1_2_client_method,
  85105. wolfTLSv1_2_server_method), 0);
  85106. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  85107. /* CH -> */
  85108. if (test == 0) {
  85109. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85110. } else {
  85111. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85112. sizeof(test_buffer)), -1);
  85113. }
  85114. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85115. /* <- SH + SKE + SHD */
  85116. if (test == 0) {
  85117. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85118. sizeof(test_buffer)), -1);
  85119. } else {
  85120. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85121. }
  85122. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85123. /* -> CKE + CLIENT FINISHED */
  85124. if (test == 0) {
  85125. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85126. } else {
  85127. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85128. sizeof(test_buffer)), -1);
  85129. }
  85130. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85131. /* abide clang static analyzer */
  85132. if (ssl_s != NULL) {
  85133. /* disable group message to separate sending of ChangeCipherspec
  85134. * from Finished */
  85135. ssl_s->options.groupMessages = 0;
  85136. }
  85137. /* allow writing of CS, but not FINISHED */
  85138. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  85139. /* <- CS */
  85140. if (test == 0) {
  85141. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85142. sizeof(test_buffer)), -1);
  85143. } else {
  85144. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85145. }
  85146. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  85147. /* move CS message where the client can read it */
  85148. memmove(test_ctx.c_buff,
  85149. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  85150. test_ctx.c_len = 6;
  85151. /* read CS */
  85152. if (test == 0) {
  85153. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85154. } else {
  85155. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85156. sizeof(test_buffer)), -1);
  85157. }
  85158. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85159. ExpectIntEQ(test_ctx.c_len, 0);
  85160. if (test == 0) {
  85161. /* send SERVER FINISHED */
  85162. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85163. sizeof(test_buffer)), -1);
  85164. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  85165. WOLFSSL_ERROR_WANT_READ);
  85166. } else {
  85167. /* send SERVER FINISHED + App Data */
  85168. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  85169. }
  85170. ExpectIntGT(test_ctx.c_len, 0);
  85171. /* Send and receive the data */
  85172. if (test == 0) {
  85173. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  85174. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85175. sizeof(test_buffer)), 5);
  85176. } else {
  85177. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85178. sizeof(test_buffer)), 5);
  85179. }
  85180. ExpectBufEQ(test_buffer, "hello", 5);
  85181. wolfSSL_free(ssl_c);
  85182. wolfSSL_free(ssl_s);
  85183. wolfSSL_CTX_free(ctx_c);
  85184. wolfSSL_CTX_free(ctx_s);
  85185. ssl_c = ssl_s = NULL;
  85186. ctx_c = ctx_s = NULL;
  85187. }
  85188. #endif
  85189. return EXPECT_RESULT();
  85190. }
  85191. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85192. static const char* test_get_signature_nid_siglag;
  85193. static int test_get_signature_nid_sig;
  85194. static int test_get_signature_nid_hash;
  85195. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  85196. {
  85197. EXPECT_DECLS;
  85198. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  85199. if (!wolfSSL_is_server(ssl)) {
  85200. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  85201. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  85202. }
  85203. return EXPECT_RESULT();
  85204. }
  85205. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85206. {
  85207. EXPECT_DECLS;
  85208. int nid = 0;
  85209. (void)ctx;
  85210. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  85211. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85212. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85213. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85214. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85215. }
  85216. else /* No sigalg info on static ciphersuite */
  85217. return TEST_SUCCESS;
  85218. return EXPECT_RESULT();
  85219. }
  85220. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85221. {
  85222. EXPECT_DECLS;
  85223. int nid = 0;
  85224. (void)ctx;
  85225. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85226. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85227. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85228. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85229. return EXPECT_RESULT();
  85230. }
  85231. #endif
  85232. static int test_get_signature_nid(void)
  85233. {
  85234. EXPECT_DECLS;
  85235. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85236. test_ssl_cbf client_cbf;
  85237. test_ssl_cbf server_cbf;
  85238. size_t i;
  85239. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  85240. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  85241. caCertFile }
  85242. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  85243. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  85244. caEccCertFile }
  85245. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  85246. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  85247. caCertFile }
  85248. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  85249. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  85250. caEccCertFile }
  85251. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  85252. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  85253. caEdCertFile }
  85254. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  85255. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  85256. caEd448CertFile }
  85257. struct {
  85258. const char* siglag;
  85259. int sig_nid;
  85260. int hash_nid;
  85261. int tls_ver;
  85262. const char* server_cert;
  85263. const char* server_key;
  85264. const char* client_ca;
  85265. } params[] = {
  85266. #ifndef NO_RSA
  85267. #ifndef NO_SHA256
  85268. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  85269. #ifdef WC_RSA_PSS
  85270. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85271. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85272. #endif
  85273. #endif
  85274. #ifdef WOLFSSL_SHA512
  85275. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  85276. #ifdef WC_RSA_PSS
  85277. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85278. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85279. #endif
  85280. #endif
  85281. #endif
  85282. #ifdef HAVE_ECC
  85283. #ifndef NO_SHA256
  85284. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85285. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85286. #endif
  85287. #endif
  85288. #ifdef HAVE_ED25519
  85289. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  85290. #endif
  85291. #ifdef HAVE_ED448
  85292. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  85293. #endif
  85294. };
  85295. printf("\n");
  85296. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  85297. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85298. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85299. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  85300. params[i].siglag);
  85301. switch (params[i].tls_ver) {
  85302. #ifndef WOLFSSL_NO_TLS12
  85303. case WOLFSSL_TLSV1_2:
  85304. client_cbf.method = wolfTLSv1_2_client_method;
  85305. server_cbf.method = wolfTLSv1_2_server_method;
  85306. break;
  85307. #endif
  85308. #ifdef WOLFSSL_TLS13
  85309. case WOLFSSL_TLSV1_3:
  85310. client_cbf.method = wolfTLSv1_3_client_method;
  85311. server_cbf.method = wolfTLSv1_3_server_method;
  85312. break;
  85313. #endif
  85314. default:
  85315. printf("skipping\n");
  85316. continue;
  85317. }
  85318. test_get_signature_nid_siglag = params[i].siglag;
  85319. test_get_signature_nid_sig = params[i].sig_nid;
  85320. test_get_signature_nid_hash = params[i].hash_nid;
  85321. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85322. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85323. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  85324. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  85325. server_cbf.certPemFile = params[i].server_cert;
  85326. server_cbf.keyPemFile = params[i].server_key;
  85327. client_cbf.caPemFile = params[i].client_ca;
  85328. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85329. &server_cbf, NULL), TEST_SUCCESS);
  85330. if (EXPECT_SUCCESS())
  85331. printf("passed\n");
  85332. }
  85333. #endif
  85334. return EXPECT_RESULT();
  85335. }
  85336. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85337. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  85338. {
  85339. #ifndef NO_MD5
  85340. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  85341. #elif !defined(NO_SHA)
  85342. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  85343. #elif !defined(NO_SHA256)
  85344. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  85345. #else
  85346. #error "We need a digest to hash the Signer object"
  85347. #endif
  85348. byte hashBuf[WC_MAX_DIGEST_SIZE];
  85349. wc_HashAlg hash;
  85350. size_t i;
  85351. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  85352. for (i = 0; i < CA_TABLE_SIZE; i++) {
  85353. Signer* cur;
  85354. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  85355. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  85356. sizeof(*cur)), 0);
  85357. }
  85358. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  85359. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  85360. return MakeWordFromHash(hashBuf);
  85361. }
  85362. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  85363. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  85364. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  85365. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  85366. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  85367. {
  85368. EXPECT_DECLS;
  85369. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  85370. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  85371. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85372. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  85373. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  85374. return EXPECT_RESULT();
  85375. }
  85376. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  85377. {
  85378. EXPECT_DECLS;
  85379. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  85380. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85381. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85382. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85383. return EXPECT_RESULT();
  85384. }
  85385. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85386. {
  85387. EXPECT_DECLS;
  85388. WOLFSSL_CERT_MANAGER* cm;
  85389. (void)ssl;
  85390. /* WARNING: this approach bypasses the reference counter check in
  85391. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  85392. * cause unexpected behaviour when other active connections try accessing
  85393. * the caTable. */
  85394. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  85395. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  85396. WOLFSSL_SUCCESS);
  85397. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85398. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85399. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  85400. return EXPECT_RESULT();
  85401. }
  85402. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  85403. {
  85404. EXPECT_DECLS;
  85405. WOLFSSL_CTX* ctx;
  85406. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  85407. return EXPECT_RESULT();
  85408. }
  85409. #endif
  85410. static int test_tls_cert_store_unchanged(void)
  85411. {
  85412. EXPECT_DECLS;
  85413. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85414. test_ssl_cbf client_cbf;
  85415. test_ssl_cbf server_cbf;
  85416. int i;
  85417. for (i = 0; i < 2; i++) {
  85418. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85419. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85420. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  85421. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  85422. sizeof(test_tls_cert_store_unchanged_before_hashes));
  85423. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  85424. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  85425. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85426. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85427. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85428. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85429. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85430. switch (i) {
  85431. case 0:
  85432. client_cbf.on_ctx_cleanup =
  85433. test_tls_cert_store_unchanged_ctx_cleanup;
  85434. server_cbf.on_ctx_cleanup =
  85435. test_tls_cert_store_unchanged_ctx_cleanup;
  85436. break;
  85437. case 1:
  85438. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85439. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85440. break;
  85441. default:
  85442. Fail(("Should not enter here"), ("Entered here"));
  85443. }
  85444. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  85445. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  85446. server_cbf.caPemFile = caCertFile;
  85447. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85448. &server_cbf, NULL), TEST_SUCCESS);
  85449. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  85450. test_tls_cert_store_unchanged_after_hashes,
  85451. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85452. }
  85453. #endif
  85454. return EXPECT_RESULT();
  85455. }
  85456. static int test_wolfSSL_SendUserCanceled(void)
  85457. {
  85458. EXPECT_DECLS;
  85459. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  85460. size_t i;
  85461. struct {
  85462. method_provider client_meth;
  85463. method_provider server_meth;
  85464. const char* tls_version;
  85465. } params[] = {
  85466. #if defined(WOLFSSL_TLS13)
  85467. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  85468. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  85469. #ifdef WOLFSSL_DTLS13
  85470. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  85471. #endif
  85472. #endif
  85473. #ifndef WOLFSSL_NO_TLS12
  85474. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  85475. #ifdef WOLFSSL_DTLS
  85476. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  85477. #endif
  85478. #endif
  85479. #if !defined(NO_OLD_TLS)
  85480. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  85481. #ifdef WOLFSSL_DTLS
  85482. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  85483. #endif
  85484. #endif
  85485. };
  85486. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85487. WOLFSSL_CTX *ctx_c = NULL;
  85488. WOLFSSL_CTX *ctx_s = NULL;
  85489. WOLFSSL *ssl_c = NULL;
  85490. WOLFSSL *ssl_s = NULL;
  85491. struct test_memio_ctx test_ctx;
  85492. WOLFSSL_ALERT_HISTORY h;
  85493. printf("Testing %s\n", params[i].tls_version);
  85494. XMEMSET(&h, 0, sizeof(h));
  85495. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85496. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85497. params[i].client_meth, params[i].server_meth), 0);
  85498. /* CH1 */
  85499. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85500. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85501. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85502. /* Alert closed connection */
  85503. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85504. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  85505. /* Last alert will be close notify because user_canceled should be
  85506. * followed by a close_notify */
  85507. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  85508. ExpectIntEQ(h.last_rx.code, close_notify);
  85509. ExpectIntEQ(h.last_rx.level, alert_warning);
  85510. wolfSSL_free(ssl_c);
  85511. wolfSSL_free(ssl_s);
  85512. wolfSSL_CTX_free(ctx_c);
  85513. wolfSSL_CTX_free(ctx_s);
  85514. }
  85515. #endif
  85516. return EXPECT_RESULT();
  85517. }
  85518. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85519. defined(HAVE_OCSP) && \
  85520. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  85521. !defined(WOLFSSL_NO_TLS12)
  85522. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  85523. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  85524. {
  85525. (void)ctx;
  85526. (void)url;
  85527. (void)urlSz;
  85528. (void)ocspReqBuf;
  85529. (void)ocspReqSz;
  85530. (void)ocspRespBuf;
  85531. return -1;
  85532. }
  85533. static int test_ocsp_callback_fails(void)
  85534. {
  85535. WOLFSSL_CTX *ctx_c = NULL;
  85536. WOLFSSL_CTX *ctx_s = NULL;
  85537. WOLFSSL *ssl_c = NULL;
  85538. WOLFSSL *ssl_s = NULL;
  85539. struct test_memio_ctx test_ctx;
  85540. EXPECT_DECLS;
  85541. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85542. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85543. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85544. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  85545. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  85546. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  85547. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  85548. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  85549. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  85550. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  85551. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  85552. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  85553. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  85554. wolfSSL_free(ssl_c);
  85555. wolfSSL_free(ssl_s);
  85556. wolfSSL_CTX_free(ctx_c);
  85557. wolfSSL_CTX_free(ctx_s);
  85558. return EXPECT_RESULT();
  85559. }
  85560. #else
  85561. static int test_ocsp_callback_fails(void)
  85562. {
  85563. return TEST_SKIPPED;
  85564. }
  85565. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85566. defined(HAVE_OCSP) && \
  85567. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  85568. /*----------------------------------------------------------------------------*
  85569. | Main
  85570. *----------------------------------------------------------------------------*/
  85571. typedef int (*TEST_FUNC)(void);
  85572. typedef struct {
  85573. const char *name;
  85574. TEST_FUNC func;
  85575. byte run:1;
  85576. byte fail:1;
  85577. } TEST_CASE;
  85578. #define TEST_DECL(func) { #func, func, 0, 0 }
  85579. int testAll = 1;
  85580. TEST_CASE testCases[] = {
  85581. TEST_DECL(test_fileAccess),
  85582. /*********************************
  85583. * wolfcrypt
  85584. *********************************/
  85585. TEST_DECL(test_ForceZero),
  85586. TEST_DECL(test_wolfCrypt_Init),
  85587. TEST_DECL(test_wc_LoadStaticMemory_ex),
  85588. /* Locking with Compat Mutex */
  85589. TEST_DECL(test_wc_SetMutexCb),
  85590. TEST_DECL(test_wc_LockMutex_ex),
  85591. /* Digests */
  85592. TEST_DECL(test_wc_InitMd5),
  85593. TEST_DECL(test_wc_Md5Update),
  85594. TEST_DECL(test_wc_Md5Final),
  85595. TEST_DECL(test_wc_InitSha),
  85596. TEST_DECL(test_wc_ShaUpdate),
  85597. TEST_DECL(test_wc_ShaFinal),
  85598. TEST_DECL(test_wc_InitSha256),
  85599. TEST_DECL(test_wc_Sha256Update),
  85600. TEST_DECL(test_wc_Sha256Final),
  85601. TEST_DECL(test_wc_Sha256FinalRaw),
  85602. TEST_DECL(test_wc_Sha256GetFlags),
  85603. TEST_DECL(test_wc_Sha256Free),
  85604. TEST_DECL(test_wc_Sha256GetHash),
  85605. TEST_DECL(test_wc_Sha256Copy),
  85606. TEST_DECL(test_wc_InitSha224),
  85607. TEST_DECL(test_wc_Sha224Update),
  85608. TEST_DECL(test_wc_Sha224Final),
  85609. TEST_DECL(test_wc_Sha224SetFlags),
  85610. TEST_DECL(test_wc_Sha224GetFlags),
  85611. TEST_DECL(test_wc_Sha224Free),
  85612. TEST_DECL(test_wc_Sha224GetHash),
  85613. TEST_DECL(test_wc_Sha224Copy),
  85614. TEST_DECL(test_wc_InitSha512),
  85615. TEST_DECL(test_wc_Sha512Update),
  85616. TEST_DECL(test_wc_Sha512Final),
  85617. TEST_DECL(test_wc_Sha512GetFlags),
  85618. TEST_DECL(test_wc_Sha512FinalRaw),
  85619. TEST_DECL(test_wc_Sha512Free),
  85620. TEST_DECL(test_wc_Sha512GetHash),
  85621. TEST_DECL(test_wc_Sha512Copy),
  85622. TEST_DECL(test_wc_InitSha512_224),
  85623. TEST_DECL(test_wc_Sha512_224Update),
  85624. TEST_DECL(test_wc_Sha512_224Final),
  85625. TEST_DECL(test_wc_Sha512_224GetFlags),
  85626. TEST_DECL(test_wc_Sha512_224FinalRaw),
  85627. TEST_DECL(test_wc_Sha512_224Free),
  85628. TEST_DECL(test_wc_Sha512_224GetHash),
  85629. TEST_DECL(test_wc_Sha512_224Copy),
  85630. TEST_DECL(test_wc_InitSha512_256),
  85631. TEST_DECL(test_wc_Sha512_256Update),
  85632. TEST_DECL(test_wc_Sha512_256Final),
  85633. TEST_DECL(test_wc_Sha512_256GetFlags),
  85634. TEST_DECL(test_wc_Sha512_256FinalRaw),
  85635. TEST_DECL(test_wc_Sha512_256Free),
  85636. TEST_DECL(test_wc_Sha512_256GetHash),
  85637. TEST_DECL(test_wc_Sha512_256Copy),
  85638. TEST_DECL(test_wc_InitSha384),
  85639. TEST_DECL(test_wc_Sha384Update),
  85640. TEST_DECL(test_wc_Sha384Final),
  85641. TEST_DECL(test_wc_Sha384GetFlags),
  85642. TEST_DECL(test_wc_Sha384FinalRaw),
  85643. TEST_DECL(test_wc_Sha384Free),
  85644. TEST_DECL(test_wc_Sha384GetHash),
  85645. TEST_DECL(test_wc_Sha384Copy),
  85646. TEST_DECL(test_wc_InitBlake2b),
  85647. TEST_DECL(test_wc_InitBlake2b_WithKey),
  85648. TEST_DECL(test_wc_InitBlake2s_WithKey),
  85649. TEST_DECL(test_wc_InitRipeMd),
  85650. TEST_DECL(test_wc_RipeMdUpdate),
  85651. TEST_DECL(test_wc_RipeMdFinal),
  85652. TEST_DECL(test_wc_InitSha3),
  85653. TEST_DECL(testing_wc_Sha3_Update),
  85654. TEST_DECL(test_wc_Sha3_224_Final),
  85655. TEST_DECL(test_wc_Sha3_256_Final),
  85656. TEST_DECL(test_wc_Sha3_384_Final),
  85657. TEST_DECL(test_wc_Sha3_512_Final),
  85658. TEST_DECL(test_wc_Sha3_224_Copy),
  85659. TEST_DECL(test_wc_Sha3_256_Copy),
  85660. TEST_DECL(test_wc_Sha3_384_Copy),
  85661. TEST_DECL(test_wc_Sha3_512_Copy),
  85662. TEST_DECL(test_wc_Sha3_GetFlags),
  85663. TEST_DECL(test_wc_InitShake256),
  85664. TEST_DECL(testing_wc_Shake256_Update),
  85665. TEST_DECL(test_wc_Shake256_Final),
  85666. TEST_DECL(test_wc_Shake256_Copy),
  85667. TEST_DECL(test_wc_Shake256Hash),
  85668. /* SM3 Digest */
  85669. TEST_DECL(test_wc_InitSm3Free),
  85670. TEST_DECL(test_wc_Sm3UpdateFinal),
  85671. TEST_DECL(test_wc_Sm3GetHash),
  85672. TEST_DECL(test_wc_Sm3Copy),
  85673. TEST_DECL(test_wc_Sm3FinalRaw),
  85674. TEST_DECL(test_wc_Sm3GetSetFlags),
  85675. TEST_DECL(test_wc_Sm3Hash),
  85676. TEST_DECL(test_wc_HashInit),
  85677. TEST_DECL(test_wc_HashSetFlags),
  85678. TEST_DECL(test_wc_HashGetFlags),
  85679. /* HMAC */
  85680. TEST_DECL(test_wc_Md5HmacSetKey),
  85681. TEST_DECL(test_wc_Md5HmacUpdate),
  85682. TEST_DECL(test_wc_Md5HmacFinal),
  85683. TEST_DECL(test_wc_ShaHmacSetKey),
  85684. TEST_DECL(test_wc_ShaHmacUpdate),
  85685. TEST_DECL(test_wc_ShaHmacFinal),
  85686. TEST_DECL(test_wc_Sha224HmacSetKey),
  85687. TEST_DECL(test_wc_Sha224HmacUpdate),
  85688. TEST_DECL(test_wc_Sha224HmacFinal),
  85689. TEST_DECL(test_wc_Sha256HmacSetKey),
  85690. TEST_DECL(test_wc_Sha256HmacUpdate),
  85691. TEST_DECL(test_wc_Sha256HmacFinal),
  85692. TEST_DECL(test_wc_Sha384HmacSetKey),
  85693. TEST_DECL(test_wc_Sha384HmacUpdate),
  85694. TEST_DECL(test_wc_Sha384HmacFinal),
  85695. /* CMAC */
  85696. TEST_DECL(test_wc_InitCmac),
  85697. TEST_DECL(test_wc_CmacUpdate),
  85698. TEST_DECL(test_wc_CmacFinal),
  85699. TEST_DECL(test_wc_AesCmacGenerate),
  85700. /* Cipher */
  85701. TEST_DECL(test_wc_AesGcmStream),
  85702. TEST_DECL(test_wc_Des3_SetIV),
  85703. TEST_DECL(test_wc_Des3_SetKey),
  85704. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  85705. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  85706. TEST_DECL(test_wc_Des3_EcbEncrypt),
  85707. TEST_DECL(test_wc_Chacha_SetKey),
  85708. TEST_DECL(test_wc_Chacha_Process),
  85709. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  85710. TEST_DECL(test_wc_Poly1305SetKey),
  85711. TEST_DECL(test_wc_CamelliaSetKey),
  85712. TEST_DECL(test_wc_CamelliaSetIV),
  85713. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  85714. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  85715. TEST_DECL(test_wc_Arc4SetKey),
  85716. TEST_DECL(test_wc_Arc4Process),
  85717. TEST_DECL(test_wc_Rc2SetKey),
  85718. TEST_DECL(test_wc_Rc2SetIV),
  85719. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  85720. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  85721. /* AES cipher and GMAC. */
  85722. TEST_DECL(test_wc_AesSetKey),
  85723. TEST_DECL(test_wc_AesSetIV),
  85724. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  85725. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  85726. TEST_DECL(test_wc_AesGcmSetKey),
  85727. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  85728. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  85729. TEST_DECL(test_wc_GmacSetKey),
  85730. TEST_DECL(test_wc_GmacUpdate),
  85731. TEST_DECL(test_wc_AesCcmSetKey),
  85732. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  85733. #if defined(WOLFSSL_AES_EAX) && \
  85734. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  85735. TEST_DECL(test_wc_AesEaxVectors),
  85736. TEST_DECL(test_wc_AesEaxEncryptAuth),
  85737. TEST_DECL(test_wc_AesEaxDecryptAuth),
  85738. #endif /* WOLFSSL_AES_EAX */
  85739. /* SM4 cipher */
  85740. TEST_DECL(test_wc_Sm4),
  85741. TEST_DECL(test_wc_Sm4Ecb),
  85742. TEST_DECL(test_wc_Sm4Cbc),
  85743. TEST_DECL(test_wc_Sm4Ctr),
  85744. TEST_DECL(test_wc_Sm4Gcm),
  85745. TEST_DECL(test_wc_Sm4Ccm),
  85746. /* RNG tests */
  85747. #ifdef HAVE_HASHDRBG
  85748. #ifdef TEST_RESEED_INTERVAL
  85749. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  85750. #endif
  85751. TEST_DECL(test_wc_RNG_GenerateBlock),
  85752. #endif
  85753. TEST_DECL(test_get_rand_digit),
  85754. TEST_DECL(test_wc_InitRngNonce),
  85755. TEST_DECL(test_wc_InitRngNonce_ex),
  85756. /* MP API tests */
  85757. TEST_DECL(test_get_digit_count),
  85758. TEST_DECL(test_mp_cond_copy),
  85759. TEST_DECL(test_mp_rand),
  85760. TEST_DECL(test_get_digit),
  85761. TEST_DECL(test_wc_export_int),
  85762. /* RSA */
  85763. TEST_DECL(test_wc_InitRsaKey),
  85764. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  85765. TEST_DECL(test_wc_RsaPublicKeyDecode),
  85766. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  85767. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  85768. TEST_DECL(test_wc_MakeRsaKey),
  85769. TEST_DECL(test_wc_CheckProbablePrime),
  85770. TEST_DECL(test_wc_RsaPSS_Verify),
  85771. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  85772. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  85773. TEST_DECL(test_wc_RsaKeyToDer),
  85774. TEST_DECL(test_wc_RsaKeyToPublicDer),
  85775. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  85776. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  85777. TEST_DECL(test_wc_RsaEncryptSize),
  85778. TEST_DECL(test_wc_RsaSSL_SignVerify),
  85779. TEST_DECL(test_wc_RsaFlattenPublicKey),
  85780. TEST_DECL(test_RsaDecryptBoundsCheck),
  85781. /* DSA */
  85782. TEST_DECL(test_wc_InitDsaKey),
  85783. TEST_DECL(test_wc_DsaSignVerify),
  85784. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  85785. TEST_DECL(test_wc_MakeDsaKey),
  85786. TEST_DECL(test_wc_DsaKeyToDer),
  85787. TEST_DECL(test_wc_DsaKeyToPublicDer),
  85788. TEST_DECL(test_wc_DsaImportParamsRaw),
  85789. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  85790. TEST_DECL(test_wc_DsaExportParamsRaw),
  85791. TEST_DECL(test_wc_DsaExportKeyRaw),
  85792. /* DH */
  85793. TEST_DECL(test_wc_DhPublicKeyDecode),
  85794. /* wolfCrypt ECC tests */
  85795. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  85796. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  85797. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  85798. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  85799. !defined(HAVE_SELFTEST) && \
  85800. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  85801. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  85802. #endif
  85803. TEST_DECL(test_wc_ecc_make_key),
  85804. TEST_DECL(test_wc_ecc_init),
  85805. TEST_DECL(test_wc_ecc_check_key),
  85806. TEST_DECL(test_wc_ecc_get_generator),
  85807. TEST_DECL(test_wc_ecc_size),
  85808. TEST_DECL(test_wc_ecc_params),
  85809. TEST_DECL(test_wc_ecc_signVerify_hash),
  85810. TEST_DECL(test_wc_ecc_shared_secret),
  85811. TEST_DECL(test_wc_ecc_export_x963),
  85812. TEST_DECL(test_wc_ecc_export_x963_ex),
  85813. TEST_DECL(test_wc_ecc_import_x963),
  85814. TEST_DECL(test_wc_ecc_import_private_key),
  85815. TEST_DECL(test_wc_ecc_export_private_only),
  85816. TEST_DECL(test_wc_ecc_rs_to_sig),
  85817. TEST_DECL(test_wc_ecc_import_raw),
  85818. TEST_DECL(test_wc_ecc_import_unsigned),
  85819. TEST_DECL(test_wc_ecc_sig_size),
  85820. TEST_DECL(test_wc_ecc_ctx_new),
  85821. TEST_DECL(test_wc_ecc_ctx_reset),
  85822. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  85823. TEST_DECL(test_wc_ecc_ctx_set_info),
  85824. TEST_DECL(test_wc_ecc_encryptDecrypt),
  85825. TEST_DECL(test_wc_ecc_del_point),
  85826. TEST_DECL(test_wc_ecc_pointFns),
  85827. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  85828. TEST_DECL(test_wc_ecc_verify_hash_ex),
  85829. TEST_DECL(test_wc_ecc_mulmod),
  85830. TEST_DECL(test_wc_ecc_is_valid_idx),
  85831. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  85832. TEST_DECL(test_wc_ecc_sig_size_calc),
  85833. TEST_DECL(test_wc_EccPrivateKeyToDer),
  85834. /* SM2 elliptic curve */
  85835. TEST_DECL(test_wc_ecc_sm2_make_key),
  85836. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  85837. TEST_DECL(test_wc_ecc_sm2_create_digest),
  85838. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  85839. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  85840. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  85841. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  85842. /* Curve25519 */
  85843. TEST_DECL(test_wc_curve25519_init),
  85844. TEST_DECL(test_wc_curve25519_size),
  85845. TEST_DECL(test_wc_curve25519_export_key_raw),
  85846. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  85847. TEST_DECL(test_wc_curve25519_make_key),
  85848. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  85849. TEST_DECL(test_wc_curve25519_make_pub),
  85850. TEST_DECL(test_wc_curve25519_export_public_ex),
  85851. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  85852. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  85853. TEST_DECL(test_wc_curve25519_import_private),
  85854. /* ED25519 */
  85855. TEST_DECL(test_wc_ed25519_make_key),
  85856. TEST_DECL(test_wc_ed25519_init),
  85857. TEST_DECL(test_wc_ed25519_sign_msg),
  85858. TEST_DECL(test_wc_ed25519_import_public),
  85859. TEST_DECL(test_wc_ed25519_import_private_key),
  85860. TEST_DECL(test_wc_ed25519_export),
  85861. TEST_DECL(test_wc_ed25519_size),
  85862. TEST_DECL(test_wc_ed25519_exportKey),
  85863. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  85864. TEST_DECL(test_wc_Ed25519KeyToDer),
  85865. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  85866. /* Curve448 */
  85867. TEST_DECL(test_wc_curve448_make_key),
  85868. TEST_DECL(test_wc_curve448_shared_secret_ex),
  85869. TEST_DECL(test_wc_curve448_export_public_ex),
  85870. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  85871. TEST_DECL(test_wc_curve448_export_key_raw),
  85872. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  85873. TEST_DECL(test_wc_curve448_import_private),
  85874. TEST_DECL(test_wc_curve448_init),
  85875. TEST_DECL(test_wc_curve448_size),
  85876. /* Ed448 */
  85877. TEST_DECL(test_wc_ed448_make_key),
  85878. TEST_DECL(test_wc_ed448_init),
  85879. TEST_DECL(test_wc_ed448_sign_msg),
  85880. TEST_DECL(test_wc_ed448_import_public),
  85881. TEST_DECL(test_wc_ed448_import_private_key),
  85882. TEST_DECL(test_wc_ed448_export),
  85883. TEST_DECL(test_wc_ed448_size),
  85884. TEST_DECL(test_wc_ed448_exportKey),
  85885. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  85886. TEST_DECL(test_wc_Ed448KeyToDer),
  85887. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  85888. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  85889. /* Kyber */
  85890. TEST_DECL(test_wc_kyber_make_key_kats),
  85891. TEST_DECL(test_wc_kyber_encapsulate_kats),
  85892. TEST_DECL(test_wc_kyber_decapsulate_kats),
  85893. /* Dilithium */
  85894. TEST_DECL(test_wc_dilithium),
  85895. TEST_DECL(test_wc_dilithium_make_key),
  85896. TEST_DECL(test_wc_dilithium_sign),
  85897. TEST_DECL(test_wc_dilithium_verify),
  85898. TEST_DECL(test_wc_dilithium_sign_vfy),
  85899. TEST_DECL(test_wc_dilithium_check_key),
  85900. TEST_DECL(test_wc_dilithium_public_der_decode),
  85901. TEST_DECL(test_wc_dilithium_der),
  85902. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  85903. TEST_DECL(test_wc_dilithium_sig_kats),
  85904. TEST_DECL(test_wc_dilithium_verify_kats),
  85905. /* Signature API */
  85906. TEST_DECL(test_wc_SignatureGetSize_ecc),
  85907. TEST_DECL(test_wc_SignatureGetSize_rsa),
  85908. /* PEM and DER APIs. */
  85909. TEST_DECL(test_wc_PemToDer),
  85910. TEST_DECL(test_wc_AllocDer),
  85911. TEST_DECL(test_wc_CertPemToDer),
  85912. TEST_DECL(test_wc_KeyPemToDer),
  85913. TEST_DECL(test_wc_PubKeyPemToDer),
  85914. TEST_DECL(test_wc_PemPubKeyToDer),
  85915. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  85916. TEST_DECL(test_wc_CheckCertSigPubKey),
  85917. /* wolfCrypt ASN tests */
  85918. TEST_DECL(test_ToTraditional),
  85919. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  85920. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  85921. /* Certificate */
  85922. TEST_DECL(test_wc_SetSubjectRaw),
  85923. TEST_DECL(test_wc_GetSubjectRaw),
  85924. TEST_DECL(test_wc_SetIssuerRaw),
  85925. TEST_DECL(test_wc_SetIssueBuffer),
  85926. TEST_DECL(test_wc_SetSubjectKeyId),
  85927. TEST_DECL(test_wc_SetSubject),
  85928. TEST_DECL(test_CheckCertSignature),
  85929. TEST_DECL(test_wc_ParseCert),
  85930. TEST_DECL(test_wc_ParseCert_Error),
  85931. TEST_DECL(test_MakeCertWithPathLen),
  85932. TEST_DECL(test_MakeCertWith0Ser),
  85933. TEST_DECL(test_MakeCertWithCaFalse),
  85934. TEST_DECL(test_wc_SetKeyUsage),
  85935. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  85936. TEST_DECL(test_wc_SetSubjectBuffer),
  85937. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  85938. /* wolfcrypt PKCS#7 */
  85939. TEST_DECL(test_wc_PKCS7_New),
  85940. TEST_DECL(test_wc_PKCS7_Init),
  85941. TEST_DECL(test_wc_PKCS7_InitWithCert),
  85942. TEST_DECL(test_wc_PKCS7_EncodeData),
  85943. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  85944. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  85945. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  85946. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  85947. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  85948. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  85949. TEST_DECL(test_wc_PKCS7_Degenerate),
  85950. TEST_DECL(test_wc_PKCS7_BER),
  85951. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  85952. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  85953. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  85954. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  85955. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  85956. /* wolfCrypt PKCS#12 */
  85957. TEST_DECL(test_wc_i2d_PKCS12),
  85958. /*
  85959. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  85960. * avoid memory leaks.
  85961. */
  85962. TEST_DECL(test_wolfCrypt_Cleanup),
  85963. TEST_DECL(test_wolfSSL_Init),
  85964. TEST_DECL(test_dual_alg_support),
  85965. /*********************************
  85966. * OpenSSL compatibility API tests
  85967. *********************************/
  85968. /* If at some point a stub get implemented this test should fail indicating
  85969. * a need to implement a new test case
  85970. */
  85971. TEST_DECL(test_stubs_are_stubs),
  85972. /* ASN.1 compatibility API tests */
  85973. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  85974. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  85975. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  85976. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  85977. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  85978. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  85979. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  85980. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  85981. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  85982. TEST_DECL(test_wolfSSL_ASN1_get_object),
  85983. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  85984. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  85985. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  85986. TEST_DECL(test_wolfSSL_ASN1_STRING),
  85987. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  85988. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  85989. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  85990. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  85991. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  85992. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  85993. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  85994. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  85995. TEST_DECL(test_wolfSSL_ASN1_TIME),
  85996. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  85997. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  85998. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  85999. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  86000. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  86001. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  86002. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  86003. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  86004. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  86005. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  86006. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  86007. TEST_DECL(test_ASN1_strings),
  86008. TEST_DECL(test_wolfSSL_lhash),
  86009. TEST_DECL(test_wolfSSL_certs),
  86010. TEST_DECL(test_wolfSSL_private_keys),
  86011. TEST_DECL(test_wolfSSL_PEM_def_callback),
  86012. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  86013. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  86014. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  86015. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  86016. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  86017. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  86018. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  86019. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  86020. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  86021. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  86022. #ifndef NO_BIO
  86023. TEST_DECL(test_wolfSSL_BIO),
  86024. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  86025. TEST_DECL(test_wolfSSL_PEM_read_bio),
  86026. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  86027. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  86028. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  86029. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  86030. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  86031. #endif
  86032. /* EVP API testing */
  86033. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  86034. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  86035. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  86036. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  86037. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  86038. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  86039. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  86040. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  86041. TEST_DECL(test_wolfSSL_EVP_shake128),
  86042. TEST_DECL(test_wolfSSL_EVP_shake256),
  86043. TEST_DECL(test_wolfSSL_EVP_sm3),
  86044. TEST_DECL(test_EVP_blake2),
  86045. #ifdef OPENSSL_ALL
  86046. TEST_DECL(test_wolfSSL_EVP_md4),
  86047. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  86048. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  86049. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  86050. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  86051. #endif
  86052. TEST_DECL(test_EVP_MD_do_all),
  86053. TEST_DECL(test_wolfSSL_EVP_MD_size),
  86054. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  86055. TEST_DECL(test_wolfSSL_EVP_Digest),
  86056. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  86057. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  86058. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  86059. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  86060. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  86061. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  86062. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  86063. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  86064. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  86065. TEST_DECL(test_wolfssl_EVP_chacha20),
  86066. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  86067. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  86068. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  86069. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  86070. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  86071. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  86072. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  86073. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  86074. #ifdef OPENSSL_ALL
  86075. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  86076. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  86077. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  86078. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  86079. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  86080. TEST_DECL(test_wolfSSL_EVP_rc4),
  86081. TEST_DECL(test_wolfSSL_EVP_enc_null),
  86082. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  86083. TEST_DECL(test_wolfSSL_EVP_mdc2),
  86084. TEST_DECL(test_evp_cipher_aes_gcm),
  86085. #endif
  86086. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  86087. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  86088. #ifdef OPENSSL_EXTRA
  86089. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  86090. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  86091. #endif
  86092. #ifdef OPENSSL_ALL
  86093. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  86094. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  86095. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  86096. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  86097. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  86098. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  86099. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  86100. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  86101. #endif
  86102. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  86103. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  86104. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  86105. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  86106. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  86107. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  86108. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  86109. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  86110. #ifndef NO_BIO
  86111. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  86112. #endif
  86113. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  86114. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  86115. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86116. #ifndef NO_BIO
  86117. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  86118. #endif /* !NO_BIO */
  86119. #endif
  86120. #ifdef OPENSSL_ALL
  86121. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  86122. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  86123. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  86124. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  86125. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  86126. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  86127. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  86128. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  86129. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  86130. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  86131. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  86132. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  86133. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  86134. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  86135. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  86136. #endif
  86137. TEST_DECL(test_EVP_PKEY_rsa),
  86138. TEST_DECL(test_EVP_PKEY_ec),
  86139. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  86140. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  86141. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  86142. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  86143. TEST_DECL(test_EVP_PKEY_cmp),
  86144. #ifdef OPENSSL_ALL
  86145. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  86146. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  86147. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  86148. #endif
  86149. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  86150. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  86151. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  86152. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  86153. #endif
  86154. #ifndef NO_BIO
  86155. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  86156. TEST_DECL(test_wolfSSL_GetLoggingCb),
  86157. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  86158. TEST_DECL(test_wc_ERR_remove_state),
  86159. TEST_DECL(test_wc_ERR_print_errors_fp),
  86160. #endif
  86161. TEST_DECL(test_wolfSSL_configure_args),
  86162. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  86163. TEST_DECL(test_wolfSSL_set1_curves_list),
  86164. TEST_DECL(test_wolfSSL_curves_mismatch),
  86165. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  86166. TEST_DECL(test_wolfSSL_OtherName),
  86167. TEST_DECL(test_wolfSSL_FPKI),
  86168. TEST_DECL(test_wolfSSL_URI),
  86169. TEST_DECL(test_wolfSSL_TBS),
  86170. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  86171. TEST_DECL(test_X509_STORE_untrusted),
  86172. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  86173. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  86174. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  86175. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  86176. TEST_DECL(test_wolfSSL_X509_Name_canon),
  86177. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  86178. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  86179. TEST_DECL(test_wolfSSL_X509_NID),
  86180. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  86181. TEST_DECL(test_wolfSSL_get0_param),
  86182. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  86183. TEST_DECL(test_wolfSSL_set1_host),
  86184. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  86185. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  86186. TEST_DECL(test_wolfSSL_X509_STORE),
  86187. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  86188. TEST_DECL(test_X509_STORE_get0_objects),
  86189. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  86190. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  86191. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  86192. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  86193. TEST_DECL(test_wolfSSL_X509_cmp_time),
  86194. TEST_DECL(test_wolfSSL_X509_time_adj),
  86195. /* X509 tests */
  86196. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  86197. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  86198. TEST_DECL(test_wolfSSL_X509_check_host),
  86199. TEST_DECL(test_wolfSSL_X509_check_email),
  86200. TEST_DECL(test_wolfSSL_X509_check_private_key),
  86201. TEST_DECL(test_wolfSSL_X509),
  86202. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  86203. TEST_DECL(test_wolfSSL_X509_sign),
  86204. TEST_DECL(test_wolfSSL_X509_sign2),
  86205. TEST_DECL(test_wolfSSL_X509_verify),
  86206. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  86207. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  86208. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  86209. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  86210. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  86211. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  86212. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  86213. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  86214. TEST_DECL(test_wolfSSL_X509_NAME),
  86215. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  86216. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  86217. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  86218. TEST_DECL(test_wolfSSL_X509_set_name),
  86219. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  86220. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  86221. TEST_DECL(test_wolfSSL_X509_set_version),
  86222. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  86223. TEST_DECL(test_wolfSSL_X509_CRL),
  86224. TEST_DECL(test_wolfSSL_i2d_X509),
  86225. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  86226. TEST_DECL(test_wolfSSL_PEM_read_X509),
  86227. TEST_DECL(test_wolfSSL_X509_check_ca),
  86228. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  86229. TEST_DECL(test_wolfSSL_X509_bad_altname),
  86230. TEST_DECL(test_wolfSSL_X509_name_match),
  86231. TEST_DECL(test_wolfSSL_X509_name_match2),
  86232. TEST_DECL(test_wolfSSL_X509_name_match3),
  86233. TEST_DECL(test_wolfSSL_X509_max_altnames),
  86234. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  86235. TEST_DECL(test_wolfSSL_make_cert),
  86236. /* X509 ACERT tests */
  86237. TEST_DECL(test_wolfSSL_X509_ACERT_verify),
  86238. TEST_DECL(test_wolfSSL_X509_ACERT_misc_api),
  86239. #ifndef NO_BIO
  86240. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  86241. TEST_DECL(test_wolfSSL_X509_INFO),
  86242. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  86243. #endif
  86244. #ifdef OPENSSL_ALL
  86245. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  86246. #endif
  86247. TEST_DECL(test_wolfSSL_X509_CA_num),
  86248. TEST_DECL(test_x509_get_key_id),
  86249. TEST_DECL(test_wolfSSL_X509_get_version),
  86250. #ifndef NO_BIO
  86251. TEST_DECL(test_wolfSSL_X509_print),
  86252. TEST_DECL(test_wolfSSL_X509_CRL_print),
  86253. #endif
  86254. TEST_DECL(test_X509_get_signature_nid),
  86255. /* X509 extension testing. */
  86256. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  86257. TEST_DECL(test_wolfSSL_X509_get_ext),
  86258. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  86259. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  86260. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  86261. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  86262. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  86263. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  86264. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  86265. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  86266. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  86267. TEST_DECL(test_wolfSSL_X509V3_EXT),
  86268. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  86269. TEST_DECL(test_wolfSSL_X509_cmp),
  86270. TEST_DECL(test_GENERAL_NAME_set0_othername),
  86271. TEST_DECL(test_othername_and_SID_ext),
  86272. TEST_DECL(test_wolfSSL_dup_CA_list),
  86273. /* OpenSSL sk_X509 API test */
  86274. TEST_DECL(test_sk_X509),
  86275. /* OpenSSL sk_X509_CRL API test */
  86276. TEST_DECL(test_sk_X509_CRL),
  86277. /* OpenSSL X509 REQ API test */
  86278. TEST_DECL(test_X509_REQ),
  86279. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  86280. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  86281. TEST_DECL(test_X509_LOOKUP_add_dir),
  86282. /* RAND compatibility API */
  86283. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  86284. TEST_DECL(test_wolfSSL_RAND_bytes),
  86285. TEST_DECL(test_wolfSSL_RAND),
  86286. /* BN compatibility API */
  86287. TEST_DECL(test_wolfSSL_BN_CTX),
  86288. TEST_DECL(test_wolfSSL_BN),
  86289. TEST_DECL(test_wolfSSL_BN_init),
  86290. TEST_DECL(test_wolfSSL_BN_enc_dec),
  86291. TEST_DECL(test_wolfSSL_BN_word),
  86292. TEST_DECL(test_wolfSSL_BN_bits),
  86293. TEST_DECL(test_wolfSSL_BN_shift),
  86294. TEST_DECL(test_wolfSSL_BN_math),
  86295. TEST_DECL(test_wolfSSL_BN_math_mod),
  86296. TEST_DECL(test_wolfSSL_BN_math_other),
  86297. TEST_DECL(test_wolfSSL_BN_rand),
  86298. TEST_DECL(test_wolfSSL_BN_prime),
  86299. /* OpenSSL PKCS5 API test */
  86300. TEST_DECL(test_wolfSSL_PKCS5),
  86301. /* OpenSSL PKCS8 API test */
  86302. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  86303. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  86304. /* OpenSSL PKCS7 API test */
  86305. TEST_DECL(test_wolfssl_PKCS7),
  86306. TEST_DECL(test_wolfSSL_PKCS7_certs),
  86307. TEST_DECL(test_wolfSSL_PKCS7_sign),
  86308. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  86309. #ifndef NO_BIO
  86310. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  86311. #ifdef HAVE_SMIME
  86312. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  86313. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  86314. #endif /* HAVE_SMIME */
  86315. #endif /* !NO_BIO */
  86316. /* OpenSSL PKCS12 API test */
  86317. TEST_DECL(test_wolfSSL_PKCS12),
  86318. /* Can't memory test as callbacks use Assert. */
  86319. TEST_DECL(test_error_queue_per_thread),
  86320. TEST_DECL(test_wolfSSL_ERR_put_error),
  86321. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  86322. #ifndef NO_BIO
  86323. TEST_DECL(test_wolfSSL_ERR_print_errors),
  86324. #endif
  86325. TEST_DECL(test_OBJ_NAME_do_all),
  86326. TEST_DECL(test_wolfSSL_OBJ),
  86327. TEST_DECL(test_wolfSSL_OBJ_cmp),
  86328. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  86329. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  86330. #ifdef OPENSSL_ALL
  86331. TEST_DECL(test_wolfSSL_OBJ_ln),
  86332. TEST_DECL(test_wolfSSL_OBJ_sn),
  86333. #endif
  86334. #ifndef NO_BIO
  86335. TEST_DECL(test_wolfSSL_BIO_gets),
  86336. TEST_DECL(test_wolfSSL_BIO_puts),
  86337. TEST_DECL(test_wolfSSL_BIO_dump),
  86338. /* Can't memory test as server hangs. */
  86339. TEST_DECL(test_wolfSSL_BIO_should_retry),
  86340. TEST_DECL(test_wolfSSL_BIO_write),
  86341. TEST_DECL(test_wolfSSL_BIO_printf),
  86342. TEST_DECL(test_wolfSSL_BIO_f_md),
  86343. TEST_DECL(test_wolfSSL_BIO_up_ref),
  86344. TEST_DECL(test_wolfSSL_BIO_reset),
  86345. TEST_DECL(test_wolfSSL_BIO_get_len),
  86346. #endif
  86347. TEST_DECL(test_wolfSSL_check_domain),
  86348. TEST_DECL(test_wolfSSL_cert_cb),
  86349. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  86350. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  86351. TEST_DECL(test_wolfSSL_sigalg_info),
  86352. /* Can't memory test as tcp_connect aborts. */
  86353. TEST_DECL(test_wolfSSL_SESSION),
  86354. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  86355. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  86356. TEST_DECL(test_wolfSSL_ticket_keys),
  86357. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  86358. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  86359. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  86360. TEST_DECL(test_wolfSSL_verify_mode),
  86361. TEST_DECL(test_wolfSSL_verify_depth),
  86362. TEST_DECL(test_wolfSSL_verify_result),
  86363. TEST_DECL(test_wolfSSL_msg_callback),
  86364. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  86365. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  86366. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  86367. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  86368. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  86369. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  86370. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  86371. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  86372. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  86373. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  86374. TEST_DECL(test_wolfSSL_PEM_read),
  86375. TEST_DECL(test_wolfSSL_OpenSSL_version),
  86376. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  86377. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  86378. TEST_DECL(test_CONF_modules_xxx),
  86379. #ifdef OPENSSL_ALL
  86380. TEST_DECL(test_wolfSSL_TXT_DB),
  86381. TEST_DECL(test_wolfSSL_NCONF),
  86382. #endif
  86383. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  86384. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  86385. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  86386. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  86387. TEST_DECL(test_CRYPTO_THREADID_xxx),
  86388. TEST_DECL(test_ENGINE_cleanup),
  86389. /* test the no op functions for compatibility */
  86390. TEST_DECL(test_no_op_functions),
  86391. /* OpenSSL error API tests */
  86392. TEST_DECL(test_ERR_load_crypto_strings),
  86393. #ifdef OPENSSL_ALL
  86394. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  86395. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  86396. TEST_DECL(test_wolfSSL_CTX_ctrl),
  86397. #endif /* OPENSSL_ALL */
  86398. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86399. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  86400. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  86401. /*********************************
  86402. * Crypto API tests
  86403. *********************************/
  86404. TEST_DECL(test_wolfSSL_MD4),
  86405. TEST_DECL(test_wolfSSL_MD5),
  86406. TEST_DECL(test_wolfSSL_MD5_Transform),
  86407. TEST_DECL(test_wolfSSL_SHA),
  86408. TEST_DECL(test_wolfSSL_SHA_Transform),
  86409. TEST_DECL(test_wolfSSL_SHA224),
  86410. TEST_DECL(test_wolfSSL_SHA256),
  86411. TEST_DECL(test_wolfSSL_SHA256_Transform),
  86412. TEST_DECL(test_wolfSSL_SHA512_Transform),
  86413. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  86414. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  86415. TEST_DECL(test_wolfSSL_HMAC_CTX),
  86416. TEST_DECL(test_wolfSSL_HMAC),
  86417. TEST_DECL(test_wolfSSL_CMAC),
  86418. TEST_DECL(test_wolfSSL_DES),
  86419. TEST_DECL(test_wolfSSL_DES_ncbc),
  86420. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  86421. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  86422. TEST_DECL(test_wolfSSL_AES_encrypt),
  86423. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  86424. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  86425. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  86426. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  86427. TEST_DECL(test_wolfSSL_RC4),
  86428. TEST_DECL(test_wolfSSL_RSA),
  86429. TEST_DECL(test_wolfSSL_RSA_DER),
  86430. TEST_DECL(test_wolfSSL_RSA_print),
  86431. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  86432. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  86433. TEST_DECL(test_wolfSSL_RSA_get0_key),
  86434. TEST_DECL(test_wolfSSL_RSA_meth),
  86435. TEST_DECL(test_wolfSSL_RSA_verify),
  86436. TEST_DECL(test_wolfSSL_RSA_sign),
  86437. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  86438. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  86439. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  86440. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  86441. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  86442. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  86443. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  86444. TEST_DECL(test_wolfSSL_RSA_ex_data),
  86445. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  86446. TEST_DECL(test_wolfSSL_RSA_To_Der),
  86447. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  86448. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  86449. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  86450. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  86451. TEST_DECL(test_wolfSSL_DH),
  86452. TEST_DECL(test_wolfSSL_DH_dup),
  86453. TEST_DECL(test_wolfSSL_DH_check),
  86454. TEST_DECL(test_wolfSSL_DH_prime),
  86455. TEST_DECL(test_wolfSSL_DH_1536_prime),
  86456. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  86457. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  86458. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  86459. TEST_DECL(test_wolfSSL_d2i_DHparams),
  86460. TEST_DECL(test_wolfSSL_DH_LoadDer),
  86461. TEST_DECL(test_wolfSSL_i2d_DHparams),
  86462. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  86463. TEST_DECL(test_wolfSSL_EC_GROUP),
  86464. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  86465. TEST_DECL(test_wolfSSL_EC_POINT),
  86466. TEST_DECL(test_wolfSSL_SPAKE),
  86467. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  86468. TEST_DECL(test_EC_i2d),
  86469. TEST_DECL(test_wolfSSL_EC_curve),
  86470. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  86471. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  86472. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  86473. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  86474. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  86475. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  86476. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  86477. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  86478. TEST_DECL(test_ECDSA_size_sign),
  86479. TEST_DECL(test_ECDH_compute_key),
  86480. #endif
  86481. #ifdef OPENSSL_EXTRA
  86482. TEST_DECL(test_EC25519),
  86483. TEST_DECL(test_ED25519),
  86484. TEST_DECL(test_EC448),
  86485. TEST_DECL(test_ED448),
  86486. #endif
  86487. TEST_DECL(test_DSA_do_sign_verify),
  86488. #ifdef OPENSSL_ALL
  86489. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  86490. TEST_DECL(test_wolfSSL_DSA_SIG),
  86491. #endif
  86492. TEST_DECL(test_openssl_generate_key_and_cert),
  86493. TEST_DECL(test_wolfSSL_FIPS_mode),
  86494. TEST_DECL(test_openssl_FIPS_drbg),
  86495. /*********************************
  86496. * CertManager API tests
  86497. *********************************/
  86498. TEST_DECL(test_wolfSSL_CertManagerAPI),
  86499. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  86500. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  86501. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  86502. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  86503. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  86504. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  86505. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  86506. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  86507. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  86508. TEST_DECL(test_wolfSSL_CertManagerCRL),
  86509. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  86510. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  86511. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86512. TEST_DECL(test_various_pathlen_chains),
  86513. #endif
  86514. /*********************************
  86515. * SSL/TLS API tests
  86516. *********************************/
  86517. TEST_DECL(test_wolfSSL_Method_Allocators),
  86518. #ifndef NO_WOLFSSL_SERVER
  86519. TEST_DECL(test_wolfSSL_CTX_new),
  86520. #endif
  86521. TEST_DECL(test_server_wolfSSL_new),
  86522. TEST_DECL(test_client_wolfSSL_new),
  86523. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  86524. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  86525. TEST_DECL(test_for_double_Free),
  86526. #endif
  86527. TEST_DECL(test_wolfSSL_set_options),
  86528. #ifdef WOLFSSL_TLS13
  86529. /* TLS v1.3 API tests */
  86530. TEST_DECL(test_tls13_apis),
  86531. TEST_DECL(test_tls13_cipher_suites),
  86532. #endif
  86533. TEST_DECL(test_wolfSSL_tmp_dh),
  86534. TEST_DECL(test_wolfSSL_ctrl),
  86535. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  86536. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  86537. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  86538. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  86539. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  86540. #endif
  86541. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  86542. TEST_DECL(test_wolfSSL_security_level),
  86543. TEST_DECL(test_wolfSSL_SSL_in_init),
  86544. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  86545. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  86546. TEST_DECL(test_CONF_CTX_FILE),
  86547. TEST_DECL(test_CONF_CTX_CMDLINE),
  86548. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  86549. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  86550. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  86551. /* Bad certificate signature tests */
  86552. TEST_DECL(test_EccSigFailure_cm),
  86553. TEST_DECL(test_RsaSigFailure_cm),
  86554. #endif /* NO_CERTS */
  86555. /* PKCS8 testing */
  86556. TEST_DECL(test_wolfSSL_no_password_cb),
  86557. TEST_DECL(test_wolfSSL_PKCS8),
  86558. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  86559. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  86560. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86561. TEST_DECL(test_wolfSSL_get_finished),
  86562. /* Uses Assert in handshake callback. */
  86563. TEST_DECL(test_wolfSSL_CTX_add_session),
  86564. /* Large number of memory allocations. */
  86565. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  86566. /* Large number of memory allocations. */
  86567. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  86568. /* Large number of memory allocations. */
  86569. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  86570. /* Large number of memory allocations. */
  86571. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  86572. /* Large number of memory allocations. */
  86573. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  86574. /* Large number of memory allocations. */
  86575. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  86576. #endif
  86577. TEST_DECL(test_SSL_CIPHER_get_xxx),
  86578. TEST_DECL(test_wolfSSL_ERR_strings),
  86579. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  86580. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  86581. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  86582. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  86583. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  86584. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  86585. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  86586. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  86587. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  86588. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  86589. /* Large number of memory allocations. */
  86590. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  86591. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86592. TEST_DECL(test_wolfSSL_CertRsaPss),
  86593. #endif
  86594. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  86595. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  86596. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  86597. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  86598. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  86599. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  86600. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  86601. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  86602. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  86603. TEST_DECL(test_multiple_crls_same_issuer),
  86604. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  86605. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  86606. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  86607. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  86608. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  86609. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  86610. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  86611. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  86612. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  86613. TEST_DECL(test_SetTmpEC_DHE_Sz),
  86614. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  86615. #ifdef WOLFSSL_DTLS
  86616. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  86617. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  86618. #endif
  86619. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  86620. /* Uses Assert in handshake callback. */
  86621. TEST_DECL(test_wolfSSL_dtls_plaintext),
  86622. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  86623. defined(HAVE_IO_TESTS_DEPENDENCIES)
  86624. TEST_DECL(test_wolfSSL_read_write),
  86625. /* Can't memory test as server hangs if client fails before second connect.
  86626. */
  86627. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  86628. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  86629. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  86630. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  86631. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  86632. /* Can't memory test as server hangs. */
  86633. TEST_DECL(test_wolfSSL_dtls_export),
  86634. /* Uses Assert in handshake callback. */
  86635. TEST_DECL(test_wolfSSL_tls_export),
  86636. #endif
  86637. TEST_DECL(test_wolfSSL_dtls_export_peers),
  86638. TEST_DECL(test_wolfSSL_SetMinVersion),
  86639. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  86640. /* wolfSSL handshake APIs. */
  86641. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  86642. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  86643. TEST_DECL(test_wolfSSL_BUF),
  86644. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  86645. /* Can't memory test as server hangs. */
  86646. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  86647. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  86648. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  86649. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  86650. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  86651. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  86652. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  86653. /* Can't memory test as server hangs. */
  86654. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  86655. TEST_DECL(test_wolfSSL_Tls13_postauth),
  86656. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  86657. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  86658. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  86659. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  86660. TEST_DECL(test_wolfSSL_THREADID_hash),
  86661. /* TLS extensions tests */
  86662. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86663. #ifdef HAVE_SNI
  86664. TEST_DECL(test_wolfSSL_UseSNI_params),
  86665. /* Uses Assert in handshake callback. */
  86666. TEST_DECL(test_wolfSSL_UseSNI_connection),
  86667. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  86668. #endif /* HAVE_SNI */
  86669. #endif
  86670. TEST_DECL(test_wolfSSL_UseTrustedCA),
  86671. TEST_DECL(test_wolfSSL_UseMaxFragment),
  86672. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  86673. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  86674. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  86675. /* Uses Assert in handshake callback. */
  86676. TEST_DECL(test_wolfSSL_UseALPN_connection),
  86677. TEST_DECL(test_wolfSSL_UseALPN_params),
  86678. #endif
  86679. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  86680. /* Uses Assert in handshake callback. */
  86681. TEST_DECL(test_wolfSSL_set_alpn_protos),
  86682. #endif
  86683. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  86684. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  86685. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  86686. TEST_DECL(test_tls_ext_duplicate),
  86687. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  86688. defined(HAVE_IO_TESTS_DEPENDENCIES)
  86689. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  86690. /* Uses Assert in handshake callback. */
  86691. TEST_DECL(test_wolfSSL_Tls13_ECH),
  86692. #endif
  86693. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  86694. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  86695. /* OCSP Stapling */
  86696. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  86697. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  86698. TEST_DECL(test_self_signed_stapling),
  86699. TEST_DECL(test_ocsp_callback_fails),
  86700. /* Multicast */
  86701. TEST_DECL(test_wolfSSL_mcast),
  86702. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  86703. TEST_DECL(test_wolfSSL_msgCb),
  86704. TEST_DECL(test_wolfSSL_either_side),
  86705. TEST_DECL(test_wolfSSL_DTLS_either_side),
  86706. /* Uses Assert in handshake callback. */
  86707. TEST_DECL(test_wolfSSL_dtls_fragments),
  86708. /* Uses Assert in handshake callback. */
  86709. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  86710. /* Uses Assert in handshake callback. */
  86711. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  86712. /* Uses Assert in handshake callback. */
  86713. TEST_DECL(test_wolfSSL_dtls_bad_record),
  86714. /* Uses Assert in handshake callback. */
  86715. TEST_DECL(test_wolfSSL_dtls_stateless),
  86716. TEST_DECL(test_generate_cookie),
  86717. #ifndef NO_BIO
  86718. /* Can't memory test as server hangs. */
  86719. TEST_DECL(test_wolfSSL_BIO_connect),
  86720. /* Can't memory test as server Asserts in thread. */
  86721. TEST_DECL(test_wolfSSL_BIO_accept),
  86722. TEST_DECL(test_wolfSSL_BIO_tls),
  86723. TEST_DECL(test_wolfSSL_BIO_datagram),
  86724. #endif
  86725. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  86726. TEST_DECL(test_DhCallbacks),
  86727. #endif
  86728. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  86729. TEST_DECL(test_export_keying_material),
  86730. #endif
  86731. /* Can't memory test as client/server Asserts in thread. */
  86732. TEST_DECL(test_ticket_and_psk_mixing),
  86733. /* Can't memory test as client/server Asserts in thread. */
  86734. TEST_DECL(test_prioritize_psk),
  86735. /* Can't memory test as client/server hangs. */
  86736. TEST_DECL(test_wc_CryptoCb),
  86737. /* Can't memory test as client/server hangs. */
  86738. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  86739. #if !defined(NO_FILESYSTEM) && \
  86740. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  86741. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  86742. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  86743. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  86744. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  86745. #ifdef HAVE_MAX_FRAGMENT
  86746. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  86747. #endif /* HAVE_MAX_FRAGMENT */
  86748. #ifndef NO_RSA
  86749. TEST_DECL(test_wolfSSL_dtls_stateless2),
  86750. #if !defined(NO_OLD_TLS)
  86751. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  86752. #endif /* !defined(NO_OLD_TLS) */
  86753. #endif /* ! NO_RSA */
  86754. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  86755. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  86756. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  86757. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  86758. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  86759. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  86760. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  86761. && defined(WOLFSSL_TLS13) && \
  86762. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  86763. TEST_DECL(test_ticket_nonce_malloc),
  86764. #endif
  86765. TEST_DECL(test_ticket_ret_create),
  86766. TEST_DECL(test_wrong_cs_downgrade),
  86767. TEST_DECL(test_extra_alerts_wrong_cs),
  86768. TEST_DECL(test_extra_alerts_skip_hs),
  86769. TEST_DECL(test_extra_alerts_bad_psk),
  86770. TEST_DECL(test_multiple_alerts_EAGAIN),
  86771. TEST_DECL(test_tls13_bad_psk_binder),
  86772. /* Can't memory test as client/server Asserts. */
  86773. TEST_DECL(test_harden_no_secure_renegotiation),
  86774. TEST_DECL(test_override_alt_cert_chain),
  86775. TEST_DECL(test_rpk_set_xxx_cert_type),
  86776. TEST_DECL(test_tls13_rpk_handshake),
  86777. TEST_DECL(test_dtls13_bad_epoch_ch),
  86778. TEST_DECL(test_short_session_id),
  86779. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  86780. /* Can't memory test as client/server hangs. */
  86781. TEST_DECL(test_dtls_msg_from_other_peer),
  86782. TEST_DECL(test_dtls_ipv6_check),
  86783. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  86784. TEST_DECL(test_dtls_no_extensions),
  86785. TEST_DECL(test_tls_alert_no_server_hello),
  86786. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  86787. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  86788. TEST_DECL(test_session_ticket_no_id),
  86789. TEST_DECL(test_session_ticket_hs_update),
  86790. TEST_DECL(test_dtls_downgrade_scr_server),
  86791. TEST_DECL(test_dtls_downgrade_scr),
  86792. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  86793. TEST_DECL(test_dtls_client_hello_timeout),
  86794. TEST_DECL(test_dtls_dropped_ccs),
  86795. TEST_DECL(test_dtls_seq_num_downgrade),
  86796. TEST_DECL(test_certreq_sighash_algos),
  86797. TEST_DECL(test_revoked_loaded_int_cert),
  86798. TEST_DECL(test_dtls_frag_ch),
  86799. TEST_DECL(test_dtls13_frag_ch_pq),
  86800. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  86801. TEST_DECL(test_dtls_old_seq_number),
  86802. TEST_DECL(test_tls13_pq_groups),
  86803. TEST_DECL(test_tls13_early_data),
  86804. TEST_DECL(test_tls_multi_handshakes_one_record),
  86805. TEST_DECL(test_write_dup),
  86806. TEST_DECL(test_read_write_hs),
  86807. TEST_DECL(test_get_signature_nid),
  86808. TEST_DECL(test_tls_cert_store_unchanged),
  86809. TEST_DECL(test_wolfSSL_SendUserCanceled),
  86810. /* This test needs to stay at the end to clean up any caches allocated. */
  86811. TEST_DECL(test_wolfSSL_Cleanup)
  86812. };
  86813. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  86814. static void TestSetup(void)
  86815. {
  86816. /* Stub, for now. Add common test setup code here. */
  86817. }
  86818. static void TestCleanup(void)
  86819. {
  86820. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  86821. /* Clear any errors added to the error queue during the test run. */
  86822. wolfSSL_ERR_clear_error();
  86823. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  86824. }
  86825. /* Print out all API test cases with numeric identifier.
  86826. */
  86827. void ApiTest_PrintTestCases(void)
  86828. {
  86829. int i;
  86830. printf("All Test Cases:\n");
  86831. for (i = 0; i < TEST_CASE_CNT; i++) {
  86832. printf("%3d: %s\n", i + 1, testCases[i].name);
  86833. }
  86834. }
  86835. /* Add test case with index to the list to run.
  86836. *
  86837. * @param [in] idx Index of test case to run starting at 1.
  86838. * @return 0 on success.
  86839. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  86840. */
  86841. int ApiTest_RunIdx(int idx)
  86842. {
  86843. if (idx < 1 || idx > TEST_CASE_CNT) {
  86844. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  86845. return BAD_FUNC_ARG;
  86846. }
  86847. testAll = 0;
  86848. testCases[idx-1].run = 1;
  86849. return 0;
  86850. }
  86851. /* Add test case with name to the list to run.
  86852. *
  86853. * @param [in] name Name of test case to run.
  86854. * @return 0 on success.
  86855. * @return BAD_FUNC_ARG when name is not a known test case name.
  86856. */
  86857. int ApiTest_RunName(char* name)
  86858. {
  86859. int i;
  86860. for (i = 0; i < TEST_CASE_CNT; i++) {
  86861. if (XSTRCMP(testCases[i].name, name) == 0) {
  86862. testAll = 0;
  86863. testCases[i].run = 1;
  86864. return 0;
  86865. }
  86866. }
  86867. printf("Test case name not found: %s\n", name);
  86868. printf("Use --list to see all test case names.\n");
  86869. return BAD_FUNC_ARG;
  86870. }
  86871. /* Converts the result code to a string.
  86872. *
  86873. * @param [in] res Test result code.
  86874. * @return String describing test result.
  86875. */
  86876. static const char* apitest_res_string(int res)
  86877. {
  86878. const char* str = "invalid result";
  86879. switch (res) {
  86880. case TEST_SUCCESS:
  86881. str = "passed";
  86882. break;
  86883. case TEST_FAIL:
  86884. str = "failed";
  86885. break;
  86886. case TEST_SKIPPED:
  86887. str = "skipped";
  86888. break;
  86889. }
  86890. return str;
  86891. }
  86892. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86893. static double gettime_secs(void)
  86894. #if defined(_MSC_VER) && defined(_WIN32)
  86895. {
  86896. /* there's no gettimeofday for Windows, so we'll use system time */
  86897. #define EPOCH_DIFF 11644473600LL
  86898. FILETIME currentFileTime;
  86899. GetSystemTimePreciseAsFileTime(&currentFileTime);
  86900. ULARGE_INTEGER uli = { 0, 0 };
  86901. uli.LowPart = currentFileTime.dwLowDateTime;
  86902. uli.HighPart = currentFileTime.dwHighDateTime;
  86903. /* Convert to seconds since Unix epoch */
  86904. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  86905. }
  86906. #else
  86907. {
  86908. struct timeval tv;
  86909. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  86910. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  86911. }
  86912. #endif
  86913. #endif
  86914. int ApiTest(void)
  86915. {
  86916. int i;
  86917. int ret;
  86918. int res = 0;
  86919. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86920. double timeDiff;
  86921. #endif
  86922. printf(" Begin API Tests\n");
  86923. fflush(stdout);
  86924. /* we must perform init and cleanup if not all tests are running */
  86925. if (!testAll) {
  86926. #ifdef WOLFCRYPT_ONLY
  86927. if (wolfCrypt_Init() != 0) {
  86928. printf("wolfCrypt Initialization failed\n");
  86929. res = 1;
  86930. }
  86931. #else
  86932. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  86933. printf("wolfSSL Initialization failed\n");
  86934. res = 1;
  86935. }
  86936. #endif
  86937. }
  86938. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  86939. if (res == 0) {
  86940. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  86941. printf("failed to create tmp dir\n");
  86942. res = 1;
  86943. }
  86944. else {
  86945. tmpDirNameSet = 1;
  86946. }
  86947. }
  86948. #endif
  86949. if (res == 0) {
  86950. for (i = 0; i < TEST_CASE_CNT; ++i) {
  86951. EXPECT_DECLS;
  86952. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  86953. currentTestName = testCases[i].name;
  86954. #endif
  86955. /* When not testing all cases then skip if not marked for running.
  86956. */
  86957. if (!testAll && !testCases[i].run) {
  86958. continue;
  86959. }
  86960. TestSetup();
  86961. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  86962. fflush(stdout);
  86963. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86964. timeDiff = gettime_secs();
  86965. #endif
  86966. ret = testCases[i].func();
  86967. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86968. timeDiff = gettime_secs() - timeDiff;
  86969. #endif
  86970. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  86971. if (ret != TEST_SKIPPED) {
  86972. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  86973. }
  86974. else
  86975. #endif
  86976. {
  86977. printf(" %s\n", apitest_res_string(ret));
  86978. }
  86979. fflush(stdout);
  86980. /* if return code is < 0 and not skipped then assert error */
  86981. Expect((ret > 0 || ret == TEST_SKIPPED),
  86982. ("Test failed\n"),
  86983. ("ret %d", ret));
  86984. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  86985. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  86986. TestCleanup();
  86987. }
  86988. }
  86989. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  86990. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  86991. wc_ecc_fp_free(); /* free per thread cache */
  86992. #endif
  86993. if (!testAll) {
  86994. #ifdef WOLFCRYPT_ONLY
  86995. wolfCrypt_Cleanup();
  86996. #else
  86997. wolfSSL_Cleanup();
  86998. #endif
  86999. }
  87000. (void)testDevId;
  87001. if (res != 0) {
  87002. printf("\nFAILURES:\n");
  87003. for (i = 0; i < TEST_CASE_CNT; ++i) {
  87004. if (testCases[i].fail) {
  87005. printf(" %3d: %s\n", i + 1, testCases[i].name);
  87006. }
  87007. }
  87008. printf("\n");
  87009. fflush(stdout);
  87010. }
  87011. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87012. if (tmpDirNameSet) {
  87013. printf("\nBinary dumps of the memio streams can be found in the\n"
  87014. "%s directory. This can be imported into\n"
  87015. "Wireshark by transforming the file with\n"
  87016. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  87017. "And then loading test_output.dump.hex into Wireshark using\n"
  87018. "the \"Import from Hex Dump...\" option and selecting the\n"
  87019. "TCP encapsulation option.\n", tmpDirName);
  87020. }
  87021. #endif
  87022. printf(" End API Tests\n");
  87023. fflush(stdout);
  87024. return res;
  87025. }